Example #1
0
        public async Task <IActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await userManager.FindByIdAsync(HttpContext.User.GetUserId());

            if (user != null)
            {
                var result = await userManager.ChangePhoneNumberAsync(user, model.PhoneNumber, model.Code);

                if (result.Succeeded)
                {
                    await signInManager.SignInAsync(user, isPersistent : false);

                    this.AlertSuccess("Your phone number was added.");

                    return(RedirectToAction("Index"));
                }
            }
            // If we got this far, something failed, redisplay the form
            ModelState.AddModelError(string.Empty, "Failed to verify phone number");
            return(View(model));
        }