public async Task <IActionResult> ConfirmPhone(string ConfirmCode) { try { var verification = await VerificationCheckResource.CreateAsync( to : "+84396987327", code : "439294", pathServiceSid : "XXX" ); if (verification.Status == "approved") { return(RedirectToAction("Index", "Home")); } else { return(View(ConfirmCode)); } } catch (System.Exception ex) { ViewBag.ErrorMessage = ex.Message; return(View(ConfirmCode)); } }
/// <summary> /// Asynchronously verify the phone code that the user inputted via Twilio. /// </summary> /// <param name="phoneNumber">The phone number the verification code was sent to (string)</param> /// <param name="phoneCode">User-inputtted phone code, attempt to match what was sent (string)</param> /// <returns>String indicating whether the verification was approved, is still pending, or failed</returns> public async Task <string> VerifyPhoneCodeAsync(string phoneNumber, string phoneCode) { // Must catch twilio.exceptions.twilioapiexception if they try to verify after expiration time or if the phone number // was not used in a verification. try { // Initiate the API with the credentials defined in the constants file. string accountSID = Constants.TwilioAccountSID; string authorizationToken = Constants.TwilioAuthToken; TwilioClient.Init(accountSID, authorizationToken); // Asynchronously attempt to verify the inputted code that was sent to the phone number, using the path service SID. var verificationCheck = await VerificationCheckResource.CreateAsync( to : $"+1{phoneNumber}", code : $"{phoneCode}", pathServiceSid : Constants.TwilioPathServiceSID ).ConfigureAwait(false); // Return the verification status. return(verificationCheck.Status); } catch (TwilioException) { return(Constants.TwilioAuthenticationFailString); } }
public async Task VerifyConfirmationSmsCodeAsync(string number, string code) { var verification = await VerificationCheckResource.CreateAsync( to : number, code : code, pathServiceSid : smsSettings.Service ); }
public async Task <VerificationCheckResource> VerifyCode(string phoneNumber, string code) { return(await VerificationCheckResource.CreateAsync( to : phoneNumber, code : code, pathServiceSid : _settings.VerificationServiceSID )); }
public async Task <VerificationResult> ConfirmVerification(string phonenumber, string code) { var checkVerification = await VerificationCheckResource.CreateAsync(to : phonenumber, code : code, pathServiceSid : TwilioConfiguration.VerificationSid); if (checkVerification.Status == "approved") { return(new VerificationResult { Sid = checkVerification.Sid }); } throw new UserFriendlyException("There was an issue confirming your code. Please try again."); }
public async Task <string> CheckCode(string phone, string code) { TwilioInit(); try{ var verificationCheck = await VerificationCheckResource.CreateAsync( to : phone, code : code, pathServiceSid : "VA4ecd8e6e80f84392b619552df9a6ed47" ); return(verificationCheck.Status); }catch { return("Error"); } }
public async Task <IActionResult> OnPostAsync() { await this.LoadPhoneNumber(); if (!this.ModelState.IsValid) { return(this.Page()); } try { var verification = await VerificationCheckResource.CreateAsync( to : $"{this.CountryCode}{this.PhoneNumber}", code : this.VerificationCode, pathServiceSid : this.settings.VerificationServiceSID); if (verification.Status == "approved") { var identityUser = await this.userManager.GetUserAsync(this.User); identityUser.PhoneNumberConfirmed = true; var updateResult = await this.userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { var user = this.userManager.GetUserAsync(this.HttpContext.User); return(this.Redirect($"/Profile/{user.Result.UserName}")); } else { this.ModelState.AddModelError(string.Empty, "There was an error confirming the verification code, please try again"); } } else { this.ModelState.AddModelError(string.Empty, $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { this.ModelState.AddModelError( string.Empty, "There was an error confirming the code, please check the verification code is correct and try again"); } return(this.Page()); }
public async Task <IActionResult> PostVerifyPhoneCodeAsync(SMSVerification input) { await LoadPhoneNumber(); if (!ModelState.IsValid) { return(View("ConfirmPhone", input)); } try { VerificationCheckResource verification = await VerificationCheckResource.CreateAsync( to : PhoneNumber, code : input.VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var identityUser = await _userManager.GetUserAsync(User); identityUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { ViewBag.urlAppWeb = _configuration["URLAppWeb"]; return(View("ConfirmPhoneSuccess")); } else { ModelState.AddModelError("", "Erreur lors de la vérification du code, Veuillez reessayer"); } } else { ModelState.AddModelError("", $"Erreur lors de la vérification du code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "Erreur lors de la vérification, vérifiez que votre code est correct et reessayez"); } return(View("ConfirmPhone", input)); }
public async Task <IActionResult> OnPostAsync() { await LoadPhoneNumber(); if (!ModelState.IsValid) { return(Page()); } try { var verification = await VerificationCheckResource.CreateAsync( to : PhoneNumber, code : VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var applicationUser = await _userManager.GetUserAsync(User); applicationUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(applicationUser); if (updateResult.Succeeded) { return(RedirectToPage("ConfirmPhoneSuccess")); } else { ModelState.AddModelError(string.Empty, "There was an error confirming the verification code, please try again"); } } else { ModelState.AddModelError(string.Empty, $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "There was an error confirming the code, please check the verification code is correct and try again"); } return(Page()); }
public async Task <IActionResult> PostVerifyPhoneCodeAsync(SMSVerification input) { await LoadPhoneNumber(); if (!ModelState.IsValid) { return(View("ConfirmPhone", input)); } try { VerificationCheckResource verification = await VerificationCheckResource.CreateAsync( to : PhoneNumber, code : input.VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var identityUser = await _userManager.GetUserAsync(User); identityUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { return(View("ConfirmPhoneSuccess")); } else { ModelState.AddModelError("", "There was an error confirming the verification code, please try again"); } } else { ModelState.AddModelError("", $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "There was an error confirming the code, please check the verification code is correct and try again"); } return(View("ConfirmPhone", input)); }
public async Task <IActionResult> ConfirmPhone(ConfirmPhoneViewModel confirmPhoneViewModel) { if (ModelState.IsValid) { try { var verification = await VerificationCheckResource.CreateAsync( to : confirmPhoneViewModel.PhoneNumber, code : confirmPhoneViewModel.VerificationCode, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { var identityUser = await _userManager.GetUserAsync(User); identityUser.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { return(RedirectToAction("ConfirmPhoneSuccess")); } else { ModelState.AddModelError("", "There was an error confirming the verification code, please try again"); } } else { ModelState.AddModelError("", $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { ModelState.AddModelError("", "There was an error confirming the code, please check the verification code is correct and try again"); } } return(View(confirmPhoneViewModel)); }
public async Task <bool> VerifyPhoneNumber(string phoneNumber, string code) { try { var verification = await VerificationCheckResource.CreateAsync( to : phoneNumber, code : code, pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "approved") { return(true); } return(false); } catch { return(false); } }
public async Task <bool> VerifyPhoneNumber(string phonenumber, string token) { try { var verification = await VerificationCheckResource.CreateAsync( to : phonenumber, code : token, pathServiceSid : _config.GetSection("Twilio:VerificationServiceSID")?.Value ); if (verification.Status == "approved") { return(true); } return(false); } catch (Exception ex) { return(false); } }
public async Task <IActionResult> verify([FromBody] VerifyUserResource verifyUserResource) { if (!ModelState.IsValid) { return(BadRequest(0)); } var user = await userManager.FindByNameAsync(verifyUserResource.UserName); try { var verification = await VerificationCheckResource.CreateAsync( to : "+2" + verifyUserResource.Phone, code : verifyUserResource.OTP, pathServiceSid : config["Twilio:VerificationServiceSID"] ); if (verification.Status == "approved") { user.PhoneNumberConfirmed = true; await userManager.UpdateAsync(user); var tokenString = GenerateJSONWebToken(user); return(Ok(new { token = tokenString })); } else { return(BadRequest(new APIResponse { bit = false })); } } catch (Exception ex) { return(BadRequest(new APIResponse { bit = false })); } }
public async Task <IActionResult> CheckVerificationCode(string studentId, string code) { var student = await _context.Users.FindAsync(studentId); if (student == null) { return(BadRequest()); } if (string.IsNullOrEmpty(code)) { return(BadRequest("wrongCode")); } var name = $"{student.FirstName} {student.LastName}"; var email = student.Email; try { var verification = await VerificationCheckResource.CreateAsync( to : $"{student.PhoneCode}{student.PhoneNumber}", code : code, pathServiceSid : StaticInformation.TwilioVerificationServiceSid ); if (verification.Status != "approved") { return(BadRequest("wrongCode")); } return(Ok(new { name, email })); } catch (Exception e) { Console.WriteLine(e.Message); } return(BadRequest()); }
public async Task <PasswordVerificationResult> ValidarCodigoAsync(string phoneNumber, string code) { try { var verificationCheckResource = await VerificationCheckResource.CreateAsync( to : phoneNumber, code : code, pathServiceSid : VerificationSid ); return(verificationCheckResource.Status.Equals("approved") ? new PasswordVerificationResult(verificationCheckResource.Sid) : new PasswordVerificationResult(new List <string> { "Código incorreto. Tente novamente." })); } catch (TwilioException e) { return(new PasswordVerificationResult(new List <string> { e.Message })); } }
public async Task <VerificationResult> CheckVerificationAsync(string phoneNumber, string code) { try { var verificationCheckResource = await VerificationCheckResource.CreateAsync( to : phoneNumber, code : code, pathServiceSid : _config.VerificationSid ); return(verificationCheckResource.Status.Equals("approved") ? new VerificationResult(verificationCheckResource.Sid) : new VerificationResult(new List <string> { "Wrong code. Try again." })); } catch (TwilioException e) { return(new VerificationResult(new List <string> { e.Message })); } }
public async Task <IActionResult> OnPostAsync() { await this.LoadPhoneNumber(); if (!this.ModelState.IsValid) { return(this.Page()); } try { var verification = await VerificationCheckResource.CreateAsync( to : $"+{this.CountryCode}{this.PhoneNumber}", code : this.VerificationCode, pathServiceSid : this.settings.VerificationServiceSID); if (verification.Status == "approved") { var identityUser = await this.userManager.GetUserAsync(this.User); identityUser.PhoneNumberConfirmed = true; var updateResult = await this.userManager.UpdateAsync(identityUser); if (updateResult.Succeeded) { var user = this.userManager.GetUserAsync(this.HttpContext.User); var isAdded = await this.dashboardService.IsAddedUserInRole(GlobalConstants.ContributorRole, user.Result.UserName); if (isAdded) { this.TempData["Success"] = string.Format( SuccessMessages.SuccessfullyConfirmedPhoneNumberAndRegisteredContributorRole, GlobalConstants.ContributorRole); } else { this.TempData["Success"] = string.Format( SuccessMessages.SuccessfullyConfirmedPhoneNumberInContributorRole, GlobalConstants.ContributorRole); } return(this.Redirect($"/Profile/{user.Result.UserName}")); } else { this.ModelState.AddModelError(string.Empty, "There was an error confirming the verification code, please try again"); } } else { this.ModelState.AddModelError(string.Empty, $"There was an error confirming the verification code: {verification.Status}"); } } catch (Exception) { this.ModelState.AddModelError( string.Empty, "There was an error confirming the code, please check the verification code is correct and try again"); } return(this.Page()); }
public async Task <IActionResult> VerifyNumber(string code, UserDevice userDevice) { var user = await _userManager.GetUserAsync(User); if (user == null || user.PhoneNumberConfirmed) { return(BadRequest("refresh")); } if (string.IsNullOrEmpty(code)) { return(BadRequest("wrongCode")); } try { var verification = await VerificationCheckResource.CreateAsync( to : $"{user.PhoneCode}{user.PhoneNumber}", code : code, pathServiceSid : StaticInformation.TwilioVerificationServiceSid ); if (verification.Status != "approved") { return(BadRequest("wrongCode")); } } catch (Exception e) { Console.WriteLine(e.Message); return(BadRequest()); } //If we come here then the code is correct but not saved to the database user.PhoneNumberConfirmed = true; var updateResult = await _userManager.UpdateAsync(user); if (!updateResult.Succeeded) { return(BadRequest()); } try { var oldCookies = HttpContext.Request.Cookies["_ulisp"]; var oldDevices = _context.UserDevices.Where(x => x.UserId == user.Id) .Where(x => x.AuthCookies == oldCookies).OrderByDescending(x => x.DateTime).ToList(); var oldDevice = new UserDevice(); if (oldDevices.Any()) { oldDevice = oldDevices[0]; } var device = new UserDevice() { User = user, Ip = oldDevice.Ip, OperatingSystem = oldDevice.OperatingSystem, AuthCookies = oldCookies, GroupNumber = oldDevice.GroupNumber, Activity = EnumList.Activity.PhoneVerification, DeviceType = oldDevice.DeviceType }; await _context.AddAsync(device); await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e); } return(Ok()); }