public IDataShell <AccountDBModel> UpdateModifyPassword(AccountDBModel user) { var res = _userDAL.UpdateModifyPassword(user); return(res); }
/// <summary> /// 更新密码 /// </summary> /// <param name="req"></param> /// <returns></returns> public IDataShell <AccountModel> ModifyPassword(ModifyPasswordReq req) { #region --早期验证-- // 这是一个数据验证扩展的样例 Dictionary <string, Func <bool> > check = new Dictionary <string, Func <bool> >() { ["旧密码为空"] = () => req.OldPassword.NullEmpty(), ["新密码两次输入不一致"] = () => req.NewPassword != req.NewPassword2, }; foreach (var c in check.CheckerYield()) { if (c.haveerror) { return(c.info.Fail <AccountModel>()); } } #endregion #region --提取用户信息-- AccountModel user = new AccountModel() { Account = req.Account, Email = req.Email, Mobile = req.Mobile, AccountID = req.AccountID }; IDataShell <AccountDBModel> tempuser = new DataShell <AccountDBModel>(); switch (user) { case AccountModel u when user.Account.NotNullEmpty(): tempuser = _userDAL.GetByAccount(user); break; case AccountModel u when user.Email.NotNullEmpty(): tempuser = _userDAL.GetByEmail(user); break; case AccountModel u when user.Mobile.NotNullEmpty(): tempuser = _userDAL.GetByMobile(user); break; case AccountModel u when user.AccountID.NotNullEmpty(): tempuser = _userDAL.GetByAccountID(user); break; default: throw new Exception("没有找到匹配的用户"); } tempuser = _userDAL.GetByEmail(user); if (tempuser.Failure) { return(tempuser.ToNewShell <AccountDBModel, AccountModel>()); } #endregion #region --密码核验-- var srcuser = tempuser.Data; var verifyRes = PasswordVerify(srcuser.Password, req.OldPassword); if (verifyRes.Failure) { return(verifyRes.Info.Fail <AccountModel>()); } #endregion #region --更新密码-- user.Password = CommonLib.AccountPassword(req.NewPassword); //散列加密 var up_res = _userDAL.UpdateModifyPassword(user); //更新密码 up_res.Data.Password = ""; //移除敏感数据 var res = up_res.ToNewShell <AccountDBModel, AccountModel>(); #endregion return(res); }