public async Task<IActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     // Generate the token and send it
     var user = await GetCurrentUserAsync();
     var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.PhoneNumber);
     await _smsSender.SendSmsAsync(model.PhoneNumber, "Your security code is: " + code);
     return RedirectToAction(nameof(VerifyPhoneNumber), new { PhoneNumber = model.PhoneNumber });
 }
Beispiel #2
0
 public async Task<ActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     // Создание и отправка маркера
     var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number);
     if (UserManager.SmsService != null)
     {
         var message = new IdentityMessage
         {
             Destination = model.Number,
             Body = "Ваш код безопасности: " + code
         };
         await UserManager.SmsService.SendAsync(message);
     }
     return RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number });
 }
Beispiel #3
0
 public async Task<ActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     // Generate the token and send it
     var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number);
     if (UserManager.SmsService != null)
     {
         var message = new IdentityMessage
         {
             Destination = model.Number,
             Body = "Your security code is: " + code
         };
         await UserManager.SmsService.SendAsync(message);
     }
     return RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number });
 }
Beispiel #4
0
        public async Task<ActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), model.Number);
            var result = await UserManager.ChangePhoneNumberAsync(User.Identity.GetUserId(), model.Number, 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);

            // Создание и отправка маркера

            if (UserManager.SmsService != null)
            {
                var message = new IdentityMessage
                {
                    Destination = model.Number,
                    Body = "Ваш код безопасности: " + code
                };
                await UserManager.SmsService.SendAsync(message);
            }
            return RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number });
        }