コード例 #1
0
        public async Task <IActionResult> Create(ApplicationUser user)
        {
            if (ModelState.IsValid)
            {
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    if (!user.EmailConfirmed)
                    {
                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, confirmCode = code }, protocol: HttpContext.Request.Scheme);
                        var body        = await _emailTemplate.RenderViewToString(@"/Views/Email/ActivateEmail", new ActivateEmail()
                        {
                            Emailaddress = user.Email, Callback = callbackUrl
                        });

                        await _emailSender.SendEmailAsync(user.Email, T["Confirm your account"], body);

                        return(new JsonResult(new { success = "dbc.snackbar", data = "An Email is send to user" }));
                    }
                    return(new EmptyResult());
                }
                else
                {
                    AddErrors(result);
                }
            }
            return(PartialView(user));
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: Medella/DBC
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View(nameof(ForgotPasswordConfirmation), model));
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                // Send an email with this link
                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var callbackUrl = Url.Action(nameof(ResetPassword), "Account", new { userId = user.Id, code = code }, protocol: HttpContext?.Request?.Scheme);
                var body        = await _emailTemplate.RenderViewToString(@"/Views/Email/ResetPasswordEmail", new ActivateEmail()
                {
                    Emailaddress = user.Email, Callback = callbackUrl
                });

                await _emailSender.SendEmailAsync(model.Email, T["Reset password"], body);

                //show a screen that the use should check hit email

                return(View(nameof(ForgotPasswordConfirmation), model));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }