public virtual ActionResult ChangePassword(ChangePasswordModel model) { var id = WebHelper.GetIdentityId(User.Identity); if (id == 0) return View(MVC.Shared.Views.Error); if (ModelState.IsValid) { var context = ModelFactory.GetUnitOfWork(); var mRepo = ModelFactory.GetRepository<IMemberRepository>(context); var member = mRepo.Get(id); if (_MembershipService.ChangePassword(member.Username, model.OldPassword, model.NewPassword)) { TempData[MiscHelpers.TempDataConstants.Info] = Worki.Resources.Views.Account.AccountString.YouChangeYourPassword; return RedirectToAction(MVC.Dashboard.Home.Index()); } else { ModelState.AddModelError("", Worki.Resources.Validation.ValidationString.PasswordNotValide); } } // Si nous sommes arrivés là, quelque chose a échoué, réafficher le formulaire ViewData["PasswordLength"] = _MembershipService.MinPasswordLength; return View(model); }
public virtual ActionResult EditPassword(ChangePasswordModel model) { if (ModelState.IsValid) { try { var context = ModelFactory.GetUnitOfWork(); var mRepo = ModelFactory.GetRepository<IMemberRepository>(context); var member = mRepo.GetMemberFromToken(model.Token); if (_MembershipService.ChangePassword(member.Username, model.OldPassword, model.NewPassword)) { var newContext = ModelFactory.GetUnitOfWork(); mRepo = ModelFactory.GetRepository<IMemberRepository>(newContext); member = mRepo.GetMemberFromToken(model.Token); return new ObjectResult<AuthJson>(member.GetAuthData()); } else { throw new Exception(Worki.Resources.Validation.ValidationString.PasswordNotValide); } } catch (Exception ex) { return new ObjectResult<AuthJson>(null, 400, ex.Message); } } else { return new ObjectResult<AuthJson>(null, 400, ModelState.GetErrors()); } }