public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
     }
     // If we got this far, something failed, redisplay form
     ModelState.AddModelError("", "Failed to verify phone");
     return View(model);
 }
Exemple #2
0
 public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
     }
     // ここに到達した場合は何らかの問題が発生しているので、フォームを再表示します。
     ModelState.AddModelError("", "電話番号を確認できませんでした");
     return View(model);
 }
Exemple #3
0
 public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
     }
     // 如果我们进行到这一步时某个地方出错,则重新显示表单
     ModelState.AddModelError("", "无法验证电话号码");
     return View(model);
 }
 public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
     }
     // Это сообщение означает наличие ошибки; повторное отображение формы
     ModelState.AddModelError("", "Не удалось проверить телефон");
     return View(model);
 }
 public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInAsync(user, isPersistent: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
     }
     //Si nous sommes arrivés là, quelque chose a échoué, réafficher le formulaire
     ModelState.AddModelError("", "La vérification du téléphone a échoué");
     return View(model);
 }
Exemple #6
0
 public async Task<IActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var user = await GetCurrentUserAsync();
     if (user != null)
     {
         var result = await UserManager.ChangePhoneNumberAsync(user, model.PhoneNumber, model.Code);
         if (result.Succeeded)
         {
             await SignInManager.SignInAsync(user, isPersistent: false);
             return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
         }
     }
     // If we got this far, something failed, redisplay the form
     ModelState.AddModelError(string.Empty, "Failed to verify phone number");
     return View(model);
 }
 public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
     }
     // Se si è arrivati a questo punto, significa che si è verificato un errore, rivisualizzare il form
     ModelState.AddModelError("", "Verifica del numero di telefono non riuscita");
     return View(model);
 }
 public async Task<ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.PhoneNumber, model.Code);
     if (result.Succeeded)
     {
         var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
         if (user != null)
         {
             await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
         }
         return RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess });
     }
     // Si llegamos a este punto, es que se ha producido un error, volvemos a mostrar el formulario
     ModelState.AddModelError("", "No se ha podido comprobar el teléfono");
     return View(model);
 }