Exemple #1
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordFormModel formModel)
        {
            var form = Service.GetForm(SiteContext.Current, formModel.Id);

            if (form != null)
            {
                var formErrors = GetFormErrors(ModelState);

                if (formErrors == null)
                {
                    form.PostedSuccessfully = true;

                    var user = await SecurityService.GetUserByNameAsync(formModel.Email);

                    if (user != null)
                    {
                        string callbackUrl = Url.Action("ResetPassword", "Account",
                                                        new { UserId = user.Id, Code = "token" }, protocol: Request.Url.Scheme);

                        await SecurityService.GenerateResetPasswordTokenAsync(
                            user.Id, Context.Shop.Name, callbackUrl);
                    }
                    else
                    {
                        form.Errors             = new SubmitFormErrors("form", "User not found");
                        form.PostedSuccessfully = false;
                    }
                }
                else
                {
                    form.Errors             = formErrors;
                    form.PostedSuccessfully = false;
                }
            }
            else
            {
                Context.ErrorMessage = "Liquid error: Form context was not found.";

                return(View("error"));
            }

            return(new RedirectResult(Url.Action("Login", "Account") + "#recover"));
        }
        public async Task <IActionResult> ForgotPasswordForm(ForgotPasswordFormModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user != null)
                {
                    await user.ForgotPasswordAsync();

                    return(RedirectToAction("RecoverPasswordForm", new { email = model.Email }));
                }
                else
                {
                    ModelState.AddModelError("ForgotPasswordFormError", "User was not found");
                    return(View(model));
                }
            }

            return(View(model));
        }
Exemple #3
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordFormModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByEmailAsync(model.Email);

                if (user == null)// || !(await userManager.IsEmailConfirmedAsync(user)))
                {
                    return(RedirectToAction(nameof(ForgotPasswordConfirmation)));
                }

                var code = await userManager.GeneratePasswordResetTokenAsync(user);

                var resetLink = Url.Action("ResetPassword",
                                           "Account", new { code },
                                           protocol: HttpContext.Request.Scheme);
                await emailSender.SendEmailAsync(model.Email, "Reset Password",
                                                 $"Please reset your password by clicking <a href='{resetLink}'>here</a>");

                return(RedirectToAction(nameof(ForgotPasswordConfirmation)));
            }

            return(View(model));
        }