public async Task <IActionResult> RegisterConfirmation(string email, string returnUrl = null)
        {
            var model = new RegisterConfirmationModel();

            if (email == null)
            {
                return(RedirectToAction("Index"));
            }

            var user = await _userManager.FindByEmailAsync(email);

            if (user == null)
            {
                return(NotFound($"Unable to load user with email '{email}'."));
            }

            model.Email = email;
            // Once you add a real email sender, you should remove this code that lets you confirm the account
            model.DisplayConfirmAccountLink = true;
            if (model.DisplayConfirmAccountLink)
            {
                var userId = await _userManager.GetUserIdAsync(user);

                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                model.EmailConfirmationUrl = Url.Action("ConfirmEmail", values: new { userId = userId, code = code, returnUrl = returnUrl });
            }
            return(View());
        }
Exemple #2
0
        public async Task <IActionResult> RegisterConfirmation(RegisterConfirmationModel model)
        {
            var user = await _userManager.FindByNameAsync(model.Login);

            if (user == null)
            {
                return(RedirectToAction("Index", "Error", new ErrorModel(model.ReturnUrl)));
            }

            // Once you add a real email sender, you should remove this code that lets you confirm the account
            var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
            var callbackUrl = Url.ActionLink(nameof(ConfirmEmail), "Register",
                                             new { userId = user.Id, code, returnUrl = model.ReturnUrl });

            await _serviceBusSenderService.SendMessageToEmailQueueAsync(callbackUrl, user.Email);

            return(View(model));
        }