コード例 #1
0
    public async Task <IActionResult> ResendConfirmationEmail([FromBody] AdminResendConfirmationEmail request)
    {
        var user = await _userManager.FindByIdAsync(request.UserID.ToString());

        if (user is null)
        {
            return(BadRequest());
        }

        var confirmLink = await LinkBuilder.GetConfirmEmailLink(_userManager, user, Request);

        await _emailSendingService.SendConfirmationEmail(user, confirmLink);

        return(Ok());
    }
コード例 #2
0
    public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
    {
        returnUrl = returnUrl ?? Url.Content("~/");
        // Get the information about the user from the external login provider
        var info = await _signInManager.GetExternalLoginInfoAsync();

        if (info == null)
        {
            ErrorMessage = "Error loading external login information during confirmation.";
            return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
        }

        if (ModelState.IsValid)
        {
            var user = new FantasyCriticUser {
                Id = Guid.NewGuid(), UserName = Input.DisplayName, Email = Input.Email
            };

            var result = await _userManager.CreateAsync(user);

            if (result.Succeeded)
            {
                var fullUser = await _userManager.FindByIdAsync(user.Id.ToString());

                result = await _userManager.AddLoginAsync(fullUser, info);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                    var confirmLink = await LinkBuilder.GetConfirmEmailLink(_userManager, fullUser, Request);

                    await _emailSendingService.SendConfirmationEmail(fullUser, confirmLink);

                    await _signInManager.SignInAsync(fullUser, isPersistent : false, info.LoginProvider);

                    return(LocalRedirect(returnUrl));
                }
            }
            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
        }

        ProviderDisplayName = info.ProviderDisplayName;
        ReturnUrl           = returnUrl;
        return(Page());
    }
コード例 #3
0
    public async Task <IActionResult> OnPostAsync(string returnUrl = null)
    {
        returnUrl ??= Url.Content("~/");

        var externalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

        GoogleLogin    = externalLogins.SingleOrDefault(x => x.Name == "Google");
        MicrosoftLogin = externalLogins.SingleOrDefault(x => x.Name == "Microsoft");
        TwitchLogin    = externalLogins.SingleOrDefault(x => x.Name == "Twitch");
        DiscordLogin   = externalLogins.SingleOrDefault(x => x.Name == "Discord");

        if (ModelState.IsValid)
        {
            var user = new FantasyCriticUser {
                Id = Guid.NewGuid(), UserName = Input.DisplayName, Email = Input.Email
            };
            var result = await _userManager.CreateAsync(user, Input.Password);

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

                var fullUser = await _userManager.FindByIdAsync(user.Id.ToString());

                var confirmLink = await LinkBuilder.GetConfirmEmailLink(_userManager, fullUser, Request);

                await _emailSendingService.SendConfirmationEmail(fullUser, confirmLink);

                if (_userManager.Options.SignIn.RequireConfirmedAccount)
                {
                    return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                }
                else
                {
                    await _signInManager.SignInAsync(fullUser, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
            }
            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
        }

        // If we got this far, something failed, redisplay form
        return(Page());
    }
コード例 #4
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());
        }

        var confirmLink = await LinkBuilder.GetConfirmEmailLink(_userManager, user, Request);

        await _emailSendingService.SendConfirmationEmail(user, confirmLink);

        StatusMessage = "Verification email sent. Please check your email.";
        return(RedirectToPage());
    }
コード例 #5
0
    public async Task <IActionResult> OnPostAsync()
    {
        if (!ModelState.IsValid)
        {
            return(Page());
        }

        string message = "If you have an account, a verification email has been sent. Please check your email.";
        var    user    = await _userManager.FindByEmailAsync(Input.Email);

        if (user == null)
        {
            ModelState.AddModelError(string.Empty, message);
            return(Page());
        }

        var confirmLink = await LinkBuilder.GetConfirmEmailLink(_userManager, user, Request);

        await _emailSendingService.SendConfirmationEmail(user, confirmLink);

        ModelState.AddModelError(string.Empty, message);
        return(Page());
    }