Base solution for your next web application

Activities of "girish28892"

<cite>ismcagdas: </cite> Hi,

Where did you use this code ? I think it's in a non unitOfWork method and because of that CurrentUnitOfWork is null in your case.

fixed...thanks alot

Answer

<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

Question

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

@hikalkan i hav put filter its giving me error "Object reference not set to an instance of an object."

Showing 1 to 4 of 4 entries