diff --git a/CustomerOnlineV2/CustomerOnlineV2.Api/API/TPApi/TPApiService.cs b/CustomerOnlineV2/CustomerOnlineV2.Api/API/TPApi/TPApiService.cs index 8a2896b..ccb8145 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Api/API/TPApi/TPApiService.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Api/API/TPApi/TPApiService.cs @@ -192,7 +192,7 @@ namespace CustomerOnlineV2.Api.API.TPApi } else { - var errorJson = JsonConvert.DeserializeObject(resultData); + var errorJson = JsonConvert.DeserializeObject(resultData); var jsonResponseData = JsonConvert.DeserializeObject(errorJson.Message); jsonResponse.Id = jsonResponseData.Id; diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs index a989140..27b8004 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs @@ -1,14 +1,11 @@ using CustomerOnlineV2.Common.Helper; using CustomerOnlineV2.Common.Models; using CustomerOnlineV2.Common.Models.AccountModel; -using CustomerOnlineV2.Common.Models.HomeModel; using CustomerOnlineV2.Common.Models.Notification; using CustomerOnlineV2.Repository.Repository.AccountRepository; using Microsoft.Extensions.Logging; -using Microsoft.IdentityModel.Tokens; -using Notify = Azure.Core.HttpHeader; using Newtonsoft.Json; - +using System.Text; using static CustomerOnlineV2.Common.Models.Notification.PasswordGenerator; namespace CustomerOnlineV2.Business.Business.AccountBusiness @@ -125,6 +122,221 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness return new string(chars.ToArray()); } - + public async Task VerifyOtp(RequestOTPModel requestOTPModel, LoginResponse loginDetails) + { + JsonRxResponse jsonRx = new JsonRxResponse(); + try + { + jsonRx = await _accountRepo.VerifyOtp(requestOTPModel, loginDetails); + _logger.LogDebug("SubmitOTP | DB RESPONSE : " + JsonConvert.SerializeObject(jsonRx)); + + + if (jsonRx.ErrorCode.Equals("0")) + { + + //List bodyMappings = new List(); + + //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() + // { + // new RecipientViewModel() + // { + // NotificationContent = new NotificationDTO() { + // Body = JsonConvert.SerializeObject(bodyMappings), + // //Title will be set by mapping json + // }, + // Address= loginDetails.Email + // } + // } + //}; + //jsonRx = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL); + } + + //return jsonRx; + return await Task.FromResult(jsonRx); + } + catch (Exception ex) + { + _logger.LogError("Something Went Wrong, Please Try Again!!", ex); + jsonRx.SetResponse("1", "Error occurred while calling RequestOTP."); + return await Task.FromResult(jsonRx); + } + } + + public JsonRxResponse RequestOTP(RequestOTPModel requestOTPModel) + { + JsonRxResponse jsonRx = new JsonRxResponse(); + try + { + requestOTPModel.OTP = Utilities.GenerateOTP(); + jsonRx = _accountRepo.RequestOTP(requestOTPModel); + _logger.LogDebug("GenerateOTP | RESPONSE : " + JsonConvert.SerializeObject(jsonRx)); + + if (jsonRx.ErrorCode == "0") + { + bool emailSent = false; + bool smsSent = false; + if (requestOTPModel.userId.IsValidEmail()) + { + + if (!string.IsNullOrEmpty(jsonRx.ErrorCode) && jsonRx.ErrorCode.Equals("0")) + { + List bodyMappings = new List(); + + 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() + { + IsBulkNotification = false, + UserName = requestOTPModel.CreatedBy, + ControlNo = requestOTPModel.receiverId, + ProviderId = "REQUESTOTP_EMAIL", + Template = NotifyTemplate.OTP_EMAIL, + Recipients = new List() + { + new RecipientViewModel() + { + NotificationContent = new NotificationDTO() { + Body = JsonConvert.SerializeObject(bodyMappings), + //Title will be set by mapping json + }, + Address= requestOTPModel.CreatedBy, + DeviceType = requestOTPModel.DeviceType, + } } + }; + + + _logger.LogDebug("SendNotification.EMAIL | REQUEST : " + JsonConvert.SerializeObject(request)); + + 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); + } + + 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 {requestOTPModel.OTP}."); + 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) + { + 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 }; + + } + + jsonRx.ErrorCode = jsonRx.ErrorCode == "103" ? "0" : jsonRx.ErrorCode;//103 = previous OTP was not expired so same was used + return jsonRx; + } + catch (Exception ex) + { + _logger.LogError("Something Went Wrong, Please Try Again!!", ex); + jsonRx.SetResponse("1", "Error occurred while calling RequestOTP."); + return jsonRx; + } + } + + private string getSenderFormattedNumber(string number) + { + string finalNo = number; + if (!number.Contains("+44")) + { + string mobileFirst = number.Substring(0, 1); + if (mobileFirst == "0") + { + if (number.Length == 11) + { + finalNo = "+44" + number.Substring(1, number.Length - 1); + return finalNo; + } + else if (number.Length < 11) + { + finalNo = $"+44{number}"; + } + } + else if (number.Substring(0, 1) != "0" && number.Length == 10) + { + finalNo = $"+44{number}"; + } + } + else if (number.Contains("+44")) + { + string MobN = number.Substring(4, 1); + if (MobN == "0" && number.Length > 14) + { + finalNo = number.Remove(4, 1); + } + } + if (!finalNo.Substring(0, 1).Contains("+")) + finalNo = $"+{finalNo}"; + return finalNo; + } } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/IAccountBusiness.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/IAccountBusiness.cs index 6ccd147..856e647 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/IAccountBusiness.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/IAccountBusiness.cs @@ -8,6 +8,7 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness Task Login(LoginModel model); Task ChangePassword(ForceChangePasswordModel model, LoginResponse logindetails); Task PasswordReset(PasswordResetModel model, LoginResponse logindetails); - // object PasswordReset(PasswordResetModel model, string processid); + Task VerifyOtp(RequestOTPModel requestOTPModel, LoginResponse logindetails); + JsonRxResponse RequestOTP(RequestOTPModel requestOTPModel); } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/LoggerProperty.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/LoggerProperty.cs new file mode 100644 index 0000000..8dde671 --- /dev/null +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/LoggerProperty.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomerOnlineV2.Business.Business +{ + public static class LoggerProperty + { + public const string PROCESSID = "processId"; + public const string PAYOUTPARTNERID = "payoutPartnerId"; + public const string METHODNAME = "methodName"; + public const string CONTROLNO = "controlNo"; + public const string CREATEDBY = "createdBy"; + public const string MESSAGE = "message"; + public const string EXCEPTION = "exception"; + public const string LOGGER = "logger"; + public const string LEVEL = "level"; + public const string IPADDRESS = "userIP"; + } +} diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/NotifierV2.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/NotifierV2.cs new file mode 100644 index 0000000..3e62b08 --- /dev/null +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/NotifierV2.cs @@ -0,0 +1,96 @@ +using CustomerOnlineV2.Common.Models.Notification; +using CustomerOnlineV2.Common.Models; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using CustomerOnlineV2.Common.Models.TransactionModel; + +namespace CustomerOnlineV2.Business.Business +{ + public static class NotifierV2 + { + + public static JsonRxResponse SendNotification(SendNotificationRequest request, NOTIFICATION_TYPE nOTIFICATION_TYPE = NOTIFICATION_TYPE.PUSH_NOTIFICATION) + { + ThirdPartyAPI _tpApi = new ThirdPartyAPI(); + + APIJsonResponse jsonResponse = new APIJsonResponse(); + + if (string.IsNullOrEmpty(request.ProcessId)) + request.ProcessId = Guid.NewGuid().ToString(); + + //request.ProviderId = Guid.NewGuid().ToString(); + request.NotificationTypeId = nOTIFICATION_TYPE.ToString(); + + + APIJsonResponse result = _tpApi.ThirdPartyApiGetDataOnly(request, "TP/NotificationAPI", out jsonResponse); + + + return new JsonRxResponse() + { + ErrorCode = result.ResponseCode, + Id = result.Id, + Msg = result.Msg, + Data = result.Data, + Extra = result.Extra, + Extra2 = result.Extra1 + }; + } + + + } + + public class SendSMSApiService + { + public APIJsonResponse SMSTPApi(SMSRequestModel model) + { + //Log.Debug("Calculate | Calling third party api to fetch the ex-rate details " + JsonConvert.SerializeObject(model)); + using (var client = RestApiClient.GetThirdPartyClient()) + { + APIJsonResponse jsonResponse = new APIJsonResponse(); + var obj = JsonConvert.SerializeObject(model); + var jbdContent = new StringContent(obj.ToString(), Encoding.UTF8, "application/json"); + try + { + var URL = "TP/SMSApi"; + + HttpResponseMessage resp = client.PostAsync(URL, jbdContent).Result; + string resultData = resp.Content.ReadAsStringAsync().Result; + if (resp.IsSuccessStatusCode) + { + jsonResponse = JsonConvert.DeserializeObject(resultData); + var a = (jsonResponse.Data != null ? JsonConvert.DeserializeObject(jsonResponse.Data.ToString()) : null); + jsonResponse.Data = a; + + return jsonResponse; + } + else + { + var errorJson = JsonConvert.DeserializeObject(resultData); + var jsonResponseData = JsonConvert.DeserializeObject(errorJson.Message); + var data = JsonConvert.DeserializeObject>(jsonResponseData.Data.ToString()); + jsonResponse.Id = jsonResponseData.Id; + jsonResponse.ResponseCode = jsonResponseData.ResponseCode; + jsonResponse.Msg = jsonResponseData.Msg; + jsonResponse.Data = data; + jsonResponse.Extra = jsonResponseData.Extra; + jsonResponse.Extra1 = jsonResponseData.Extra1; + return jsonResponse; + } + } + catch (Exception ex) + { + return new APIJsonResponse() + { + ResponseCode = "1", + Msg = (ex.InnerException == null ? ex.Message : ex.InnerException.Message) + }; + } + } + } + } +} diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/IRegisterBusiness.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/IRegisterBusiness.cs index 916407c..f7d0747 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/IRegisterBusiness.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/IRegisterBusiness.cs @@ -13,7 +13,7 @@ namespace CustomerOnlineV2.Business.Business.RegisterBusiness { public interface IRegisterBusiness { - Task AddCustomers(OnlineCustomerRegisterModel register); + Task AddCustomers(OnlineCustomerRegisterModel register); Task GetAddressList(AddressRequest addressRequest); Task GetTranCustomerById(LoginResponse loginDetails); Task UpdateCustomers(CustomerListModel customer, string Id); diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/RegisterBusiness.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/RegisterBusiness.cs index 7a4b80c..82b38bb 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/RegisterBusiness.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/RegisterBusiness/RegisterBusiness.cs @@ -2,15 +2,12 @@ using CustomerOnlineV2.Common.Models; using CustomerOnlineV2.Common.Models.AccountModel; using CustomerOnlineV2.Common.Models.HomeModel; +using CustomerOnlineV2.Common.Models.Notification; using CustomerOnlineV2.Common.Models.RegisterModel; using CustomerOnlineV2.Repository.Repository.RegisterRepository; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; - -using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json; +using Notify = CustomerOnlineV2.Common.Models.Notification; namespace CustomerOnlineV2.Business.Business.RegisterBusiness { @@ -20,7 +17,7 @@ namespace CustomerOnlineV2.Business.Business.RegisterBusiness private readonly ITPApiService _tpApi; - + private readonly IRegisterRepository _registerRepository; @@ -30,41 +27,85 @@ namespace CustomerOnlineV2.Business.Business.RegisterBusiness _registerRepository = registerRepository; } - public async Task AddCustomers(OnlineCustomerRegisterModel register) + public async Task AddCustomers(OnlineCustomerRegisterModel register) { var model1 = await _registerRepository.AddRegisterDetails(register); - return model1; + try + { + if (model1.ErrorCode.Equals("0")) + { + List bodyMappings = new List(); + + bodyMappings.Add(new Mapping() { SValue = "CustomerName", SText = register.fullName }); + bodyMappings.Add(new Mapping() { SValue = "CustomerId", SText = "" }); + bodyMappings.Add(new Mapping() { SValue = "UserId", SText = register.membershipId }); + bodyMappings.Add(new Mapping() { SValue = "FirstName", SText = register.firstName }); + bodyMappings.Add(new Mapping() { SValue = "MiddleName", SText = register.middleName }); + bodyMappings.Add(new Mapping() { SValue = "LastName", SText = register.lastName1 }); + bodyMappings.Add(new Mapping() { SValue = "MobileNo", SText = register.mobile }); + bodyMappings.Add(new Mapping() { SValue = "Address", SText = register.address }); + bodyMappings.Add(new Mapping() { SValue = "EMAIL_ID", SText = register.email }); + bodyMappings.Add(new Mapping() { SValue = "RegisteredDate", SText = "" }); + + SendNotificationRequest request = new SendNotificationRequest() + { + IsBulkNotification = false, + UserName = register.email, + ProviderId = "BasicRegistration", + NotificationTypeId = NOTIFICATION_TYPE.EMAIL.ToString(), + Template = Common.Models.Notification.NotifyTemplate.BASIC_REGISTRATION_EMAIL, + Recipients = new List() + { + new RecipientViewModel() + { + NotificationContent = new NotificationDTO() { + Body = JsonConvert.SerializeObject(bodyMappings), + //Title will be set by mapping json + }, + Address= register.email + } + } + }; + var model = NotifierV2.SendNotification(request, NOTIFICATION_TYPE.EMAIL); + } + return model1; + } + catch (Exception ex) + { + _logger.LogError("Something Went Wrong, Please Try Again!!", ex); + model1.SetResponse("1", "Error occurred while calling RequestOTP."); + return model1; + } } public Task GetAddressList(AddressRequest addressRequest) { throw new NotImplementedException(); } - public async Task GetTranCustomerById(LoginResponse loginDetails) { return await _registerRepository.GetTranCustomerById(loginDetails); } - - public async Task GetAllNotificationDetails(LoginResponse loginDetails) + public async Task GetAllNotificationDetails(LoginResponse loginDetails) { return (CustomerNotificationModel)await _registerRepository.GetAllNotificationDetails(loginDetails); } - public async Task UpdateCustomers(CustomerListModel model, string id) + + public async Task UpdateCustomers(CustomerListModel model, string id) { var model1 = await _registerRepository.UpdateCustomers1(model, id); return model1; } - public async Task UpdateDocuments(CustomerListModel model, string Id) { var model1 = await _registerRepository.UpdateDocument1(model, Id); return model1; } - - public async Task GetRewardPoints(LoginResponse loginDetails) + public async Task GetRewardPoints(LoginResponse loginDetails) { return (CustomerNotificationModel)await _registerRepository.GetRewardPoints(loginDetails); } + + } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/ThirdPartyAPI.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/ThirdPartyAPI.cs new file mode 100644 index 0000000..e4d83c4 --- /dev/null +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/ThirdPartyAPI.cs @@ -0,0 +1,84 @@ +using CustomerOnlineV2.Common.Models; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.Net.Http.Headers; +using System.Text; + +namespace CustomerOnlineV2.Business.Business +{ + public class ThirdPartyAPI + { + private static int timeOut = 100; + private string tp_base_url = "http://77.68.15.91:1083/api/v1/"; + private string apiAccessKey = "KPb1ttRs3CJnORpVU8SmAKUs7a42vtvjzQ47gU0b4u0vxAEI0PgZref6puzkVhLTX2PRNMGCbnb2TglupsjV5AGhYvw8a8POTcUcFSrEdHmTkhkIGNvUvxSpKjUOXGFQWaGU1bxoqqUSaFOmNE5zGojVmwPoMy38CNLwnpQKjdsIuxCKGCApa2gWHJl9gebmIpUODv9jAZgmMEaXqyR4CLg4iSksfTyYNjdqxEE88P5THYt5GuNk8Ti6K2RxIKfPWY49hBOpiYnXcApgSDiKFYqQG9WuZ7cvDGJIWg5WgWKjGle8Y3OydhONXVkN5OMPXDA4VZkK4c5nM363Zkg4w4qdzWuwhsEoAwU4rej6sMRZue3L0BowBJja1OK0iPoTX70EexX8rviMLOZPUDwhxzkL3eODS69VEEbjHb8WSjhho5h3KnCE4tcqCWihwSZ8Yuyhw1rzIMNw2C8pN1GEJyXc6goIFkf7dmK9ynJSxu52D9GjOkKqoD7dFNFulOFVfgeCuhPDYG2A2c2RSvGHv24VDXvmGVaAMLiPtsTz5oD8f0na7fX1xGg0Qveh0KgQL5THnrMK6gm5Ky7O8nbecIxY"; + + + public ResponseModel ThirdPartyApiGetDataOnly(RequestModel model, string api_url, out APIJsonResponse jsonResponse, string MethodType = "post") + { + ResponseModel _responseModel = default(ResponseModel); + using (HttpClient httpClient = new HttpClient()) + { + try + { + httpClient.BaseAddress = new Uri(tp_base_url); + httpClient.DefaultRequestHeaders.Add("apiAccessKey", apiAccessKey); + httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + httpClient.Timeout = new TimeSpan(0, 0, timeOut); + HttpResponseMessage resp = new HttpResponseMessage(); + if (MethodType.ToLower().Equals("get")) + resp = httpClient.GetAsync(api_url).Result; + if (MethodType.ToLower().Equals("put")) + { + StringContent jbdContent = new StringContent(JsonConvert.SerializeObject(model).ToString(), Encoding.UTF8, "application/json"); + resp = httpClient.PutAsync(api_url, jbdContent).Result; + } + if (MethodType.ToLower().Equals("post")) + { + var jsonData = JsonConvert.SerializeObject(model).ToString(); + StringContent jbdContent = new StringContent(jsonData, Encoding.UTF8, "application/json"); + resp = httpClient.PostAsync(api_url, jbdContent).Result; + } + string resultData = resp.Content.ReadAsStringAsync().Result; + if (resp.IsSuccessStatusCode) + { + var result = resp.Content.ReadAsStringAsync().Result; + JObject a = JObject.Parse(result); + _responseModel = a.ToObject(); + } + else + { + + ErrorJosn errorJson = JsonConvert.DeserializeObject(resultData); + APIJsonResponse jsonResponseData = JsonConvert.DeserializeObject(errorJson.Message); + List data = JsonConvert.DeserializeObject>(jsonResponseData.Data.ToString()); + jsonResponse = new APIJsonResponse() + { + Id = jsonResponseData.Id, + Msg = jsonResponseData.Msg, + Data = data, + Extra = jsonResponseData.Extra, + Extra1 = jsonResponseData.Extra1 + }; + } + } + catch (HttpRequestException ex) + { + jsonResponse = new APIJsonResponse() + { + ResponseCode = "999", + Msg = ex.Message, + Data = ex.Data, + }; + _responseModel = default(ResponseModel); + } + }; + + jsonResponse = new APIJsonResponse() + { + ResponseCode = "0", + Msg = "Api Calling process successfully!" + }; + return _responseModel; + } + } +} diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/ApplicationConfig.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/ApplicationConfig.cs new file mode 100644 index 0000000..03ca36a --- /dev/null +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/ApplicationConfig.cs @@ -0,0 +1,62 @@ +using CustomerOnlineV2.Common.Configs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomerOnlineV2.Common.Helper +{ + public static class ApplicationConfig + { + public static string GetDocumentUploadPath() + { + return ReadWebConfig("docUploadPath"); + } + + public static string GetDocumentUploadUrl() + { + return ReadWebConfig("docUploadURL"); + } + + public static string GetTelecomsIconRelativePath() + { + return ReadWebConfig("telecomsIconRelativePath"); + } + + public static string GetCountryFlagRelativePath() + { + return ReadWebConfig("countryFlagRelativePath"); + } + + public static string GetKycImageRelativePath() + { + return ReadWebConfig("kycImageRelativePath"); + } + + public static string GetRewardImageRelativePath() + { + return ReadWebConfig("rewardImageRelativePath"); + } + + public static string GetRootURL() + { + return ReadWebConfig("rootUrl"); + } + + public static string GetMaximumFileSize() + { + return ReadWebConfig("maxFileSize"); + } + + public static string ReadWebConfig(string key) + { + return ReadWebConfig(key, ""); + } + + public static string ReadWebConfig(string key, string defValue) + { + return ConfigurationManager.AppSettings[key] ?? defValue; + } + } +} diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/LoginUserInfo.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/LoginUserInfo.cs index 398fba5..f71f058 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/LoginUserInfo.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/LoginUserInfo.cs @@ -22,7 +22,7 @@ namespace CustomerOnlineV2.Common.Helper model.RememberMe = Convert.ToBoolean(claimIdentity.FindFirst(x => x.Type == "RememberMe").Value); model.SessionId = claimIdentity.FindFirst(x => x.Type == "SessionId").Value; model.UserId = claimIdentity.FindFirst(x => x.Type == "UserId").Value; - model.IsEmailVerified = Convert.ToBoolean(claimIdentity.FindFirst(x => x.Type == "IsEmailVerified").Value); + } return model; } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/Utilities.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/Utilities.cs index 0f8d003..3c05179 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/Utilities.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Helper/Utilities.cs @@ -1,5 +1,6 @@ using CustomerOnlineV2.Common.Configs; using Microsoft.AspNetCore.Http; +using System.Text.RegularExpressions; namespace CustomerOnlineV2.Common.Helper { @@ -66,6 +67,18 @@ namespace CustomerOnlineV2.Common.Helper else return strVal; } - + public static string GenerateOTP() + { + string[] strChar = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; + Random random = new Random(); + string otpChar = strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] + + strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] + + strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)]; + return otpChar; + } + public static bool IsValidEmail(this string email) + { + return Regex.IsMatch(email ?? "", ApplicationConfig.ReadWebConfig("regex"), RegexOptions.IgnoreCase); + } } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/AccountModel/AccountModel.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/AccountModel/AccountModel.cs index c0c164b..1726aac 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/AccountModel/AccountModel.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/AccountModel/AccountModel.cs @@ -46,4 +46,28 @@ namespace CustomerOnlineV2.Common.Models.AccountModel public string? MembershipId { get; set; } public bool IsEmailVerified { get; set; } } + public class VerifyOtpModel + { + public string? Email { get; set; } + public string otp { get; set; } + } + public class RequestOTPModel + { + public string? userId { get; set; } + public string? OTP { get; set; } + public string? requestFor { get; set; } + public string? receiverId { get; set; } + public string? mobileNo { get; set; } + public string? customerName { get; set; } + public string? IpAddress { get; set; } + public string? sessionId { get; set; } + public string? FcmId { get; set; } + public string? ProcessId { get; set; } + public string? MethodName { get; set; } + public string? CreatedBy { get; set; } + [JsonIgnore] + public string? DeviceType { get; set; } + [JsonIgnore] + public string? Lang { get; set; } + } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/CommonResponse.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/CommonResponse.cs index 71005cd..e6bd6c7 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/CommonResponse.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/CommonResponse.cs @@ -17,7 +17,15 @@ ResponseMessage = ResponseMessageHelper.FAILED; } - public CommonResponse(int responseCode, string? responseMessage, string? id = null, string? extra = null) + public CommonResponse(int responseCode, string? responseMessage, string? id = null, string? extra = null, string? extra2 = null) + { + ResponseCode = responseCode; + ResponseMessage = responseMessage; + Id = id; + Extra = extra; + Extra2 = extra2; + } + public void SetResponse(int responseCode, string? responseMessage, string? id = null, string? extra = null) { ResponseCode = responseCode; ResponseMessage = responseMessage; @@ -29,4 +37,98 @@ public string Message { get; set; } } } + public class JsonRxResponse + { + private string? _errorCode = ""; + private string? _msg = ""; + private string? _id = ""; + private string? _extra = ""; + private string? _extra2 = ""; + private string? _extra3 = ""; + private object _data = null; + private string? _footNoteMessage = ""; + public string ErrorCode + { + set { _errorCode = value; } + get { return _errorCode; } +} + + public string Msg + { + set { _msg = value; } + get { return _msg; } + } + + public string Id + { + set { _id = value; } + get { return _id; } + } + public string Extra + { + set { _extra = value; } + get { return _extra; } + } + public string Extra2 + { + set { _extra2 = value; } + get { return _extra2; } + } + public string Extra3 + { + set { _extra3 = value; } + get { return _extra3; } + } + public object Data + { + set { _data = value; } + get { return _data; } + } + public JsonRxResponse() + { + } + public string FootNoteMessage + { + set { _footNoteMessage = value; } + get { return _footNoteMessage; } + } + public void SetResponse(string? errorCode, string? message, string? id = null, string? extra = null) + { + ErrorCode = errorCode; + Msg = message; + Id = id; + Extra = extra; + } + } + public class APIJsonResponse + { + public string? ResponseCode { get; set; } + public string? Msg { get; set; } + public string? Id { get; set; } + public object? Data { get; set; } + public string? Extra { get; set; } + public string? Extra1 { get; set; } + public string? Extra2 { get; set; } + public string? Extra3 { get; set; } + public string? FootNoteMessage { get; set; } + public void SetResponse(string responseCode, string msg, string id = null, string extra = null, string extra1 = null, string extra3 = null, string footNoteMessage = "") + { + ResponseCode = responseCode; + Msg = msg; + Id = id; + Extra = extra; + Extra1 = extra1; + Extra3 = extra3; + FootNoteMessage = footNoteMessage; + } + } + public class ErrorJosn + { + public string Message { get; set; } + } + public class Data + { + public string Name { get; set; } + public string Message { get; set; } + } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/Notification/RestApiClient.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/Notification/RestApiClient.cs new file mode 100644 index 0000000..d37c143 --- /dev/null +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/Notification/RestApiClient.cs @@ -0,0 +1,33 @@ +using CustomerOnlineV2.Common.Configs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; + +namespace CustomerOnlineV2.Common.Models.Notification +{ + public class RestApiClient + { + private static int timeOut = 100;//Convert.ToInt16(ConfigurationManager.AppSettings["ApiTimeOutSeconds"]); + + public static HttpClient GetThirdPartyClient() + { + //string authHeader = ConfigurationManager.AppSettings["ApiUser"].ToString() + ":" +ConfigurationManager.AppSettings["ApiPwd"].ToString(); + //var plainTextBytes = Encoding.UTF8.GetBytes(authHeader); + //string encodedAuthHeader = Convert.ToBase64String(plainTextBytes); + string thirdPartyUrl = "http://77.68.15.91:1083/api/v1/"; //ConfigurationManager.AppSettings["ThirdParty_Base_Url"].ToString(); + string apiAccessKey = "KPb1ttRs3CJnORpVU8SmAKUs7a42vtvjzQ47gU0b4u0vxAEI0PgZref6puzkVhLTX2PRNMGCbnb2TglupsjV5AGhYvw8a8POTcUcFSrEdHmTkhkIGNvUvxSpKjUOXGFQWaGU1bxoqqUSaFOmNE5zGojVmwPoMy38CNLwnpQKjdsIuxCKGCApa2gWHJl9gebmIpUODv9jAZgmMEaXqyR4CLg4iSksfTyYNjdqxEE88P5THYt5GuNk8Ti6K2RxIKfPWY49hBOpiYnXcApgSDiKFYqQG9WuZ7cvDGJIWg5WgWKjGle8Y3OydhONXVkN5OMPXDA4VZkK4c5nM363Zkg4w4qdzWuwhsEoAwU4rej6sMRZue3L0BowBJja1OK0iPoTX70EexX8rviMLOZPUDwhxzkL3eODS69VEEbjHb8WSjhho5h3KnCE4tcqCWihwSZ8Yuyhw1rzIMNw2C8pN1GEJyXc6goIFkf7dmK9ynJSxu52D9GjOkKqoD7dFNFulOFVfgeCuhPDYG2A2c2RSvGHv24VDXvmGVaAMLiPtsTz5oD8f0na7fX1xGg0Qveh0KgQL5THnrMK6gm5Ky7O8nbecIxY"; + + var httpClient = new HttpClient(); + httpClient.BaseAddress = new Uri(thirdPartyUrl); + + httpClient.DefaultRequestHeaders.Add("apiAccessKey", apiAccessKey.ToString()); + httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + httpClient.Timeout = new TimeSpan(0, 0, timeOut); + return httpClient; + } + + } +} diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/Notification/SMSRequestModel.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/Notification/SMSRequestModel.cs new file mode 100644 index 0000000..f53071a --- /dev/null +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/Notification/SMSRequestModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CustomerOnlineV2.Common.Models.Notification +{ + public class SMSRequestModel + { + public string? ProcessId { get; set; } + public string? UserName { get; set; } + public string? RequestedBy { get; set; } + public string? MobileNumber { get; set; } + public string? SMSBody { get; set; } + public string? method { get; set; } + public string? ProviderId { get; set; } + public string? ControlNo { get; set; } + public string? MTID { get; set; } + } +} diff --git a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/RegisterModel/UserRegisterResponse.cs b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/RegisterModel/UserRegisterResponse.cs index 0a511e4..da0e76b 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Common/Models/RegisterModel/UserRegisterResponse.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Common/Models/RegisterModel/UserRegisterResponse.cs @@ -181,5 +181,6 @@ namespace CustomerOnlineV2.Common.Models.RegisterModel public string? islocked { get; set; } public string? sessionId { get; set; } public string? AboutUs { get; set; } + public string? otp { get; set; } } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Repository/ConnectionHelper/ConnectionHelper.cs b/CustomerOnlineV2/CustomerOnlineV2.Repository/ConnectionHelper/ConnectionHelper.cs index dfb1aee..b38b36b 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Repository/ConnectionHelper/ConnectionHelper.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Repository/ConnectionHelper/ConnectionHelper.cs @@ -179,7 +179,8 @@ namespace CustomerOnlineV2.Repository.ConnectionHelper response.Id = Convert.ToString(dt.Rows[0][2]); if (dt.Columns.Count > 3) response.Extra = Convert.ToString(dt.Rows[0][3]); - + if (dt.Columns.Count > 4) + response.Extra2 = Convert.ToString(dt.Rows[0][4]); return response; } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs index ad43eb7..233c2c6 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs @@ -96,6 +96,8 @@ namespace CustomerOnlineV2.Repository.Repository.AccountRepository } return await Task.FromResult(_response); } + + public async Task PasswordReset(PasswordResetModel model, LoginResponse logindetails) { CommonResponse _response = new CommonResponse(); @@ -104,7 +106,9 @@ namespace CustomerOnlineV2.Repository.Repository.AccountRepository var sql = "EXEC JsonRx_Proc_UserRegistration @flag='pwd-reset' "; sql += " ,@username = " + _connHelper.FilterString(model.Username); sql += ", @dob = " + _connHelper.FilterString(model.Dob); + sql += ", @randomPassword = " + _connHelper.FilterString(model.RandomPassword); + _logger.LogDebug("ACCOUNTREPOSITORY | RESETPASSWORD | SQL | " + sql); return _connHelper.ParseDbResult(sql); } @@ -117,5 +121,50 @@ namespace CustomerOnlineV2.Repository.Repository.AccountRepository } return await Task.FromResult(_response); } + public JsonRxResponse RequestOTP(RequestOTPModel requestOTPModel) + { + var sql = "EXEC mobile_proc_OTPRequest @flag='REQUEST' "; + sql += ", @USER_ID = " + _connHelper.FilterString(requestOTPModel.CreatedBy); + sql += ", @OTP_CODE = " + _connHelper.FilterString(requestOTPModel.OTP); + sql += ", @REQUEST_FOR = " + _connHelper.FilterString(requestOTPModel.requestFor); + sql += ", @RECEIVER_ID = " + _connHelper.FilterString(requestOTPModel.receiverId); + _logger.LogDebug("RequestOTP | SQL : {0}", sql); + var _dbRes = _connHelper.ParseDbResult(sql); + _logger.LogDebug("RequestOTP | DB RESPONSE : " + JsonConvert.SerializeObject(_dbRes)); + List successCode = new List { "0", "100", "103" }; + return new JsonRxResponse + { + ErrorCode = successCode.Contains(_dbRes.ResponseCode.ToString()) ? "0" : "1", + Msg = _dbRes.ResponseMessage, + Id = _dbRes.Id, + Extra = _dbRes.Extra, + Extra2 = _dbRes.Extra2 + }; + } + public async Task VerifyOtp(RequestOTPModel requestOTPModel, LoginResponse logindetails) + { + JsonRxResponse _response; + try + { + var sql = "EXEC mobile_proc_OTPRequest @flag='SUBMIT' "; + sql += " ,@USER_ID = " + _connHelper.FilterString(requestOTPModel.CreatedBy); + sql += ", @OTP_CODE = " + _connHelper.FilterString(requestOTPModel.OTP.Trim()); + sql += ", @REQUEST_FOR = " + _connHelper.FilterString(requestOTPModel.requestFor); + sql += ", @RECEIVER_ID = " + _connHelper.FilterString(requestOTPModel.receiverId); + _logger.LogDebug("SubmitOTP | Lang {0} | SQL : {1}", sql); + var _dbRes = _connHelper.ParseDbResult(sql); + _response = new JsonRxResponse + { + ErrorCode = _dbRes.ResponseCode.ToString(), + Msg = _dbRes.ResponseMessage + }; + } + catch (Exception ex) + { + _logger.LogError("Error in VerifyOtp: {0}", ex.Message); + _response = new JsonRxResponse { ErrorCode = "1", Msg = "An error occurred while verifying OTP." }; + } + return await Task.FromResult(_response); + } } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/IAccountRepository.cs b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/IAccountRepository.cs index bc994b3..354c37a 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/IAccountRepository.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/IAccountRepository.cs @@ -8,5 +8,7 @@ namespace CustomerOnlineV2.Repository.Repository.AccountRepository Task ChangePassword(ForceChangePasswordModel model, LoginResponse logindetails); Task Login(LoginModel model); Task PasswordReset(PasswordResetModel model, LoginResponse logindetails); + Task VerifyOtp(RequestOTPModel requestOTPModel, LoginResponse logindetails); + JsonRxResponse RequestOTP(RequestOTPModel requestOTPModel); } } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/IRegisterRepository.cs b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/IRegisterRepository.cs index 7f7d3df..b571bb2 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/IRegisterRepository.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/IRegisterRepository.cs @@ -12,10 +12,10 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository { public interface IRegisterRepository { - Task AddRegisterDetails(OnlineCustomerRegisterModel register); + Task AddRegisterDetails(OnlineCustomerRegisterModel register); Task GetTranCustomerById(LoginResponse loginDetails); Task GetAllNotificationDetails(LoginResponse loginDetails); - Task UpdateCustomers1(CustomerListModel model, string id); + Task UpdateCustomers1(CustomerListModel model, string id); Task GetRewardPoints(LoginResponse loginDetails); Task UpdateDocument1(CustomerListModel model, string id); } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/RegisterRepository.cs b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/RegisterRepository.cs index 9251431..ec26094 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/RegisterRepository.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/RegisterRepository/RegisterRepository.cs @@ -26,8 +26,9 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository _connHelper = connHelper; } - public async Task AddRegisterDetails(OnlineCustomerRegisterModel model) + public async Task AddRegisterDetails(OnlineCustomerRegisterModel model) { + var response = new JsonRxResponse(); try { var sql = "EXEC proc_online_core_customerSetup"; @@ -60,40 +61,36 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository sql += ",@serviceUsedFor =" + _connHelper.FilterString("on"); - - - - var dt = _connHelper.ExecuteDataTable(sql); if (dt == null || dt.Rows.Count <= 0) { - model.ResponseCode = ResponseHelper.FAILED; - model.ResponseMessage = "DB Null Error!"; + response.ErrorCode = ResponseHelper.FAILED.ToString(); + response.Msg = "DB Null Error!"; + - } else if (dt.Rows[0]["ErrorCode"].Equals("0")) { - model.ResponseCode = ResponseHelper.SUCCESS; - model.ResponseMessage = "Customer is registered. Proceed to login."; + response.ErrorCode = ResponseHelper.SUCCESS.ToString(); + response.Msg = "Customer is registered. Proceed to login."; } else { - model.ResponseCode = ResponseHelper.FAILED; - model.ResponseMessage = dt.Rows[0]["Msg"].ToString(); + response.ErrorCode = ResponseHelper.FAILED.ToString(); + response.Msg = dt.Rows[0]["Msg"].ToString(); } } catch (Exception ex) { - model.ResponseCode = ResponseHelper.EXCEPTION; - model.ResponseMessage = "Exception occured: " + ex.Message; + response.ErrorCode = ResponseHelper.EXCEPTION.ToString(); + response.Msg = "Exception occured: " + ex.Message; + - } - return await Task.FromResult(model); + return await Task.FromResult(response); } public async Task GetTranCustomerById(LoginResponse loginDetails) @@ -119,7 +116,6 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository _response.ResponseCode = Convert.ToInt16(dt.Rows[0]["errorCode"]); _response.ResponseMessage = Convert.ToString(dt.Rows[0]["msg"]); - List obj = new List(); foreach (DataRow item in dt.Rows) { @@ -135,7 +131,7 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository address = Convert.ToString(item["address1"]), address2 = Convert.ToString(item["address2"]), idType = Convert.ToString(item["idType"]), - idNumber = Convert.ToString(item["idNumber"]), + idNumber = Convert.ToString(item["idNumber"]), idIssueDate = Convert.ToString(item["idIssueDate"]), idExpiryDate = Convert.ToString(item["idExpiryDate"]), nativeCountry = Convert.ToString(item["ICountryName"]) @@ -153,7 +149,7 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository } return await Task.FromResult(_response); } - public async Task GetAllNotificationDetails(LoginResponse loginDetails) + public async Task GetAllNotificationDetails(LoginResponse loginDetails) { CustomerNotificationModel _response = new CustomerNotificationModel(); try @@ -192,7 +188,7 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository Category = Convert.ToString(item["category"]), //url = Convert.ToString(item["url"]), //IsClickable = Convert.ToString(item["isClickable"]) - // notificationCount = Convert.ToString(item["notificationCount"]) + // notificationCount = Convert.ToString(item["notificationCount"]) }); } _response.NotificationModel = obj; @@ -207,12 +203,8 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository } return await Task.FromResult(_response); } - public async Task UpdateCustomers1(CustomerListModel model, string id) { - - - try { var sql = "EXEC mobile_proc_online_customerMaster_V1"; @@ -229,7 +221,7 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository - + //_logger.LogDebug("RECEIVERREPOSITORY | GETRECEIVEDRDETAILS | SQL | " + sql); var dt = _connHelper.ExecuteDataTable(sql); @@ -238,14 +230,19 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository model.ResponseCode = ResponseHelper.FAILED; model.ResponseMessage = "DB Null Error!"; - + // _logger.LogError("RECEIVERREPOSITORY | GETRECEIVEDRDETAILS | DB RESPONSE | " + JsonConvert.SerializeObject(_response)); } else { model.ResponseCode = ResponseHelper.SUCCESS; model.ResponseMessage = ResponseMessageHelper.SUCCESS; - + // _response.firstName = Convert.ToString(dt.Rows[0]["firstName"]); + // _response.middleName = Convert.ToString(dt.Rows[0]["middleName"]); + // _response.lastName1 = Convert.ToString(dt.Rows[0]["lastName1"]); + // _response.Country = Convert.ToString(dt.Rows[0]["Country"]); + // _response.Address = Convert.ToString(dt.Rows[0]["Address"]); + // _response.State = Convert.ToString(dt.Rows[0]["State"]); } } catch (Exception ex) @@ -253,7 +250,7 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository model.ResponseCode = ResponseHelper.EXCEPTION; model.ResponseMessage = "Exception occured: " + ex.Message; - + //_logger.LogError("RECEIVERREPOSITORY | GETRECEIVEDRDETAILS | EXCEPTION | " + JsonConvert.SerializeObject(_response)); } return await Task.FromResult(model); @@ -309,8 +306,7 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository } - - public async Task GetRewardPoints(LoginResponse loginDetails) + public async Task GetRewardPoints(LoginResponse loginDetails) { CustomerNotificationModel _response = new CustomerNotificationModel(); try @@ -361,7 +357,8 @@ namespace CustomerOnlineV2.Repository.Repository.RegisterRepository CustomerName = Convert.ToString(item["CUSTOMER_NAME"]), Date = Convert.ToString(item["CREATED_DATE"]), RewardPoints = Convert.ToString(item["REWARD_POINTS"]), - ReferralCode = Convert.ToString(item["REFERRAL_CODE"]), + ReferralCode = loginDetails.MembershipId, + //ReferralCode = Convert.ToString(item["REFERRAL_CODE"]), //IsRead = Convert.ToString(item["isRead"]), //Type = Convert.ToString(item["type"]), //SentId = Convert.ToString(item["sentId"]), diff --git a/CustomerOnlineV2/CustomerOnlineV2/Authorization/AuthorizationAttribute.cs b/CustomerOnlineV2/CustomerOnlineV2/Authorization/AuthorizationAttribute.cs index 361c171..ac8e5bd 100644 --- a/CustomerOnlineV2/CustomerOnlineV2/Authorization/AuthorizationAttribute.cs +++ b/CustomerOnlineV2/CustomerOnlineV2/Authorization/AuthorizationAttribute.cs @@ -1,8 +1,11 @@ -using CustomerOnlineV2.Common.Models.AccountModel; +using CustomerOnlineV2.Common.Helper; +using CustomerOnlineV2.Common.Models.AccountModel; +using CustomerOnlineV2.Common.Models.Notification; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using System.Net; using System.Security.Claims; +using System.Text; namespace CustomerOnlineV2.Authorization { @@ -34,7 +37,7 @@ namespace CustomerOnlineV2.Authorization _loginData.UserName = claimsIndentity.FindFirst(c => c.Type == "UserName").Value; _loginData.SessionId = claimsIndentity.FindFirst(c => c.Type == "SessionId").Value; _loginData.ForceChangePassword = Convert.ToBoolean(claimsIndentity.FindFirst(c => c.Type == "ForceChangePassword").Value); - _loginData.IsEmailVerified = Convert.ToBoolean(claimsIndentity.FindFirst(c => c.Type == "IsEmailVerified").Value); + //_loginData.IsEmailVerified = Convert.ToBoolean(claimsIndentity.FindFirst(c => c.Type == "IsEmailVerified").Value); if (string.IsNullOrEmpty(_loginData.UserName)) { @@ -48,12 +51,12 @@ namespace CustomerOnlineV2.Authorization return; } - if (!_loginData.IsEmailVerified) - { - context.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; - context.HttpContext.Response.Redirect("/Account/VerifyOTP"); - return; - } + //is Email Verified + //{ + // context.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; + // context.HttpContext.Response.Redirect("/Account/VerifyOTP"); + // return; + //} //force change password if (_loginData.ForceChangePassword) diff --git a/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs b/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs index c8db7e7..c40cf98 100644 --- a/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs +++ b/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs @@ -1,17 +1,16 @@ using CustomerOnlineV2.Business.Business.AccountBusiness; using CustomerOnlineV2.Common.Helper; -using CustomerOnlineV2.Common.Models.AccountModel; using CustomerOnlineV2.Common.Models; -using Microsoft.AspNetCore.Authentication.Cookies; +using CustomerOnlineV2.Common.Models.AccountModel; using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; -using Serilog.Context; using Serilog; +using Serilog.Context; using System.Security.Claims; using System.Web; -using System.Security.Permissions; namespace CustomerOnlineV2.Controllers { @@ -41,6 +40,7 @@ namespace CustomerOnlineV2.Controllers return View(); } + [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] @@ -75,13 +75,18 @@ namespace CustomerOnlineV2.Controllers new Claim("SessionId", result.SessionId), new Claim("UserId", result.UserId), new Claim("MembershipId", result.MembershipId), - new Claim("IsEmailVerified", Convert.ToString(result.IsEmailVerified)) + //new Claim("IsEmailVerified", Convert.ToString(result.IsEmailVerified)), }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); + if (!result.IsEmailVerified) + { + Log.Information("ACCOUNTCONTROLLER | LOGIN | VERIFY OTP"); + return RedirectToAction("VerifyOTP", "Account"); + } if (result.ForceChangePassword) { Log.Information("ACCOUNTCONTROLLER | LOGIN | FORCE CHANGE PASSWORD"); @@ -186,5 +191,128 @@ namespace CustomerOnlineV2.Controllers } } } + + public async Task VerifyOTP(RequestOTPModel requestOTPModel) + { + requestOTPModel.sessionId = Guid.NewGuid().ToString().Replace("-", ""); + var loginDetails = HttpContext.GetLoginDetails(); + string userEmail = loginDetails.UserName; + try + { + if (!loginDetails.IsEmailVerified) + { + requestOTPModel.ProcessId = Guid.NewGuid().ToString(); + requestOTPModel.MethodName = "RequestOTP"; + requestOTPModel.CreatedBy = userEmail; + requestOTPModel.IpAddress = ""; + requestOTPModel.requestFor = "REGISTER"; + Log.Debug("RequestOTP | REQUEST : " + JsonConvert.SerializeObject(requestOTPModel)); + var staticDataResponse = _accountBusiness.RequestOTP(requestOTPModel); + if (staticDataResponse.ErrorCode == "0") + { + var viewModel = new VerifyOtpModel + { + Email = userEmail, + otp = "", + }; + ViewBag.ResponseCode = "0"; + ViewBag.ResponseMessage = "OTP has been sent."; + return View(viewModel); + } + else + { + ViewBag.ResponseCode = staticDataResponse.ErrorCode; + ViewBag.ResponseMessage = staticDataResponse.Msg; + _logger.LogError("ACCOUNTCONTROLLER | REQUESTOTP | ERROR OCCURED | " + JsonConvert.SerializeObject(staticDataResponse)); + return View(); + } + } + return View("ErrorViewName"); + } + catch (Exception ex) + { + _logger.LogError("An error occurred in VerifyOtp action.", ex); + return View("ErrorViewName"); + } + } + + [HttpPost] + [ValidateAntiForgeryToken] + public async Task VerifyOtp(RequestOTPModel requestOTPModel) + { + try + { + var loginDetails = HttpContext.GetLoginDetails(); + + if (string.IsNullOrEmpty(loginDetails.UserName)) + { + _logger.LogError("ACCOUNTCONTROLLER | VERIFYOTP | INVALID logindetails.UserName"); + return RedirectToAction("Index", "Account"); + } + + requestOTPModel.ProcessId = Guid.NewGuid().ToString(); + requestOTPModel.MethodName = "SubmitOTP"; + requestOTPModel.CreatedBy = loginDetails.Email; + requestOTPModel.IpAddress = ""; + requestOTPModel.requestFor = "REGISTER"; + + using (LogContext.PushProperty("DebugId", loginDetails.UserName)) + { + _logger.LogDebug("ACCOUNTCONTROLLER | VERIFYOTP | REQUEST | " + JsonConvert.SerializeObject(requestOTPModel)); + + var response = await _accountBusiness.VerifyOtp(requestOTPModel, loginDetails); + Log.Debug("verify OTP response: " + JsonConvert.SerializeObject(response)); + + if (response.ErrorCode == ResponseHelper.SUCCESS.ToString()) + { + var currentUser = HttpContext.User as ClaimsPrincipal; + var identity = currentUser?.Identity as ClaimsIdentity; + if (identity != null) + { + var isEmailVerifiedClaim = identity.FindFirst("IsEmailVerified"); + if (isEmailVerifiedClaim != null) + { + identity.RemoveClaim(isEmailVerifiedClaim); + } + identity.AddClaim(new Claim("IsEmailVerified", "true")); + + } + Log.Debug("ACCOUNTCONTROLLER | VERIFYOTP | REQUEST ARRIVED | " + loginDetails.Email); + return RedirectToAction("Index", "Home"); + } + else + { + ViewBag.ResponseCode = response.ErrorCode; + ViewBag.ResponseMessage = response.Msg; + _logger.LogError("ACCOUNTCONTROLLER | LOGIN | ERROR OCCURRED | " + JsonConvert.SerializeObject(response)); + return View(); + } + } + } + catch (Exception ex) + { + _logger.LogError("An error occurred in VerifyOtp action.", ex); + return RedirectToAction("Index", "Account"); + } + } + + private async Task ResetIsEmailVerifiedClaimAsync(string email, bool newIsEmailVerifiedValue) + { + var existingClaims = (ClaimsIdentity)User.Identity; + + var existingIsEmailVerifiedClaim = existingClaims.FindFirst("IsEmailVerified"); + if (existingIsEmailVerifiedClaim != null) + { + existingClaims.RemoveClaim(existingIsEmailVerifiedClaim); + } + + // Add a new "IsEmailVerified" claim with the updated value + var newIsEmailVerifiedClaim = new Claim("IsEmailVerified", newIsEmailVerifiedValue.ToString()); + existingClaims.AddClaim(newIsEmailVerifiedClaim); + + // Sign in again with the updated claims + await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(existingClaims)); + } + } } diff --git a/CustomerOnlineV2/CustomerOnlineV2/Views/Account/VerifyOTP.cshtml b/CustomerOnlineV2/CustomerOnlineV2/Views/Account/VerifyOTP.cshtml new file mode 100644 index 0000000..00d6c47 --- /dev/null +++ b/CustomerOnlineV2/CustomerOnlineV2/Views/Account/VerifyOTP.cshtml @@ -0,0 +1,255 @@ +@model CustomerOnlineV2.Common.Models.AccountModel.VerifyOtpModel + +@{ + Layout = null; +} + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+
+
+
+
+

Verify OTP

+
Please enter the 6-digit code sent to your email address
+

+
+ @*
*@ + +
+ + +
+ +
+ + +
+ + + @*
+
+ + +
+
+ +
+
*@ +
+
+
+ +
+
+ +
+
+
+ + + + +
+ +
Dont have username ? Registration won't take more than 5 min, Register Now
+
Already registered, Login Now
+ +
+ +
+
+
+
+ + Email Address + info@imelondon.co.uk +
+
+ + Contact Numbers + +44 02088660307 + +44 07984713677 +
+
+ + Our Head Office + Pentax House, South Hill Avenue, South Harrow, London, HA2 0DU +
+
+
+
+
+
+ + + + + +
+
+
+
+
+
+
+

+ IME London is a product of Subhida UK Limited, Pentax House,South Hill Avenue, South Harrow, London, H2A 0D + + Company Registration No. 06432399 Subhida UK Ltd is authorized and regulated by the Financial Conduct + Authority (FCA)
under the Payment Service Regulations 2017. FCA Registration No. 576127 HMRC Registration No. XYML000000119350 +

+
+
+
+

© IME London, 2023

+
+
+
+ + + + diff --git a/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml b/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml index d738b9a..3649f52 100644 --- a/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml +++ b/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml @@ -547,15 +547,15 @@ async: true, success: function (response) { EnableRegisterButton(); - if (response.responseCode != 0) { - ShowAlertMessageErrorOnly(response.responseCode, response.responseMessage); + if (response.errorCode != 0) { + ShowAlertMessageErrorOnly(response.errorCode, response.msg); //ShowAlertMessage("Receiver Successfully created") return false; } // window.location.replace("/account/index"); - ShowAlertMessage(response.responseCode, response.responseMessage, "/account/index"); + ShowAlertMessage(response.errorCode, response.msg, "/account/index"); }, diff --git a/CustomerOnlineV2/CustomerOnlineV2/Views/Transaction/Receipt.cshtml b/CustomerOnlineV2/CustomerOnlineV2/Views/Transaction/Receipt.cshtml index 30069bd..af3a677 100644 --- a/CustomerOnlineV2/CustomerOnlineV2/Views/Transaction/Receipt.cshtml +++ b/CustomerOnlineV2/CustomerOnlineV2/Views/Transaction/Receipt.cshtml @@ -110,6 +110,12 @@ @Utilities.ShowDecimal(Model.TransferFee) @Model.CollectionCurrency + + Reward Amount Used : + + @Model.PromotionDiscount + + Total Sent Amount : @@ -159,22 +165,17 @@ @Model.PurposeOfRemit - + @* Promotion Premium Rate* : @Model.PromotionPremiumRate - + *@ - - Promotion Discount* : - - @Model.PromotionDiscount - - + Paid by :