Esempio n. 1
0
        public virtual async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.FindByNameAsync(model.Email);

            if (user == null || !(await _userManager.IsEmailConfirmedAsync(user.Id)))
            {
                // Don't reveal that the user does not exist or is not confirmed
                return(View(MVC.Account.Views.ViewNames.ResetPasswordConfirmation));
            }

            var code = await _userManager.GeneratePasswordResetTokenAsync(user.Id);

            if (Request.Url == null)
            {
                return(View(MVC.Account.Views.ViewNames.ForgotPasswordConfirmation));
            }
            var callbackUrl = Url.Action(MVC.Account.ActionNames.ResetPassword, MVC.Account.Name,
                                         new { userId = user.Id, code }, protocol: Request.Url.Scheme);
            await _userMailer.ResetPassword(new EmailViewModel
            {
                Message  = "با سلام کاربر گرامی.برای بازیابی کلمه عبور خود لازم است بر روی لینک مقابل کلیک کنید",
                To       = model.Email,
                Url      = callbackUrl,
                UrlText  = "بازیابی کلمه عبور",
                Subject  = "بازیابی کلمه عبور",
                ViewName = MVC.UserMailer.Views.ViewNames.ResetPassword
            }
                                            ).SendAsync();

            return(View(MVC.Account.ActionNames.ForgotPasswordConfirmation, MVC.Account.Name));
        }