Beispiel #1
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ResultEx UpdatePassword(int userId, AccountModel.ModifyPwd model)
 {
     using (var dbScope = _dbScopeFactory.Create())
     {
         try
         {
             var db           = dbScope.DbContexts.Get <WebDbContext>();
             var accountModel = db.SysAccounts.Where(x => x.Id == userId).SingleOrDefault();
             if (accountModel == null)
             {
                 return(ResultEx.Init(false, "未能找到用户信息!"));
             }
             if (accountModel.Password != new MD5Encrtpy().encode(model.OldPwd))
             {
                 return(ResultEx.Init(false, "原始密码错误!"));
             }
             db.SysAccounts.Where(x => x.Id == userId).Update(x => new SysAccount {
                 Password = new MD5Encrtpy().encode(model.NewPwd)
             });
             db.SaveChanges();
             return(ResultEx.Init());
         }
         catch (System.Exception ex)
         {
             return(ResultEx.Init(ex));
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ResultEx UpdatePassword(AccountModel.ModifyPwd model)
 {
     using (var dbScope = _dbScopeFactory.Create())
     {
         try
         {
             var db           = dbScope.DbContexts.Get <WebDbContext>();
             var accountModel = this.GetModel(CurrentUser.User.UserName);
             if (accountModel == null)
             {
                 return(ResultEx.Init(false, "未能找到用户信息!"));
             }
             if (accountModel.Password != new MD5Encrtpy().encode(model.OldPwd))
             {
                 return(ResultEx.Init(false, "原始密码错误!"));
             }
             accountModel.Password        = new MD5Encrtpy().encode(model.NewPwd);
             db.Entry(accountModel).State = EntityState.Modified;
             db.SaveChanges();
             return(ResultEx.Init());
         }
         catch (System.Exception ex)
         {
             return(ResultEx.Init(ex));
         }
     }
 }
Beispiel #3
0
        public void UpdatePasswordOldPwdNotRight()
        {
            var model = new AccountModel.ModifyPwd {
                ConfirmPwd = "123456", NewPwd = "123456", OldPwd = "888888", UserID = 1
            };
            var accountService = new Mock <IAccountSvc>();

            accountService
            .Setup(c => c.UpdatePassword(model))
            .Returns(ResultEx.Init());
            // Target object
            var presenter = new AccountPresenter(accountService.Object);
            // Act
            var result = presenter.UpdatePassword(model);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.flag);
            Assert.Empty(result.msg);
        }
Beispiel #4
0
 public ResultEx UpdatePassword(AccountModel.ModifyPwd model)
 {
     return(AccountSvc.UpdatePassword(model));
 }