Ejemplo n.º 1
0
        public async Task <IActionResult> PasswordReset(VerifyEmail model)
        {
            ViewBag.Title = "Password Reset";

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("PasswordReset", new { ReturnUrl = "" }));
            }

            var isEmailInDb = await AuthRepo.GetUserbyEmailAsync(model.Email);

            if (!isEmailInDb.Item1)
            {
                ViewBag.Error = isEmailInDb.Item2;
                return(RedirectToAction("PassordReset", new { ReturnUrl = "" }));
            }

            var result = await AuthRepo.GetResetPasswordToken(model.Email);

            if (!result.Item1)
            {
                ViewBag.Error = "Email does not exist, Please Enter registered Email";
            }

            var callbackUrl = UrlHelperExtensions.ActionLink(this.Url, "ResetPassword", "Auth", new { Username = result.Item2.Email, Token = result.Item3, ReturnUrl = model.ReturnUrl });
            var res         = await AuthRepo.SendResetPasswordEmail(result.Item2, callbackUrl);

            if (!res.Item1)
            {
                ViewBag.Error = "Email Failed to send";
            }

            ViewBag.Success = "Email Sent Successfully";
            return(View(new VerifyEmail {
                ReturnUrl = model.ReturnUrl
            }));
        }