public async Task <ActionResult> verify([FromBody] TokenVerificationModel data) { var currentUser = await userManager.GetUserAsync(this.User); if (ModelState.IsValid) { TokenVerificationResult result; if (data.Token.Length > 4) { result = await authy.verifyTokenAsync(currentUser.AuthyId, data.Token); } else { result = await authy.verifyPhoneTokenAsync(currentUser.PhoneNumber, currentUser.CountryCode, data.Token); } logger.LogDebug(result.ToString()); if (result.Succeeded) { await addTokenVerificationClaim(currentUser); return(Ok(result)); } else { return(BadRequest(result)); } } else { return(BadRequest(ModelState)); } }
public async Task <ActionResult> Verify(TokenVerificationModel tokenVerification) { string sessionStr = HttpContext.Session.GetString(_2faVerificationModelSessionName); var verificationRequest = JsonConvert .DeserializeObject <PhoneVerificationRequestModel>(sessionStr); if (ModelState.IsValid) { var validationResult = await authy.verifyPhoneTokenAsync( verificationRequest.PhoneNumber, verificationRequest.CountryCode, tokenVerification.Token ?? "0000" ); if (validationResult.Succeeded) { return(RedirectToAction("Authy_PhoneVerified", "Customer")); } else { var modelErrors = this.GetModelStateDictionary <TokenVerificationModel>(); modelErrors.Add("Summary", new ModelStateError() { ErrorMessages = $"Mã xác thực không chính xác!! Vui lòng kiểm tra lại" }); ViewBag.ModelErrors = modelErrors; return(View("Verification", tokenVerification)); } } return(BadRequest()); }
public async Task <ActionResult> verify([FromBody] TokenVerificationModel tokenVerification) { var verificationRequest = HttpContext.Session.Get <PhoneVerificationRequestModel>("phone_verification_request"); if (ModelState.IsValid) { var validationResult = await authy.verifyPhoneTokenAsync( verificationRequest.PhoneNumber, verificationRequest.CountryCode, tokenVerification.Token ); return(Ok(validationResult)); } else { return(BadRequest(ModelState)); } }