using WIDESEAWCS_Core.Authorization; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseServices; using WIDESEAWCS_Core.Const; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_Core.HttpContextUser; using WIDESEAWCS_ISystemServices; using WIDESEAWCS_Model; using WIDESEAWCS_Model.Models; using WIDESEAWCS_ISystemRepository; using WIDESEAWCS_Core.BaseRepository; using System.Net; using WIDESEAWCS_Core.Caches; namespace WIDESEAWCS_SystemServices { public class Sys_UserService : ServiceBase<Sys_User, ISys_UserRepository>, ISys_UserService { private readonly IUnitOfWorkManage _unitOfWorkManage; private readonly ICacheService _cacheService; private readonly ISys_MenuService _menuService; public Sys_UserService(ISys_UserRepository repository, IUnitOfWorkManage unitOfWorkManage, ICacheService cacheService, ISys_MenuService menuService) : base(repository) { _unitOfWorkManage = unitOfWorkManage; _cacheService = cacheService; _menuService = menuService; } public WebResponseContent Login(LoginInfo loginInfo) { WebResponseContent content = new WebResponseContent(); try { //BaseDal.QueryFirst(x => x.UserName == loginInfo.UserName); string msg = string.Empty; #region 临时使用 try { loginInfo.Password = loginInfo.Password.EncryptDES(AppSecret.User); } catch { } #endregion UserInfo user = BaseDal.GetUserInfo(loginInfo.UserName, loginInfo.Password); if (user != null) { object obj = _menuService.GetMenuActionList(user.RoleId); if (obj is not IEnumerable<object> list) { return WebResponseContent.Instance.Error("æ— ç™»å½•æƒé™"); } if (!list.Any()) { return WebResponseContent.Instance.Error("æ— ç™»å½•æƒé™"); } string token = JwtHelper.IssueJwt(new TokenModelJwt() { UserId = user.UserId, RoleId = user.RoleId, UserName = user.UserName, TenantId = user.TenantId, }); _cacheService.AddOrUpdate(user.UserId.ToString(), token); content = WebResponseContent.Instance.OK(data: new { token, userName = user.UserTrueName, img = user.HeadImageUrl }); } else { content = WebResponseContent.Instance.Error("è´¦å·æˆ–密ç 错误"); } } catch (Exception ex) { content = WebResponseContent.Instance.Error(ex.Message); } return content; } public override WebResponseContent UpdateData(SaveModel saveModel) { UpdateIgnoreColOnExecute = x => { return new List<string> { nameof(Sys_User.UserPwd), nameof(Sys_User.TenantId) }; }; return base.UpdateData(saveModel); } public override WebResponseContent AddData(SaveModel saveModel) { string pwd = "123456"; string uesrName = saveModel.MainData[nameof(Sys_User.UserName).FirstLetterToLower()].ToString(); saveModel.MainData[nameof(Sys_User.UserPwd).FirstLetterToLower()] = pwd.EncryptDES(AppSecret.User); WebResponseContent content = base.AddData(saveModel); if (content.Status) { return WebResponseContent.Instance.OK($"用户新建æˆåŠŸ.å¸å·{uesrName}密ç {pwd}"); } else { return content; } } /// <summary> /// 个人ä¸å¿ƒèŽ·å–当å‰ç”¨æˆ·ä¿¡æ¯ /// </summary> /// <returns></returns> public WebResponseContent GetCurrentUserInfo() { var data = BaseDal.QueryFirst(x => x.User_Id == App.User.UserId, s => new { s.UserName, s.UserTrueName, s.Address, s.PhoneNo, s.Email, s.Remark, s.Gender, s.RoleName, s.HeadImageUrl, s.CreateDate }); return WebResponseContent.Instance.OK(null, data); } /// <summary> /// 修改密ç /// </summary> /// <param name="parameters"></param> /// <returns></returns> public WebResponseContent ModifyPwd(string oldPwd, string newPwd) { WebResponseContent content = WebResponseContent.Instance; oldPwd = oldPwd?.Trim(); newPwd = newPwd?.Trim(); string message = ""; try { if (string.IsNullOrEmpty(oldPwd)) return WebResponseContent.Instance.Error("旧密ç ä¸èƒ½ä¸ºç©º"); if (string.IsNullOrEmpty(newPwd)) return WebResponseContent.Instance.Error("新密ç ä¸èƒ½ä¸ºç©º"); if (newPwd.Length < 6) return WebResponseContent.Instance.Error("密ç ä¸èƒ½å°‘于6ä½"); int userId = App.User.UserId; string userCurrentPwd = BaseDal.QueryFirst(x => x.User_Id == userId, s => s.UserPwd); string _oldPwd = oldPwd.EncryptDES(AppSecret.User); if (_oldPwd != userCurrentPwd) return WebResponseContent.Instance.Error("旧密ç 䏿£ç¡®"); string _newPwd = newPwd.EncryptDES(AppSecret.User); if (userCurrentPwd == _newPwd) return WebResponseContent.Instance.Error("新密ç ä¸èƒ½ä¸Žæ—§å¯†ç 相åŒ"); BaseDal.UpdateData(new Sys_User { User_Id = userId, UserPwd = _newPwd, LastModifyPwdDate = DateTime.Now }, new List<string> { nameof(Sys_User.LastModifyPwdDate), nameof(Sys_User.UserPwd) }); content = WebResponseContent.Instance.OK("密ç 修改æˆåŠŸ"); } catch (Exception ex) { message = ex.Message; content = WebResponseContent.Instance.Error("æœåŠ¡å™¨äº†ç‚¹é—®é¢˜,请ç¨åŽå†è¯•"); } return content; } } }