public async Task <IActionResult> OnPostAsync() { await LoadPhoneNumber(); try { var verification = await VerificationResource.CreateAsync( to : PhoneNumber, channel : "sms", pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "pending") { return(RedirectToPage("ConfirmPhone")); } ModelState.AddModelError("", $"There was an error sending the verification code: {verification.Status}"); } catch (Exception) { ModelState.AddModelError("", "There was an error sending the verification code, please check the phone number is correct and try again"); } return(Page()); }
public async Task <IActionResult> PostVerifyPhoneModelAsync() { await LoadPhoneNumber(); SMSVerification model = new SMSVerification(); try { VerificationResource verification = await VerificationResource.CreateAsync( to : PhoneNumber, channel : "sms", pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "pending") { model.PhoneNumber = PhoneNumber; return(View("ConfirmPhone", model)); } ModelState.AddModelError("", $"Votre verification n'est pas traitée, contactez l'admin"); } catch (Exception) { ModelState.AddModelError("", "There was an error sending the verification code, please contact admin"); } return(View("VerifyPhone", model)); }
public async Task <IActionResult> SendVerificationCode(string studentId) { var student = await _context.Users.FindAsync(studentId); if (student == null) { return(BadRequest()); } try { await VerificationResource.CreateAsync( to : $"{student.PhoneCode}{student.PhoneNumber}", channel : "sms", pathServiceSid : StaticInformation.TwilioVerificationServiceSid ); return(Ok()); } catch (Exception e) { Console.WriteLine(e.Message); } return(BadRequest()); }
public async Task <IActionResult> Register(VM_Register registerAccount) { if (ModelState.IsValid) { var isSuccess = await _services.RegisterUser(registerAccount); if (isSuccess) { try { var verification = await VerificationResource.CreateAsync( to : registerAccount.PhoneNumber, channel : "sms", pathServiceSid : "XXX" ); if (verification.Status == "pending") { return(RedirectToAction("ConfirmPhone", "Account")); } } catch (System.Exception ex) { ViewBag.ErrorMessage = ex.Message; return(View(registerAccount)); } //await _phoneServices.StartVerificationAsync(registerAccount.PhoneNumber); return(RedirectToAction("Index", "Home")); } } return(View(registerAccount)); }
public async Task <IActionResult> OnPostAsync() { await this.LoadPhoneNumber(); try { var verification = await VerificationResource.CreateAsync( to : $"{this.CountryCode}{this.PhoneNumber}", channel : "sms", pathServiceSid : this.settings.VerificationServiceSID); if (verification.Status == "pending") { return(this.RedirectToPage("ConfirmPhone")); } this.ModelState.AddModelError(string.Empty, $"There was an error sending the verification code: {verification.Status}"); } catch (Exception) { this.ModelState.AddModelError( string.Empty, "There was an error sending the verification code, please check the phone number is correct and try again"); } return(this.Page()); }
public async Task SendConfirmationSmsCodeAsync(string number) { var verification = await VerificationResource.CreateAsync( to : number, channel : "sms", pathServiceSid : smsSettings.Service ); }
public async Task <VerificationResource> SendVeryficationCode(string phoneNumber) { return(await VerificationResource.CreateAsync( to : phoneNumber, channel : "sms", pathServiceSid : _settings.VerificationServiceSID )); }
public async Task <VerificationResult> StartVerification(string phonenumber, string channel) { var resource = await VerificationResource.CreateAsync(to : phonenumber, channel : channel, pathServiceSid : TwilioConfiguration.VerificationSid); return(new VerificationResult { Sid = resource.Sid }); }
public async Task <bool> SendVerificationToPhoneNumber(string phonenumber) { var verification = await VerificationResource.CreateAsync( to : phonenumber, channel : "sms", pathServiceSid : _config.GetSection("Twilio:VerificationServiceSID")?.Value ); if (verification.Status == "pending") { return(true); } return(false); }
public async Task <string> SendCode(string phone) { TwilioInit(); try{ var verification = await VerificationResource.CreateAsync( to : phone, channel : "sms", pathServiceSid : "VA4ecd8e6e80f84392b619552df9a6ed47" ); return(verification.Status); }catch { return("Error"); } }
public async Task <string> SendPhoneNumberVerification(string phoneNumber) { try { var verification = await VerificationResource.CreateAsync( to : phoneNumber, channel : "sms", pathServiceSid : _settings.VerificationServiceSID ); return(verification.Status); } catch { return("Error"); } }
public async Task <IActionResult> SendVerificationCode(string courseId) { var user = await _userManager.GetUserAsync(User); if (user == null) { return(RedirectToAction("Error", "Home")); } if (user.PhoneNumberConfirmed) { return(RedirectToAction("Index", "Home")); } var codeSent = false; try { var verification = await VerificationResource.CreateAsync( to : $"{user.PhoneCode}{user.PhoneNumber}", channel : "sms", pathServiceSid : StaticInformation.TwilioVerificationServiceSid ); if (verification.Status == "pending") { codeSent = true; } // ToDo:: This used to send normal Message // var message = await MessageResource.CreateAsync( // body: "مرحباً عمرون 🌹\nكيف الحال", // from: new Twilio.Types.PhoneNumber("Matterix"), // to: new Twilio.Types.PhoneNumber(phoneNumber) // ); } catch (Exception e) { Console.WriteLine(e.Message); codeSent = false; } return(RedirectToAction("CheckCode", new { courseId, codeSent })); }
public async Task <VerificationResult> StartVerificationAsync(string phoneNumber, string channel) { try { var verificationResource = await VerificationResource.CreateAsync( to : phoneNumber, channel : channel, pathServiceSid : _config.VerificationSid ); return(new VerificationResult(verificationResource.Sid)); } catch (TwilioException e) { return(new VerificationResult(new List <string> { e.Message })); } }
public async Task <PasswordVerificationResult> SolicitarCodigoAsync(string phoneNumber, string channel) { try { var verificationResource = await VerificationResource.CreateAsync( to : phoneNumber, channel : channel, pathServiceSid : VerificationSid ); return(new PasswordVerificationResult(verificationResource.Sid)); } catch (TwilioException e) { return(new PasswordVerificationResult(new List <string> { e.Message })); } }
/// <summary> /// Asynchronously makes a phone call via Twilio to the <paramref name="phoneNumber"/> of the user /// indicated by the <paramref name="username"/>. The robot should ask for keyboard /// input from the user before reading them their 4 digit code, verifying a human answered the call. /// </summary> /// <param name="username">The username of the user to call (string)</param> /// <param name="phoneNumber">The phone number to call, without the 1 (string)</param> /// <returns>true if the function completes without an exception (bool)</returns> public async Task <bool> SendCallVerificationAsync(string username, string phoneNumber) { // Initiate the API with the credentials defined in the constants file. string accountSID = Constants.TwilioAccountSID; string authorizationToken = Constants.TwilioAuthToken; TwilioClient.Init(accountSID, authorizationToken); // Asynchronously send the call to the phone number, via the call channel, using the path service SID. await VerificationResource.CreateAsync( to : $"+1{phoneNumber}", channel : Constants.TwilioCallChannel, pathServiceSid : Constants.TwilioPathServiceSID ).ConfigureAwait(false); // Reset the user's phone code failures (incase of a re-send). await _userManagementService.UpdatePhoneCodeFailuresAsync(username, 0).ConfigureAwait(false); return(true); }
public async Task <IActionResult> PostVerifyPhoneModelAsync(string number = null, string id = null) { await LoadPhoneNumber(); SMSVerification model = new SMSVerification(); if (number != null) { this.PhoneNumber = number; } try { if (id != null) { ApplicationUser user = await _userManager.FindByIdAsync(id); user.PhoneNumber = this.PhoneNumber; _userManager.UpdateAsync(user); } VerificationResource verification = await VerificationResource.CreateAsync( to : PhoneNumber, channel : "sms", pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "pending") { model.PhoneNumber = PhoneNumber; return(View("ConfirmPhone", model)); } ModelState.AddModelError("", $"Your verification is not pending, please constact admin"); } catch (Exception) { ModelState.AddModelError("", "There was an error sending the verification code, please contact admin"); } return(View("VerifyPhone", model)); }
private async Task <bool> SendCode(string PhoneNumber) { try { var verification = await VerificationResource.CreateAsync( to : "+2" + PhoneNumber, channel : "sms", pathServiceSid : config["Twilio:VerificationServiceSID"] ); if (verification.Status == "pending") { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public async Task <IActionResult> Register(RegisterViewModel registerViewModel) { IDictionary <string, object> value = new Dictionary <string, object>(); if (ModelState.IsValid) { //Convet number to E.164 format string phoneNumber = ProcessPhoneNumber(registerViewModel.Number); var user = new ApplicationUser { UserName = registerViewModel.LastName + registerViewModel.IdNumber, FirstName = registerViewModel.FirstName, LastName = registerViewModel.LastName, PhoneNumber = phoneNumber, IDNumber = registerViewModel.IdNumber }; var existingNumber = _userManager.FindByPhoneNumber(phoneNumber); if (existingNumber.Result == null) { var result = await _userManager.CreateAsync(user, registerViewModel.Password); if (result.Succeeded) { //add the user to User role by default. await _userManager.AddToRoleAsync(user, "User"); await _signInManager.SignInAsync(user, isPersistent : false); if (_signInManager.IsSignedIn(User) && User.IsInRole("Admin")) { return(RedirectToAction("ListUsers", "Admin")); } try { var verification = await VerificationResource.CreateAsync( to : phoneNumber, channel : "sms", pathServiceSid : _settings.VerificationServiceSID ); if (verification.Status == "pending") { return(RedirectToAction("ConfirmPhone", new { phoneNumber = phoneNumber })); } ModelState.AddModelError("", $"There was an error sending the verification code: {verification.Status}"); } catch (Exception) { ModelState.AddModelError("", "There was an error sending the verification code, please check the phone number is correct and try again"); } } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } else { ModelState.AddModelError("", "A user has already registered with the number " + registerViewModel.Number); } } return(View(registerViewModel)); }