Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Reset password #1740


User avatar
0
girish28892 created

here is my forgot password code

[HttpPost]
        //[DisableAuditing]
        [UnitOfWork]
        public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel vm)
        {
            if (ModelState.IsValid)
            {
                _unitOfWorkManager.Begin();
                _unitOfWorkManager.Current.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, 1);

                var user = await _userManager.FindByEmailAsync(vm.Email);

                //CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, 1);
                if (user == null) // || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    ViewBag.IsValid = false;
                    return View("ForgotPasswordConfirmation");
                }
                var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("ASP.NET IDENTITY");
                _userManager.UserTokenProvider = new DataProtectorTokenProvider<User, long>(provider.Create("ASP.NET Identity")) as
               IUserTokenProvider
               <User, long>;



                var code = await _userManager.GeneratePasswordResetTokenAsync(user.Id);
              
                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                var body = "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>.";
                await _userManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
                bool emailStatus = Helpers.Utility.SendMail(vm.Email, "Estone - Reset Password", body);
                //ViewBag.Link = callbackUrl;
                ViewBag.IsValid = true;
                return View("ForgotPasswordConfirmation");
            }

            // If we got this far, something failed, redisplay form
            return View();
        }

and here is my reset password code

[HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        [DisableAuditing]
        [UnitOfWork]
        public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            _unitOfWorkManager.Begin();
            _unitOfWorkManager.Current.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, 1);
            var user = await _userManager.FindByEmailAsync(model.Email);
           
               
            if (user == null)
            {
                // Don't reveal that the user does not exist
                return RedirectToAction("ResetPasswordConfirmation", "Account");
            }
            var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("ASP.NET IDENTITY");
            //var provider = Startup.DataProtectionProvider;
            _userManager.UserTokenProvider = new DataProtectorTokenProvider<User, long>(provider.Create("ASP.NET Identity")) as IUserTokenProvider<User, long>;

            var result = await _userManager.ResetPasswordAsync(user.Id, model.code, model.confirmPassword);


           await _unitOfWorkManager.Current.SaveChangesAsync();
         
         // unitOfWork.Complete();
          _unitOfWorkManager.Current.Completed +=(sender,args) => {

              _unitOfWorkManager.Current.SaveChangesAsync();
          };


            if (result.Succeeded)
            {
                return RedirectToAction("ResetPasswordConfirmation", "Account");
            }
            
            
            ModelState.AddModelError("", "Something wrong");
            
            return View("ResetPasswordConfirmation");
        }

both are working without any errors but still no change in password...pls help


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Did you debug the ResetPassword action. Because if user is null or password reset operation is successfull, both goes to same page. Maybe user is null in your case, is that possible ?

  • User Avatar
    0
    girish28892 created

    <cite>ismcagdas: </cite> Hi,

    Did you debug the ResetPassword action. Because if user is null or password reset operation is successfull, both goes to same page. Maybe user is null in your case, is that possible ?

    hello, user is not null i am getting the correct user and the password is resetting(in my code) also, but the problem is it is not getting saved in my database