public static bool HasLogin() { UserAuthVM user = ReadUserInfo(); if (user == null || user.UserSysNo == 0 || string.IsNullOrWhiteSpace(user.UserID)) { return(false); } return(true); }
/// <summary> /// 获取当前用户信息 /// </summary> /// <returns></returns> public static UserAuthVM GetCurrentUser() { UserAuthVM user = ReadUserInfo(); if (user == null || user.UserSysNo == 0 || string.IsNullOrWhiteSpace(user.UserID)) { user = null; } return(user); }
/// <summary> /// 当前用户是否有权限 /// </summary> /// <param name="controller">Controller名</param> /// <param name="action">Action名</param> /// <returns></returns> public static bool HasAuth(string controller, string action) { UserAuthVM user = GetCurrentUser(); if (user == null) { return(false); } string authKey = controller.Trim() + "|" + action.Trim(); return(HasAuth(authKey)); }
/// <summary> /// 维护数据时为公共参数赋值 /// </summary> /// <param name="bizEntity">继承EntityBase</param> /// <param name="isCreate">创建或更新</param> public static void SetBizEntityUserInfo(EntityBase bizEntity, bool isCreate) { UserAuthVM user = GetCurrentUser(); bizEntity.CompanyCode = user.CompanyCode; bizEntity.SellerSysNo = user.SellerSysNo; bizEntity.LanguageCode = user.LanguageCode; if (isCreate) { bizEntity.InUserSysNo = user.UserSysNo; bizEntity.InUserName = user.UserDisplayName; bizEntity.InDate = DateTime.Now; } else { bizEntity.EditUserSysNo = user.UserSysNo; bizEntity.EditUserName = user.UserDisplayName; bizEntity.EditDate = DateTime.Now; } }
/// <summary> /// 当前用户是否有权限 /// </summary> /// <param name="controller">Authkey</param> /// <returns></returns> public static bool HasAuth(string authKey) { UserAuthVM user = GetCurrentUser(); List <PrivilegeInfo> allList = GetAllAuthKeyList(); if (!allList.Exists(f => f.PrivilegeName.Trim().ToLower() == authKey.Trim().ToLower())) { //不需要做控制的 return(true); } //验证页面是否有权限: if (user == null || user.UserSysNo == 0 || string.IsNullOrWhiteSpace(user.UserID) || user.UserAuthKeyList == null) { return(false); } if (string.IsNullOrEmpty(authKey) || user.UserAuthKeyList.FindIndex(f => f.Trim().ToUpper() == authKey.Trim().ToUpper()) >= 0) { return(true); } return(false); }
/// <summary> /// 写用户登录信息 /// </summary> /// <param name="userSysNo">用户编号</param> /// <param name="userID">用户名</param> /// <param name="userDisplayName">用户显示名</param> public static void WriteUserInfo(UserInfo user) { if (user == null || user.SysNo == 0 || string.IsNullOrWhiteSpace(user.UserID)) { Logout(); return; } var userAuth = new UserAuthVM(); userAuth.UserSysNo = user.SysNo.Value; userAuth.UserID = user.UserID; userAuth.UserDisplayName = user.UserName; userAuth.SellerSysNo = user.VendorSysNo.Value; userAuth.SellerName = user.VendorName; userAuth.CompanyCode = user.CompanyCode; userAuth.LanguageCode = user.LanguageCode; userAuth.VendorStockType = user.VendorStockType; //userAuth.UserAuthKeyList = user.UserAuthKeyList; userAuth.UserAuthKeyList = new List <string>(); var currnentUserInfo = UserService.GetUserInfo(user.SysNo.Value, user.VendorSysNo.Value); if (null != currnentUserInfo && currnentUserInfo.Roles.Count > 0) { foreach (var userRole in currnentUserInfo.Roles) { var privilegeList = UserService.GetPrivilegeListByRoleSysNo(userRole.RoleSysNo.Value); if (null != privilegeList && privilegeList.Count > 0) { userAuth.UserAuthKeyList.AddRange(privilegeList.Select(x => x.PrivilegeName).ToList()); } } userAuth.UserAuthKeyList = userAuth.UserAuthKeyList.Distinct().ToList(); } CookieHelper.SaveCookie <UserAuthVM>(LOGIN_COOKIE, userAuth); }