示例#1
0
        public async Task <IActionResult> OnPost(ForgotPasswordVm forgotPasswordVm)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.FindByEmailAsync(forgotPasswordVm.Email);

                if (user != null)
                {
                    var token = await userManager.GeneratePasswordResetTokenAsync(user);

                    //var token = await userManager.generate(user);
                    //var resetUrl = Url.Action("ResetPassword", "Home",
                    //    new { token = token, email = user.Email }, Request.Scheme);
                    //string url = "http://localhost:44373/Account/ResetPassword?token=" + token + "&email=" + user.Email;
                    //return RedirectToPage(url);
                    //var resetUrl = Url.Page("./ResetPassword", new { token = token, email = user.Email });
                    var resetUrl = Url.Page("./ResetPassword");
                    TempData["token"] = token;
                    TempData["email"] = user.Email;

                    return(Redirect(resetUrl));
                    //return RedirectToPage("./ResetPassword", new { token = token, email = user.Email });
                    //System.IO.File.WriteAllText("resetLink.txt", resetUrl);
                }
                else
                {
                    // email user and inform them that they do not have an account
                }

                //return RedirectToPage("./ResetPassword");
            }
            //return View();

            return(Page());
        }
 public async Task <dynamic> ForgotPassword(ForgotPasswordVm model)
 {
     if (ModelState.IsValid)
     {
         var resetToken = _userService.GeneratePasswordResetToken(model.UserName);
         if (!string.IsNullOrEmpty(resetToken))
         {
             var resetUrl     = $"{Request.Localhost()}/api/v1/account/passwordreset/{HttpUtility.UrlEncode(resetToken)}";
             var emailFactory = await new EmailFactory().EmailForgotPassword(model.Email, resetToken, resetUrl);
             await new MessengerService().SendAsync(emailFactory.FromAddress, emailFactory.ToAddress, emailFactory.Subject, emailFactory.Body, emailFactory.IsBodyHtml);
         }
         return(Ok("Um e-mail com instruções sobre como redefinir sua senha está a caminho de você."));
     }
     return(BadRequest(EntityState.GetErrors(ModelState)));
 }
示例#3
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordVm model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = await _userAccountManager.GetUser(model.Email);

                    if (user != null)
                    {
                        await _userAccountManager.SavePasswordResetRequest(user);

                        return(RedirectToAction(nameof(AccountController.ForgotPassword)));  //"ForgotPasswordEmailSent"
                    }
                    ModelState.AddModelError(string.Empty, "No user account found for this email.");
                }
            }
            catch (Exception ex)
            {
                tc.TrackException(ex);
                ModelState.AddModelError(string.Empty, "Error processing your request!");
            }
            return(View(model));
        }
示例#4
0
        /// <summary>
        /// Creates and send email message to a user to reset a password
        /// </summary>
        /// <param name="model">User's data (email)</param>
        /// <returns>Task to enable asynchronous execution</returns>
        public async Task ForgotPassword(ForgotPasswordVm model)
        {
            var user = await UserManager.FindByEmailAsync(model.Email);
            if(user == null)
            {
                throw new TbIdentityException("Find user error");
            }

            // Create a password reset token and email body
            var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
            //code = WebUtility.UrlEncode(code);
            string link = string.Format("{0}/#/resetPassword/{1}/{2}", Host, user.UserName, code);
            string body = string.Format(_resetPswEmailBodyConst, user.FirstName, link);

            // Create the email message to reset a password and send it
            MailMessage message = new MailMessage();
            message.To.Add(user.Email);
            message.Subject = "Reset password";
            message.Body = body;

            await _emailService.SendMailAsync(message);
        }
示例#5
0
 public async Task <IActionResult> OnGet()
 {
     ForgotPasswordVm = new ForgotPasswordVm();
     return(Page());
 }