示例#1
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            try
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

                //کد قبلی
                //if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))

                if (user == null)
                {
                    throw new Exception("کاربر مورد نظر در سیستم موجود نیست یا تایید نشده است.");
                }

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

                var callbackUrl = Url.Action("ResetPassword", "Authentication", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                EmailServices.ForgotPassword(user.Firstname, user.Lastname, callbackUrl, user.Email, user.Id);

                model.IsSuccess = true;
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(View(url + "ForgotPassword.cshtml", model));
        }