public async Task <IActionResult> ConfirmOtp([FromBody] RequestOtpConfirmation payload) { await _otpService.ConfirmOtpAsync(payload); return(StatusCode(StatusCodes.Status200OK, new Response(true, HttpStatusCode.OK, Messages.Misc_Success))); }
public async Task ConfirmOtpAsync(RequestOtpConfirmation payload) { var token = await _otpTokenRepository.GetUnusedByWalletIdAndMobileNumber(payload.WalletId, payload.Person.MobileNumber.ToString()); if (token == default || token.ExpireAt <= DateTime.UtcNow || token.Code != payload.Otp) { throw new ValidationException(Messages.Token_OTPNotExist); } token.isUsed = true; _otpTokenRepository.Update(token); await _otpTokenRepository.SaveAsync(); await _credentialService.CreatePersonAndCovidTestCredentials(payload.CovidTest, payload.Person, payload.WalletId); }
//TODO: Improve this public async Task <OtpConfirmationResponse> ConfirmOtpAsync(RequestOtpConfirmation payload, string authToken) { var authTokenDetails = _tokenService.GetDetailsFromToken(authToken); var token = await _otpTokenRepository.GetAsync(authTokenDetails.OtpId); if (token == default || token.isUsed || token.ExpireAt <= DateTime.UtcNow || token.Code != payload.Otp) { throw new ValidationException(Messages.Token_OTPNotExist); } token.isUsed = true; _otpTokenRepository.Update(token); await _otpTokenRepository.SaveAsync(); var wallet = await _walletRepository.GetAsync(Guid.Parse(authTokenDetails.WalletId)); if (wallet == null) { throw new NotFoundException(Messages.Wallet_NotFound); } wallet.MobileNumberVerifiedAt = DateTime.UtcNow; _walletRepository.Update(wallet); await _walletRepository.SaveAsync(); var fileReference = await _amazonS3Broker.AddImageToBucket(payload.WalletDetails.Photo, Guid.NewGuid().ToString()); payload.WalletDetails.Photo = fileReference; var key = _cryptoService.GenerateEncryptedSecretKey(); await _walletDetailService.AddWalletDetails(wallet, payload.WalletDetails, key); return(new OtpConfirmationResponse() { WalletId = wallet.Id.ToString(), Key = key }); }