Example #1
0
        public async Task <IActionResult> SendCode([FromBody] SendCodeViewModel model)
        {
            var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();

            if (user == null)
            {
                return(BadRequest("Error"));
            }

            // Generate the token and send it
            var code = await _userManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider);

            if (string.IsNullOrWhiteSpace(code))
            {
                return(BadRequest("Error"));
            }

            var message = "Your security code is: " + code;

            if (model.SelectedProvider == "Email")
            {
                await _emailSender.SendEmailAsync(MailType.SecurityCode, new EmailModel { }, null);

                //await _emailSender.SendEmailAsync(Email, await _userManager.GetEmailAsync(user), "Security Code", message);
            }
            else if (model.SelectedProvider == "Phone")
            {
                await _smsSender.SendSmsTwillioAsync(await _userManager.GetPhoneNumberAsync(user), message);
            }

            return(RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe }));
        }
        public async Task <IActionResult> AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            // Generate the token and send it
            var user = await GetCurrentUserAsync();

            var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, model.PhoneNumber);

            await _smsSender.SendSmsTwillioAsync(model.PhoneNumber, "Your security code is: " + code);

            return(RedirectToAction(nameof(VerifyPhoneNumber), new { PhoneNumber = model.PhoneNumber }));
        }