public async Task <PartialViewResult> ValidateOtp(OtpViewModel viewModel)
        {
            try
            {
                var otpSession = _otpSessionAppService.GetOtpSession(viewModel.Otp);

                var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value);

                if (otpSession.PhoneNumberSentTo != user.PhoneNumber)
                {
                    ViewBag.ErrorMessage = "Invalid OTP";
                    return(PartialView("_MoneyTransferError"));
                }

                var accountHolder = await _accountHolderAppService.GetAccountHolderDetail();

                if (accountHolder.AvailableBalance < decimal.Parse(otpSession.ActionProperty["Amount"]))
                {
                    ViewBag.ErrorMessage = "Insufficient funds. Please top up!";
                    return(PartialView("_MoneyTransferError"));
                }

                var amount = otpSession.ActionProperty["Amount"].Split(".")[0].Trim();
                await _moneyTransferAppService.TransferMoneyToBankAccount(amount, accountHolder.Bank.OneCardBankCode, accountHolder.BankAccountNumber,
                                                                          user.PhoneNumber);
            }
            catch (Exception exc)
            {
                Logger.Error(exc.StackTrace);
                ViewBag.ErrorMessage = "An error occurred. Please try again later";
                return(PartialView("_MoneyTransferError"));
            }

            return(PartialView("_TransferSuccess"));
        }
Esempio n. 2
0
        public ActionResult VerifyPhone([FromRoute] string userId, [FromBody] OtpViewModel otpViewModel)
        {
            try
            {
                var verificationToken = _verificationTokenService.GetLatestUserToken(userId);

                if (verificationToken == null || verificationToken.Token != otpViewModel.Otp)
                {
                    return(BadRequest(new { status = 400, title = "Invalid Otp" }));
                }

                if (verificationToken.IsActive != true || verificationToken.ExpiresOn < DateTime.Now)
                {
                    return(BadRequest(new { status = 400, title = $"Otp expired. Please create a new one" }));
                }

                var user = _userService.GetByUserId(verificationToken.UserId);
                if (user == null || !user.IsActive)
                {
                    return(BadRequest(new { status = 400, title = $"User does not exists" }));
                }

                if (user.UserId != verificationToken.UserId || verificationToken.TokenPurpose != TokenPurpose.PhoneVerification)
                {
                    return(BadRequest(new { status = 400, title = "Invalid Otp" }));
                }

                if (user.IsPhoneVerified)
                {
                    return(BadRequest(new { status = 400, title = $"Phone number - {user.Phone} already verified" }));
                }

                _userService.VerifyPhone(user, verificationToken);
                return(Ok(new { status = 200, title = "Phone number verified successfully." }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { status = 400, title = "Something went wrong" }));
            }
        }