Browse Source

#password reset

feature/19315_Customer-Registration
Leeza Baidar 11 months ago
parent
commit
deee6b3a59
  1. 57
      CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs

57
CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs

@ -5,8 +5,8 @@ using CustomerOnlineV2.Common.Models.Notification;
using CustomerOnlineV2.Repository.Repository.AccountRepository; using CustomerOnlineV2.Repository.Repository.AccountRepository;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using NPoco.fastJSON;
using System.Text; using System.Text;
using System.Web.Helpers;
using static CustomerOnlineV2.Common.Models.Notification.PasswordGenerator; using static CustomerOnlineV2.Common.Models.Notification.PasswordGenerator;
namespace CustomerOnlineV2.Business.Business.AccountBusiness namespace CustomerOnlineV2.Business.Business.AccountBusiness
@ -47,15 +47,20 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
string random_num = result.ToString(); string random_num = result.ToString();
model.RandomPassword = random_num; model.RandomPassword = random_num;
var res =await _accountRepo.PasswordReset(model, logindetails);
var res = await _accountRepo.PasswordReset(model, logindetails);
if (res.ResponseCode == ResponseHelper.SUCCESS) if (res.ResponseCode == ResponseHelper.SUCCESS)
{ {
bool emailSent = false;
bool smsSent = false;
try try
{ {
List<Mapping> bodyMappings = new List<Mapping>(); List<Mapping> bodyMappings = new List<Mapping>();
bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = res.Extra2 }); bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = res.Extra2 });
bodyMappings.Add(new Mapping() { SValue = "PASS_WORD", SText = random_num }); bodyMappings.Add(new Mapping() { SValue = "PASS_WORD", SText = random_num });
bodyMappings.Add(new Mapping() { SValue = "EMAIL_ID", SText = model.Username }); bodyMappings.Add(new Mapping() { SValue = "EMAIL_ID", SText = model.Username });
try
{
SendNotificationRequest request = new SendNotificationRequest() SendNotificationRequest request = new SendNotificationRequest()
{ {
IsBulkNotification = false, IsBulkNotification = false,
@ -76,16 +81,58 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
} }
} }
}; };
_logger.LogDebug("PasswordReset.EMAIL | REQUEST : " + JsonConvert.SerializeObject(request)); _logger.LogDebug("PasswordReset.EMAIL | REQUEST : " + JsonConvert.SerializeObject(request));
var jsonRx1 = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL); var jsonRx1 = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL);
_logger.LogDebug("PasswordReset.EMAIL | RESPONSE : " + JsonConvert.SerializeObject(jsonRx1)); _logger.LogDebug("PasswordReset.EMAIL | RESPONSE : " + JsonConvert.SerializeObject(jsonRx1));
emailSent = true;
} }
catch (Exception emailException) catch (Exception emailException)
{ {
_logger.LogError("Error sending email", emailException); _logger.LogError("Error sending email", emailException);
} }
try
{
string ProcessId = Guid.NewGuid().ToString().Replace("-", "") + ":sendSms";
var mobileNo = getSenderFormattedNumber(res.Extra3);
SendSMSApiService _sendAPI = new SendSMSApiService();
StringBuilder s = new StringBuilder();
s.AppendLine($"Dear {res.Extra2}");
s.AppendLine($"We received your password reset request and your new credentials are");
s.AppendLine($"Login ID: {model.Username}");
s.AppendLine($"Password: {model.RandomPassword}");
s.AppendLine("Regards, IME London");
SMSRequestModel _req = new SMSRequestModel
{
ProviderId = "onewaysms",
MobileNumber = mobileNo,
SMSBody = s.ToString(),
ProcessId = ProcessId.Substring(ProcessId.Length - 40, 40),
RequestedBy = res.Id,
UserName = res.Id,
method = "send",
ControlNo = "",
};
_logger.LogDebug("SendNotification.SMS | REQUEST : " + JsonConvert.SerializeObject(_req));
APIJsonResponse _resp = _sendAPI.SMSTPApi(_req);
_logger.LogDebug("SendNotification.SMS | RESPONSE : " + JsonConvert.SerializeObject(_resp));
smsSent = true;
}
catch (Exception smsException)
{
_logger.LogError("Error sending SMS", smsException);
}
}
catch (Exception ex)
{
_logger.LogError("Something Went Wrong, Please Try Again!!", ex);
res.SetResponse('1', "Error occurred while calling RequestOTP.");
return res;
}
} }
return res; return res;
} }
@ -282,7 +329,7 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
else else
{ {
jsonRx.ErrorCode = "1"; jsonRx.ErrorCode = "1";
return new JsonRxResponse { ErrorCode = jsonRx.ErrorCode, Msg = jsonRx.Msg , Id= jsonRx.Id, Extra3= jsonRx.Extra3 };
return new JsonRxResponse { ErrorCode = jsonRx.ErrorCode, Msg = jsonRx.Msg, Id = jsonRx.Id, Extra3 = jsonRx.Extra3 };
} }

Loading…
Cancel
Save