Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName    = Input.Email,
                    Email       = Input.Email,
                    PhoneNumber = Input.PhoneNumber,
                    GivenName   = Input.GivenName,
                    FamilyName  = Input.FamilyName
                };

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    await _accountMailHelper.SendVerificationEmail(user);

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    if (error.Code == "DuplicateUserName")
                    {
                        ShowVerifyEmailLink = true;
                        // skip to avoid error message for username AND email
                        continue;
                    }
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPostSendVerificationEmailAsync()
        {
            await _accountMailHelper.SendVerificationEmail(Input.Email);

            if (_userManager.Options.SignIn.RequireConfirmedAccount)
            {
                return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
            }

            return(RedirectToPage());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostSendVerificationEmailAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            await _accountMailHelper.SendVerificationEmail(user);

            StatusMessage = "Verification email sent. Please check your email.";
            return(RedirectToPage());
        }