public async Task <IActionResult> ResetPassword(ResetPassViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

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

            if (user == null)
            {
                return(RedirectToAction("ResetPasswordConfirmation", "Signup"));
            }

            var result = await _userManager.ResetPasswordAsync(user, vm.Code, vm.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("ResetPasswordConfirmation", "Signup"));
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            return(View());
        }
Beispiel #2
0
        public async Task <IHttpActionResult> ResetPassword(ResetPassViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try {
                var profile = _uow.UserProfile.Get(model.UserId);
                if (profile == null)
                {
                    return(BadRequest("Thông tin bạn cung cấp không hợp lệ!"));
                }
                var user = await _repoUser.FindByNameAsync(profile.Email);

                var result = await _repoUser.ResetPasswordAsync(user.Id, model.Password);

                IHttpActionResult errorResult = GetErrorResult(result);
                if (errorResult != null)
                {
                    return(BadRequest(errorResult.ToString()));
                }
                _uow.Token.Delete(model.Code);
                return(Ok());
            }
            catch (BusinessException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(BadRequest(this.General_Err));
            }
        }
        public IActionResult ResetPassword(string userId, string code = null)
        {
            var vm = new ResetPassViewModel {
                Code = code
            };

            return(View(vm));
        }
Beispiel #4
0
        public void ResetPass(ResetPassViewModel password)
        {
            var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(_db));
            UserStore <ApplicationUser> store = new UserStore <ApplicationUser>();
            Guid            id   = Guid.Parse(password.ID);
            ApplicationUser user = _db.Users.FirstOrDefault(w => w.AplicationUser_Person.ID == id);

            store.SetPasswordHashAsync(user, userManager.PasswordHasher.HashPassword(password.Password));
        }
Beispiel #5
0
 public ActionResult ResetPass(ResetPassViewModel resetPass)
 {
     if (ModelState.IsValid)
     {
         _unitOfWork.Person_List.ResetPass(resetPass);
         Ok();
         return(RedirectToAction("Index", "Employee", null));
     }
     Forbidden();
     return(Content(GenerateError()));
 }
Beispiel #6
0
        public ActionResult CheckCode(CheckCodeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = db.AspNetUsers.FirstOrDefault(m => m.Id == model.id);
                if (user != null && user.LockoutEnabled && user.VerificationCode == model.Codigo)
                {
                    ResetPassViewModel resetModel = new ResetPassViewModel();
                    resetModel.id     = user.Id;
                    resetModel.Codigo = user.VerificationCode;
                    return(View(RESET_PASS, resetModel));
                }
            }

            return(View(VERYFY_CODE, model));
        }
Beispiel #7
0
        public async Task <IActionResult> Resetpass([FromBody] ResetPassViewModel model)
        {
            AppUsern user = await userManager.FindByIdAsync(model.Id);

            if (user == null)
            {
                return(new ObjectResult(new { result = "not found" }));
            }
            if (!ModelState.IsValid)
            {
                return(new ObjectResult(new { result = "all required" }));
            }
            if (model.Id != user.Id)
            {
                return(new ObjectResult(new { result = "not found" }));
            }
            #region
            //if (model.Email != user.Email)
            //{
            //    return new ObjectResult(new { result = "not found" });
            //}
            //var cd = "";
            //var code = cache.TryGetValue(model.Email, out cd);
            //if (model.Code != cd)
            //{
            //    return new ObjectResult(new { result = "Code" });
            //}
            #endregion

            var _passwordValidator =
                HttpContext.RequestServices.GetService(typeof(IPasswordValidator <AppUsern>)) as IPasswordValidator <AppUsern>;
            var _passwordHasher =
                HttpContext.RequestServices.GetService(typeof(IPasswordHasher <AppUsern>)) as IPasswordHasher <AppUsern>;

            IdentityResult result =
                await _passwordValidator.ValidateAsync(userManager, user, user.PasswordHash);

            if (result.Succeeded)
            {
                user.PasswordHash = _passwordHasher.HashPassword(user, model.NewPassword);
                await userManager.UpdateAsync(user);

                return(new OkObjectResult(new { result = "success" }));
            }
            return(BadRequest());
        }
Beispiel #8
0
        public ActionResult ResetPassword(ResetPassViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = db.AspNetUsers.FirstOrDefault(m => m.Id == model.id);

            if (user != null && user.LockoutEnabled && user.VerificationCode == model.Codigo)
            {
                user.PasswordHash     = HashPassword(model.Password);
                user.VerificationCode = null;
                db.SaveChanges();

                return(RedirectToAction("Login", "Account"));
            }

            return(View());
        }
Beispiel #9
0
        public ActionResult Resetpass(ResetPassViewModel reset)
        {
            // اول چک می کند آیا کاربری فعال شده که بخواهد پسوردش را تغییر دهد
            var user = db.UserLogin.FirstOrDefault(u => u.ActiveCode == reset.ActiveCode);

            if (user != null)
            {
                //پسورد جدید راجایگزین پسورد قدیم میکند
                user.Password   = FormsAuthentication.HashPasswordForStoringInConfigFile(reset.Password, "MD5");
                user.ActiveCode = Guid.NewGuid().ToString().Replace("-", "");
                db.SaveChanges();

                return(Redirect("/Account/Login?ResetPass=true"));
            }
            else
            {
                ModelState.AddModelError("Password", "اطلاعات ورودی صحیح نمی باشد");
            }
            return(View(reset));
        }
Beispiel #10
0
        public async Task <IActionResult> ResetPassword(ResetPassViewModel resetPassViewModel)
        {
            var user = await userManager.FindByEmailAsync(resetPassViewModel.Email);

            if (user != null)
            {
                var result = await userManager.ResetPasswordAsync(user, resetPassViewModel.Token, resetPassViewModel.Password);

                if (result.Succeeded)
                {
                    var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", result);
                    return(Ok(Response));
                }
                else
                {
                    var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null);
                    return(Ok(Response));
                }
            }
            return(null);
        }
Beispiel #11
0
        public async Task <ActionResult> RecoveryPassword(ResetPassViewModel model)
        {
            String userId      = Session["usuarioResetPassword"].ToString();
            String resetToken  = Session["tokenResetPassword"].ToString();
            String newPassword = model.NewPassword;

            ApplicationUser user = this.modelContext
                                   .Users
                                   .FirstOrDefault(x => x.Id == userId && x.resetPassToken == resetToken);

            if (user != null && resetToken.Length > 0)
            {
                ApplicationUser             cUser             = UserManager.FindById(userId);
                String                      hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword);
                UserStore <ApplicationUser> store             = new UserStore <ApplicationUser>();
                await store.SetPasswordHashAsync(user, hashedNewPassword);

                user.resetPassToken = UniqueKeyUtil.GetUniqueKey(16);
                this.modelContext.SaveChanges();
            }

            return(View("~/Views/Account/Login.cshtml"));
        }