Пример #1
0
 public ActionResult ChangePassword(ChangeAccount changeAccount)
 {
     var userId = new Guid(User.Identity.Name);
     changeAccount.ID = userId;
     var accountServices = ServiceLocator.Instance.GetService<IAccountServices>();
     accountServices.ChangePassword(changeAccount);
     var result = accountServices.GetResult();
     return Json(result);
 }
Пример #2
0
        public void ChangePassword(ChangeAccount changeAccount)
        {

            using (var accountContext = new DefaultContext())
            {
                var account = accountContext.Accounts.FirstOrDefault(x => x.ID == changeAccount.ID);
                if (account == null)
                {
                    Message = "输入账号不存在";
                    return;
                }
                if (!account.State)
                {
                    Message = "账号已禁用";
                    return;
                }
                if (account.Password != changeAccount.OldPassword.MD5().ToLower())
                {
                    Message = "旧密码错误,请重新输入!";
                    return;
                }
                if (string.IsNullOrEmpty(changeAccount.NewPassword))
                {
                    Message = "新密码不能为空,请重新输入!";
                    return;
                }
                account.SetPassword(changeAccount.NewPassword);
                accountContext.ModifiedModel(account);
                accountContext.SaveChanges();
                Flag = true;
            }
        }