public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                //if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                //{
                //    // Don't reveal that the user does not exist or is not confirmed
                //    return RedirectToAction(nameof(ForgotPasswordConfirmation));
                //}

                // For more information on how to enable account confirmation and password reset please
                // visit https://go.microsoft.com/fwlink/?LinkID=532713
                Guid guid = Guid.NewGuid();
                var  code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var callbackUrl = Url.ResetPasswordCallbackLink(user.Id, guid.ToString(), Request.Scheme);
                await _emailSender.SendEmailAsync(model.Email, "Reset Password",
                                                  $"Please reset your password by clicking here: <a href='{callbackUrl}'>link</a>");

                EmailPasswordTokeneDetails emailPasswordTokeneDetails = new EmailPasswordTokeneDetails()
                {
                    ResetDetail   = code,
                    PassworkToken = guid.ToString(),
                    CreatedOn     = System.DateTime.Now,
                    IsActive      = true
                };
                businessService.SaveEmailPasswordTokeneDetails(emailPasswordTokeneDetails);
                return(RedirectToAction(nameof(ForgotPasswordConfirmation)));
            }

            // If we got this far, something failed, redisplay form
            return(View("Login", model));
        }
Example #2
0
        public EmailPasswordTokeneDetails AddNew(EmailPasswordTokeneDetails entity)
        {
            var result = _context.EmailPasswordTokeneDetails.Add(entity);

            _context.SaveChanges();
            return(entity);
        }
Example #3
0
 public void SaveEmailPasswordTokeneDetails(EmailPasswordTokeneDetails model)
 {
     repository.AddNew(model);
 }