Browse Source

#password reset

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

287
CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs

@ -5,8 +5,8 @@ using CustomerOnlineV2.Common.Models.Notification;
using CustomerOnlineV2.Repository.Repository.AccountRepository;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NPoco.fastJSON;
using System.Text;
using System.Web.Helpers;
using static CustomerOnlineV2.Common.Models.Notification.PasswordGenerator;
namespace CustomerOnlineV2.Business.Business.AccountBusiness
@ -47,24 +47,29 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
string random_num = result.ToString();
model.RandomPassword = random_num;
var res =await _accountRepo.PasswordReset(model, logindetails);
var res = await _accountRepo.PasswordReset(model, logindetails);
if (res.ResponseCode == ResponseHelper.SUCCESS)
{
bool emailSent = false;
bool smsSent = false;
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 = "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 });
SendNotificationRequest request = new SendNotificationRequest()
{
IsBulkNotification = false,
UserName = model.Username,
//ProcessId = processId,
ProviderId = "ResetPassword",
NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(),
Template = NotifyTemplate.RESET_PASSWORD_EMAIL,
Recipients = new List<RecipientViewModel>()
try
{
SendNotificationRequest request = new SendNotificationRequest()
{
IsBulkNotification = false,
UserName = model.Username,
//ProcessId = processId,
ProviderId = "ResetPassword",
NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(),
Template = NotifyTemplate.RESET_PASSWORD_EMAIL,
Recipients = new List<RecipientViewModel>()
{
new RecipientViewModel()
{
@ -75,22 +80,64 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
Address= model.Username
}
}
};
};
_logger.LogDebug("PasswordReset.EMAIL | REQUEST : " + JsonConvert.SerializeObject(request));
var jsonRx1 = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL);
_logger.LogDebug("PasswordReset.EMAIL | RESPONSE : " + JsonConvert.SerializeObject(jsonRx1));
emailSent = true;
}
catch (Exception 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");
_logger.LogDebug("PasswordReset.EMAIL | REQUEST : " + JsonConvert.SerializeObject(request));
var jsonRx1 = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL);
_logger.LogDebug("PasswordReset.EMAIL | RESPONSE : " + JsonConvert.SerializeObject(jsonRx1));
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 emailException)
catch (Exception ex)
{
_logger.LogError("Error sending email", emailException);
_logger.LogError("Something Went Wrong, Please Try Again!!", ex);
res.SetResponse('1', "Error occurred while calling RequestOTP.");
return res;
}
}
return res;
}
public static string GenerateRandomPassword(PasswordOptions opts = null)
{
if (opts == null) opts = new PasswordOptions()
@ -146,42 +193,42 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
return new string(chars.ToArray());
}
//bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "CustomerId", SText = loginDetails.MembershipId.ToString() });
//bodyMappings.Add(new Mapping() { SValue = "UserId", SText = loginDetails.MembershipId });
//bodyMappings.Add(new Mapping() { SValue = "FirstName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "MiddleName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "LastName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "MobileNo", SText = loginDetails.MobileNumber });
//bodyMappings.Add(new Mapping() { SValue = "Address", SText = loginDetails.UserName });
//bodyMappings.Add(new Mapping() { SValue = "EMAIL_ID", SText = loginDetails.Email });
//bodyMappings.Add(new Mapping() { SValue = "RegisteredDate", SText = "" });
//SendNotificationRequest request = new SendNotificationRequest()
//{
// IsBulkNotification = false,
// UserName = loginDetails.Email,
// ProviderId = "BasicRegistration",
// NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(),
// Template = NotifyTemplate.BASIC_REGISTRATION_EMAIL,
// Recipients = new List<RecipientViewModel>()
// {
// new RecipientViewModel()
// {
// NotificationContent = new NotificationDTO() {
// Body = JsonConvert.SerializeObject(bodyMappings),
// //Title will be set by mapping json
// },
// Address= loginDetails.Email
// }
//return jsonRx;
//bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "CustomerId", SText = loginDetails.MembershipId.ToString() });
//bodyMappings.Add(new Mapping() { SValue = "UserId", SText = loginDetails.MembershipId });
//bodyMappings.Add(new Mapping() { SValue = "FirstName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "MiddleName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "LastName", SText = loginDetails.FullName });
//bodyMappings.Add(new Mapping() { SValue = "MobileNo", SText = loginDetails.MobileNumber });
//bodyMappings.Add(new Mapping() { SValue = "Address", SText = loginDetails.UserName });
//bodyMappings.Add(new Mapping() { SValue = "EMAIL_ID", SText = loginDetails.Email });
//bodyMappings.Add(new Mapping() { SValue = "RegisteredDate", SText = "" });
//SendNotificationRequest request = new SendNotificationRequest()
//{
// IsBulkNotification = false,
// UserName = loginDetails.Email,
// ProviderId = "BasicRegistration",
// NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(),
// Template = NotifyTemplate.BASIC_REGISTRATION_EMAIL,
// Recipients = new List<RecipientViewModel>()
// {
// new RecipientViewModel()
// {
// NotificationContent = new NotificationDTO() {
// Body = JsonConvert.SerializeObject(bodyMappings),
// //Title will be set by mapping json
// },
// Address= loginDetails.Email
// }
//return jsonRx;
public JsonRxResponse RequestOTP(RequestOTPModel requestOTPModel)
{
JsonRxResponse jsonRx = new JsonRxResponse();
try
{
requestOTPModel.OTP = Utilities.GenerateOTP();
requestOTPModel.OTP = Utilities.GenerateOTP();
jsonRx = _accountRepo.RequestOTP(requestOTPModel);
_logger.LogDebug("GenerateOTP | RESPONSE : " + JsonConvert.SerializeObject(jsonRx));
@ -190,24 +237,24 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
bool emailSent = false;
bool smsSent = false;
if (!string.IsNullOrEmpty(jsonRx.ErrorCode) && (jsonRx.ErrorCode.Equals("0") && jsonRx.Extra3.Equals("100")))
{
List<Mapping> bodyMappings = new List<Mapping>();
if (!string.IsNullOrEmpty(jsonRx.ErrorCode) && (jsonRx.ErrorCode.Equals("0") && jsonRx.Extra3.Equals("100")))
{
List<Mapping> bodyMappings = new List<Mapping>();
bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = requestOTPModel.CreatedBy });
//bodyMappings.Add(new Mapping() { SValue = "OTP_CODE", SText = requestOTPModel.OTP });
bodyMappings.Add(new Mapping() { SValue = "OTP_CODE", SText = jsonRx.Id });
bodyMappings.Add(new Mapping() { SValue = "TYPE", SText = requestOTPModel.requestFor });
try
bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = requestOTPModel.CreatedBy });
//bodyMappings.Add(new Mapping() { SValue = "OTP_CODE", SText = requestOTPModel.OTP });
bodyMappings.Add(new Mapping() { SValue = "OTP_CODE", SText = jsonRx.Id });
bodyMappings.Add(new Mapping() { SValue = "TYPE", SText = requestOTPModel.requestFor });
try
{
SendNotificationRequest request = new SendNotificationRequest()
{
SendNotificationRequest request = new SendNotificationRequest()
{
IsBulkNotification = false,
UserName = requestOTPModel.CreatedBy,
ControlNo = requestOTPModel.receiverId,
ProviderId = "REQUESTOTP_EMAIL",
Template = NotifyTemplate.OTP_EMAIL,
Recipients = new List<RecipientViewModel>()
IsBulkNotification = false,
UserName = requestOTPModel.CreatedBy,
ControlNo = requestOTPModel.receiverId,
ProviderId = "REQUESTOTP_EMAIL",
Template = NotifyTemplate.OTP_EMAIL,
Recipients = new List<RecipientViewModel>()
{
new RecipientViewModel()
{
@ -218,71 +265,71 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness
Address= requestOTPModel.CreatedBy,
DeviceType = requestOTPModel.DeviceType,
} }
};
};
_logger.LogDebug("SendNotification.EMAIL | REQUEST : " + JsonConvert.SerializeObject(request));
_logger.LogDebug("SendNotification.EMAIL | REQUEST : " + JsonConvert.SerializeObject(request));
var jsonRx1 = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL);
var jsonRx1 = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL);
_logger.LogDebug("SendNotification.EMAIL | RESPONSE : " + JsonConvert.SerializeObject(jsonRx1));
emailSent = true;
}
catch (Exception emailException)
{
_logger.LogError("Error sending email", emailException);
}
_logger.LogDebug("SendNotification.EMAIL | RESPONSE : " + JsonConvert.SerializeObject(jsonRx1));
emailSent = true;
}
catch (Exception emailException)
{
_logger.LogError("Error sending email", emailException);
}
try
{
string ProcessId = Guid.NewGuid().ToString().Replace("-", "") + ":sendSms";
string mobileNum = jsonRx.Extra2;
var mobNum = getSenderFormattedNumber(mobileNum);
SendSMSApiService _sendAPI = new SendSMSApiService();
StringBuilder s = new StringBuilder();
s.AppendLine($"Dear {jsonRx.Extra}");
s.AppendLine($"Your OTP code for Customer Registration is {jsonRx.Id}.");
s.AppendLine("Regards, IME London");
SMSRequestModel _req = new SMSRequestModel
{
ProviderId = "onewaysms",
MobileNumber = mobileNum,
SMSBody = s.ToString(),
ProcessId = ProcessId.Substring(ProcessId.Length - 40, 40),
RequestedBy = requestOTPModel.userId,
UserName = requestOTPModel.userId,
method = "send",
ControlNo = "", // GetControlNo()
};
_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);
}
if (emailSent || smsSent)
try
{
string ProcessId = Guid.NewGuid().ToString().Replace("-", "") + ":sendSms";
string mobileNum = jsonRx.Extra2;
var mobNum = getSenderFormattedNumber(mobileNum);
SendSMSApiService _sendAPI = new SendSMSApiService();
StringBuilder s = new StringBuilder();
s.AppendLine($"Dear {jsonRx.Extra}");
s.AppendLine($"Your OTP code for Customer Registration is {jsonRx.Id}.");
s.AppendLine("Regards, IME London");
SMSRequestModel _req = new SMSRequestModel
{
jsonRx.ErrorCode = "0";
jsonRx.SetResponse("0", "OTP has been Sent.");
return jsonRx;
}
ProviderId = "onewaysms",
MobileNumber = mobileNum,
SMSBody = s.ToString(),
ProcessId = ProcessId.Substring(ProcessId.Length - 40, 40),
RequestedBy = requestOTPModel.userId,
UserName = requestOTPModel.userId,
method = "send",
ControlNo = "", // GetControlNo()
};
_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);
}
if (emailSent || smsSent)
{
jsonRx.ErrorCode = "0";
jsonRx.SetResponse("0", "OTP has been Sent.");
return jsonRx;
}
}
}
else
{
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