Esempio n. 1
0
        public void Update(SetPasswordModel command)
        {
            SetPassword(command.NewPassword);

            this.RegisterCommand(command);
        }
        public ActionResult SetPassword(SetPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                var admin = GetAdmin();
                if (admin == null  || User.Identity.Name != Administrator || !admin.ValidatePassword(model.YourPassword))
                {
                    return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
                }

                var user = GetUser(model.UserName, model.CommandCompanyId);

                if (user != null)
                {
                    user.Update(model);
                    RavenSession.SaveChanges();
                    return RedirectToAction("ChangePasswordSuccess");
                }

                ModelState.AddModelError("", "The user name is incorrect or the new password is invalid.");
            }

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