From 7b1c83482c59138d932216d0616942476db6d834 Mon Sep 17 00:00:00 2001 From: shakun Date: Mon, 30 Oct 2023 17:53:55 +0545 Subject: [PATCH] OTP fix --- .../AccountBusiness/AccountBusiness.cs | 10 ++-- .../AccountRepository/AccountRepository.cs | 3 +- .../Controllers/AccountController.cs | 23 ++++++--- .../Views/Account/VerifyOTP.cshtml | 50 +++++++++++++------ .../Customer/CustomerRegistration.cshtml | 3 +- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs index 3c41463..f70b271 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Business/Business/AccountBusiness/AccountBusiness.cs @@ -165,10 +165,8 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness { bool emailSent = false; bool smsSent = false; - if (requestOTPModel.userId.IsValidEmail()) - { - if (!string.IsNullOrEmpty(jsonRx.ErrorCode) && jsonRx.ErrorCode.Equals("0")) + if (!string.IsNullOrEmpty(jsonRx.ErrorCode) && (jsonRx.ErrorCode.Equals("0") && jsonRx.Extra3.Equals("100"))) { List bodyMappings = new List(); @@ -221,7 +219,7 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness StringBuilder s = new StringBuilder(); s.AppendLine($"Dear {jsonRx.Extra}"); - s.AppendLine($"Your OTP code for Customer Registration is {requestOTPModel.OTP}."); + s.AppendLine($"Your OTP code for Customer Registration is {jsonRx.Id}."); s.AppendLine("Regards, IME London"); SMSRequestModel _req = new SMSRequestModel @@ -254,13 +252,13 @@ namespace CustomerOnlineV2.Business.Business.AccountBusiness return jsonRx; } } - } + } else { jsonRx.ErrorCode = "1"; - return new JsonRxResponse { ErrorCode = jsonRx.ErrorCode, Msg = jsonRx.Msg }; + return new JsonRxResponse { ErrorCode = jsonRx.ErrorCode, Msg = jsonRx.Msg , Id= jsonRx.Id, Extra3= jsonRx.Extra3 }; } diff --git a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs index 78dc442..82c8267 100644 --- a/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs +++ b/CustomerOnlineV2/CustomerOnlineV2.Repository/Repository/AccountRepository/AccountRepository.cs @@ -138,7 +138,8 @@ namespace CustomerOnlineV2.Repository.Repository.AccountRepository Msg = _dbRes.ResponseMessage, Id = _dbRes.Id, Extra = _dbRes.Extra, - Extra2 = _dbRes.Extra2 + Extra2 = _dbRes.Extra2, + Extra3= _dbRes.ResponseCode.ToString() }; } public async Task SubmitOTP(RequestOTPModel requestOTPModel, LoginResponse logindetails) diff --git a/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs b/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs index 99af1f2..0ca94eb 100644 --- a/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs +++ b/CustomerOnlineV2/CustomerOnlineV2/Controllers/AccountController.cs @@ -193,6 +193,7 @@ namespace CustomerOnlineV2.Controllers } } + [Authorization("VerifyOTP")] public async Task VerifyOTP(RequestOTPModel requestOTPModel) { requestOTPModel.sessionId = Guid.NewGuid().ToString().Replace("-", ""); @@ -209,23 +210,30 @@ namespace CustomerOnlineV2.Controllers 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 = "", }; + if (staticDataResponse.ErrorCode == "0" && staticDataResponse.Extra3.Equals("100")) + { ViewBag.ResponseCode = "0"; ViewBag.ResponseMessage = "OTP has been sent."; return View(viewModel); } else { + if (staticDataResponse.Extra3.Equals("103")) + { + ViewBag.ResponseCode = "103"; + ViewBag.ResponseMessage = "OTP already has been sent."; + return View(viewModel); + } ViewBag.ResponseCode = staticDataResponse.ErrorCode; ViewBag.ResponseMessage = staticDataResponse.Msg; _logger.LogError("ACCOUNTCONTROLLER | REQUESTOTP | ERROR OCCURED | " + JsonConvert.SerializeObject(staticDataResponse)); - return View(); + return View(viewModel); } } return View("ErrorViewName"); @@ -244,6 +252,7 @@ namespace CustomerOnlineV2.Controllers { try { + ViewBag.ResponseCode = ""; var loginDetails = HttpContext.GetLoginDetails(); if (string.IsNullOrEmpty(loginDetails.UserName)) @@ -268,14 +277,14 @@ namespace CustomerOnlineV2.Controllers if (response.ErrorCode == "0") { Log.Debug("ACCOUNTCONTROLLER | SubmitOTP | REQUEST ARRIVED | " + loginDetails.Email); - return RedirectToAction("Index", "Home"); + return Ok(new { ErrorCode = response.ErrorCode, ResponseMessage = response.Msg }); } else { - ViewBag.ResponseCode = response.ErrorCode; - ViewBag.ResponseMessage = response.Msg; + //ViewBag.ResponseCode = response.ErrorCode; + //ViewBag.ResponseMessage = response.Msg; _logger.LogError("ACCOUNTCONTROLLER | LOGIN | ERROR OCCURRED | " + JsonConvert.SerializeObject(response)); - return View(); + return Ok(new { ErrorCode = response.ErrorCode, ResponseMessage =response.Msg }); } } } diff --git a/CustomerOnlineV2/CustomerOnlineV2/Views/Account/VerifyOTP.cshtml b/CustomerOnlineV2/CustomerOnlineV2/Views/Account/VerifyOTP.cshtml index 9d5e4b0..467e5c4 100644 --- a/CustomerOnlineV2/CustomerOnlineV2/Views/Account/VerifyOTP.cshtml +++ b/CustomerOnlineV2/CustomerOnlineV2/Views/Account/VerifyOTP.cshtml @@ -86,7 +86,7 @@
- +
@@ -107,7 +107,7 @@
-
@@ -183,25 +183,37 @@ $(document).ready(function () { - if ('@ViewBag.ResponseCode' != '0') { - iziToast.error({ - title: 'Error', + if ('@ViewBag.ResponseCode' == '0') { + iziToast.success({ + title: 'OK', message: '@ViewBag.ResponseMessage' }); } - else { - iziToast.success({ - title: 'OK', + else if ('@ViewBag.ResponseCode' == '103') { + iziToast.info({ + title: 'Info', + message: '@ViewBag.ResponseMessage' + }); + } + else if ('@ViewBag.ResponseCode' == '1') { + iziToast.error({ + title: 'Error', message: '@ViewBag.ResponseMessage' }); } - }); function SubmitOTP() { let email = $('#Email').val(); let otp = $('#otp').val(); + if (otp.length === 0) { + iziToast.error({ + title: 'Error', + message: 'OTP field is required' + }); + return; + } let Data = { Email: email, @@ -222,21 +234,29 @@ }, async: true, success: function (response) { - + debugger; if (response.errorCode == 0) { - debugger - ShowAlertMessage(response.errorCode, response.msg); + iziToast.info({ + title: 'OK', + onClosed: function () { window.location.replace("/home"); + } + }); } else { - debugger - ShowAlertMessage(response.errorCode, response.msg); + iziToast.error({ + title: 'Error', + message: response.responseMessage + }); } }, error: function () { - ShowAlertMessage(response.errorCode, response.msg); + iziToast.error({ + title: 'Error', + message: response.responseMessage + }); } }); } diff --git a/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml b/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml index c8e6efb..8fc87fb 100644 --- a/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml +++ b/CustomerOnlineV2/CustomerOnlineV2/Views/Customer/CustomerRegistration.cshtml @@ -592,7 +592,8 @@ } // window.location.replace("/account/index"); - ShowAlertMessage(response.errorCode, response.msg, "/account/index"); + ShowAlertMessage(response.errorCode, response.msg, "/Account/VerifyOTP"); + // ShowAlertMessage(response.errorCode, response.msg, "/account/index"); },