Ejemplo n.º 1
0
        public GenericResponseModel <AuthResponseModel> AuthenticateUser(AuthRequestModel login)
        {
            var response = new GenericResponseModel <AuthResponseModel>();

            try
            {
                var da          = new AuthDA();
                var resultLogin = da.Login(login);
                if (!resultLogin)
                {
                    response.ErrorMessage = "User didn't Exists !";
                    return(response);
                }

                var msg = string.Empty;
                response.Value  = da.GetDataUser(login.UserName, ref msg);
                response.Status = true;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = ex.ToString();
            }

            return(response);
        }
Ejemplo n.º 2
0
        public static List <AuthEntity> GetAllAuth()
        {
            var allAuth = MemoryCacheUtils.Get("GetAllAuth") as List <AuthEntity>;

            if (allAuth == null)
            {
                allAuth = AuthDA.GetAllAuth();
                MemoryCacheUtils.Set("GetAllAuth", allAuth);
            }
            return(allAuth);
        }
        public AuthUserDataModel GetUserMenuList(int userSysNo, string applicationKey, string userID, string loginTime, string topMenuKey = null)
        {
            string keyWithoutLoginTime = CacheManager.GenerateKey(Key_Service_User_Auth_Data, applicationKey, userID);
            string keyWithLoginTime    = CacheManager.GenerateKey(keyWithoutLoginTime, loginTime);

            return(CacheManager.GetWithCache(keyWithLoginTime, () => {
                //移除失效的缓存
                CacheManager.RemoveStartsWith(keyWithoutLoginTime + "_");
                AuthUserDataModel result = AuthDA.GetUserMenuList(userSysNo, applicationKey, topMenuKey);
                return result;
            }, 60 * 60 * 8));
        }
        public int ResetSystemUserPassword(string loginName, string oldPassword, string newPassword, string applicationKey)
        {
            var result = AuthDA.Login(loginName, oldPassword, applicationKey);

            if (result == null)
            {
                throw new BusinessException("原密码错误!");
            }

            int    EditUserSysNo = DataContext.GetContextItemInt("UserSysNo", 0);
            string EditUserName  = DataContext.GetContextItemString("UserDisplayName");

            return(SystemUserDA.ResetSystemUserPassword(loginName, newPassword, applicationKey, EditUserSysNo, EditUserName));
        }
        public AuthUserModel Login(string userID, string pwd, string applicationKey)
        {
            var result = AuthDA.Login(userID, pwd, applicationKey);

            if (result == null)
            {
                throw new BusinessException("账号或密码错误!", 10);
            }
            if (result.CommonStatus != 1)
            {
                throw new BusinessException("您的账户已被禁用,请联系您的管理员。");
            }
            //生成登录时间
            result.LoginTime = DateTimeHelper.GetTimeZoneNow();
            return(result);
        }
        public List <AuthPermissionModel> LoadAllPermissions(string applicationKey)
        {
            var p_list = AuthDA.LoadAllPermissions(applicationKey);
            List <AuthPermissionModel> result = new List <Utility.Web.Auth.Models.AuthPermissionModel>();

            for (int i = 0; i < p_list.Count; i++)
            {
                result.Add(new AuthPermissionModel
                {
                    PermissionKey  = p_list[i].PermissionKey,
                    PermissionName = p_list[i].PermissionName,
                    MenuSysNo      = p_list[i].MenuSysNo,
                    MenuSysCode    = p_list[i].MenuSysCode
                });
            }
            return(result);
        }
        public int UpdateSystemUser(SystemUser entity, string ApplicationID)
        {
            //if (entity.SysNo == 1)
            //{
            //    throw new BusinessException("超级用户不能修改");
            //}
            CheckSystemUser(entity, false);
            int    EditUserSysNo = DataContext.GetContextItemInt("UserSysNo", 0);
            string EditUserName  = DataContext.GetContextItemString("UserDisplayName");

            entity.EditUserSysNo = EditUserSysNo;
            entity.EditUserName  = EditUserName;
            // lock ("check_app")
            //{
            var hasApp     = AuthDA.GetSystemApplicationsByUserSysNo(new int[] { entity.SysNo });
            var roleHasApp = AuthDA.GetSystemApplicationsByUserRole(entity.SysNo);

            var needInsert = entity.Applications.Except(hasApp, new SystemApplicationComparer());
            var needDelete = hasApp.Except(entity.Applications, new SystemApplicationComparer());

            StringBuilder sb = new StringBuilder();

            foreach (var item in needDelete)
            {
                if (roleHasApp.FirstOrDefault(x => x.ApplicationID == item.ApplicationID) != null)
                {
                    sb.AppendLine(string.Format("用户还拥有系统{0}中的角色,不能移除所属的系统{0}", item.Name));
                }
            }
            if (sb.ToString().Length > 0)
            {
                throw new BusinessException(sb.ToString());
            }
            foreach (var item in needInsert)
            {
                SystemUserDA.InsertSystemUser_Application(entity.SysNo, item.ApplicationID);
            }
            foreach (var item in needDelete)
            {
                SystemUserDA.DeleteSystemUser_Application(entity.SysNo, item.ApplicationID);
            }
            // }
            return(SystemUserDA.UpdateSystemUser(entity, ApplicationID));
        }
        public int UpdateSystemUser(SystemUser entity)
        {
            //if (entity.SysNo == 1)
            //{
            //    throw new BusinessException("超级用户不能修改");
            //}
            CheckSystemUser(entity, false);

            if (entity.Applications == null)
            {
                entity.Applications = new List <SystemApplication>();
            }
            var hasApp     = AuthDA.GetSystemApplicationsByUserSysNo(new int[] { entity.SysNo });
            var roleHasApp = AuthDA.GetSystemApplicationsByUserRole(entity.SysNo);

            var needInsert = entity.Applications.Except(hasApp, new SystemApplicationComparer());
            var needDelete = hasApp.Except(entity.Applications, new SystemApplicationComparer());

            StringBuilder sb = new StringBuilder();

            foreach (var item in needDelete)
            {
                if (roleHasApp.FirstOrDefault(x => x.ApplicationID == item.ApplicationID) != null)
                {
                    sb.AppendLine(string.Format("用户还拥有系统{0}中的角色,不能移除所属的系统{0}", item.Name));
                }
            }
            if (sb.ToString().Length > 0)
            {
                throw new BusinessException(sb.ToString());
            }

            foreach (var item in needInsert)
            {
                SystemUserDA.InsertSystemUser_Application(entity.SysNo, item.ApplicationID);
            }
            foreach (var item in needDelete)
            {
                SystemUserDA.DeleteSystemUser_Application(entity.SysNo, item.ApplicationID);
            }
            return(SystemUserDA.UpdateSystemUser(entity));
        }
Ejemplo n.º 9
0
        public List <MenuEntity> GetAllMenus()
        {
            var da = new AuthDA();

            return(da.GetAllMenus());
        }
Ejemplo n.º 10
0
        public MenuEntity GetMenuByMenuId(string id)
        {
            var da = new AuthDA();

            return(da.GetMenuByMenuId(id));
        }
Ejemplo n.º 11
0
        public IList <MenuEntity> GetMenusByLoginName(string loginName)
        {
            var da = new AuthDA();

            return(da.GetMenusByLoginName(loginName));
        }
Ejemplo n.º 12
0
 public List <AuthFunctionModel> LoadFunctionsByUserSysNo(int userSysNo, string applicationKey, string TopName = null)
 {
     return(AuthDA.LoadFunctionsByUserSysNo(userSysNo, applicationKey, TopName));
 }
 /// <summary>
 /// 获取全部Application
 /// </summary>
 /// <returns></returns>
 public List <SystemApplication> GetAllApplication()
 {
     return(AuthDA.GetAllApplication());
 }
 public static List <SystemApplication> GetSystemApplicationsByUserSysNo(IEnumerable <int> sysNos)
 {
     return(AuthDA.GetSystemApplicationsByUserSysNo(sysNos));
 }
 public static List <SystemApplication> LoadAllSystemApplication()
 {
     return(AuthDA.LoadAllSystemApplication());
 }
Ejemplo n.º 16
0
        public ActionResult BindingAdminID(string ID, string password)
        {
            if (string.IsNullOrWhiteSpace(ID) || string.IsNullOrWhiteSpace(password))
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "请输入账号和密码!"
                }));
            }
            string pd = SecurityHelper.GetMD5Value(password);

            #region 【验证账号有效性】
            SystemUser result = AuthDA.LoadSystemUserByIDAndPassword(ID, pd, ConstValue.ApplicationID);
            if (result == null)
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "账号或密码错误!"
                }));
            }
            if (result.CommonStatus != CommonStatus.Actived)
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "账号已被禁用,请联系您的管理员。"
                }));
            }
            if (result.MasterSysNo == null || result.MasterSysNo <= 0)
            {
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "不存在此账号。"
                }));
            }
            #endregion

            Client user = ClientService.LoadClient(curentUser.UserSysNo);
            if (user == null)
            {
                UserMgr.Logout();
                return(Json(new AjaxResult()
                {
                    Success = false, Message = "登录超时,请退出公众号重新进行。"
                }));
            }

            #region 【绑定后台账号到client】
            user.ManagerSysNo = result.SysNo;
            ClientService.UpdateClient(user);
            #endregion

            #region 【更新cookie】

            Company company = CompanyService.GetCompanyUser(result.SysNo);
            if (company != null && company.SysNo > 0)
            {
                curentUser.UserType = UserType.Installer;
            }
            else
            {
                curentUser.UserType = UserType.Manager;
            }
            AppUserInfo loginUser = curentUser;
            loginUser.ManagerSysNo     = result.SysNo;
            loginUser.ManagerLoginName = result.LoginName;
            loginUser.ManagerName      = HttpUtility.UrlEncode(result.UserFullName);
            UserMgr.Logout();
            UserMgr.WriteUserInfo(loginUser);

            #endregion

            return(Json(new AjaxResult()
            {
                Success = true, Message = "绑定成功!"
            }));
        }