Esempio n. 1
0
        public async Task <IActionResult> AddNewPhoneNumber(AddPhoneViewModel viewModel)
        {
            var user = await _userManager.FindByEmailAsync(viewModel.Username);

            if (user == null)
            {
                RedirectToAction("AddNewPhoneNumber");
            }
            var message = await SecurityController.GenerateCode(_userManager, user, Const.TypeGenerateAddPhoneNumber);

            if (message == null)
            {
                RedirectToAction("AddNewPhoneNumber");
            }
            var value = await SaveSms(message, viewModel.CallingCode + viewModel.PhoneNational);

            return(value ? RedirectToAction("ConfirmNewPhoneNumber", viewModel) : RedirectToAction("AddNewPhoneNumber"));
        }
Esempio n. 2
0
        public async Task <IActionResult> AddNewPhoneNumber(string username, string token, string returnUrl = "")
        {
            var typeVerify = TypeVerifyEmailError;

            try
            {
                var user = await _userManager.FindByEmailAsync(username);

                ViewData["ReturnUrl"] = returnUrl;
                if (user == null)
                {
                    return(RedirectToAction(nameof(HomeController.Error), "Home"));
                }

                if (user.EmailConfirmed)
                {
                    typeVerify = user.PhoneNumberConfirmed ? TypeVerifyEmailConfirmed : TypeVerifyEmailSuccess;
                }
                else
                {
                    var result = await _userManager.ConfirmEmailAsync(user, token);

                    if (result.Succeeded)
                    {
                        typeVerify = TypeVerifyEmailSuccess;
                    }

                    if (!user.TwoFactorEnabled)
                    {
                        return(RedirectToAction(nameof(AccountController.Login), "Account"));
                    }
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error("HttpGet SendSms: " + e.Message);
                return(RedirectToAction(nameof(HomeController.Error), "Home"));
            }

            switch (typeVerify)
            {
            case TypeVerifyEmailConfirmed:
                return(RedirectToAction(nameof(AccountController.Login), "Account"));

            case TypeVerifyEmailSuccess:
                var addPhoneViewModel = new AddPhoneViewModel();
                addPhoneViewModel.Username = username;
                var countryCode = await GetCurrentCountryCode();

                addPhoneViewModel.CountryCode  = countryCode;
                addPhoneViewModel.CountryIndex = GetIndexByCountryCode(countryCode);
                return(View(addPhoneViewModel));

            default:
                ViewBag.Error = true;
                var errorModel = new ErrorViewModel
                {
                    Title   = "Email confirmation is failed.",
                    Message = "The token for email confirmation is expired. Please check your email to verify."
                };
                return(View("Error", errorModel));
            }
        }