Пример #1
0
        public async Task <List <RoleExtend> > GetLookList(SoulPage <RoleExtend> pagination, string keyword = "")
        {
            //反格式化显示只能用"等于",其他不支持
            Dictionary <string, Dictionary <string, string> > dic = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, string> enabledTemp = new Dictionary <string, string>();

            enabledTemp.Add("有效", "1");
            enabledTemp.Add("无效", "0");
            dic.Add("F_EnabledMark", enabledTemp);
            var setList = await setApp.GetList();

            Dictionary <string, string> orgizeTemp = new Dictionary <string, string>();

            foreach (var item in setList)
            {
                orgizeTemp.Add(item.F_CompanyName, item.F_Id);
            }
            dic.Add("F_OrganizeId", orgizeTemp);
            pagination = ChangeSoulData(dic, pagination);
            var query = GetQuery();
            //获取数据权限
            var list = GetDataPrivilege("u", "", query);

            if (!string.IsNullOrEmpty(keyword))
            {
                list = list.Where(u => u.F_FullName.Contains(keyword) || u.F_EnCode.Contains(keyword));
            }
            list = list.Where(u => u.F_DeleteMark == false && u.F_Category == 2);
            return(GetFieldsFilterData(await repository.OrderList(list, pagination)));
        }
Пример #2
0
        /// <summary>
        /// 登录判断
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <UserEntity> CheckLogin(string username, string password, string localurl)
        {
            //根据登录公司查找公司
            if (!string.IsNullOrEmpty(localurl))
            {
                var setTemp = (await syssetApp.GetList()).Where(a => localurl.Contains(a.F_HostUrl)).FirstOrDefault();
                if (setTemp != null)
                {
                    repository = new RepositoryBase <UserEntity>(setTemp.F_DbString, setTemp.F_DBProvider);
                    uniwork    = new RepositoryBase(setTemp.F_DbString, setTemp.F_DBProvider);
                }
            }
            UserEntity userEntity = await repository.FindEntity(t => t.F_Account == username);

            if (userEntity != null)
            {
                if (userEntity.F_EnabledMark == true)
                {
                    //缓存用户账户信息
                    var userLogOnEntity = await CacheHelper.Get <OperatorUserInfo>(cacheKeyOperator + "info_" + userEntity.F_Id);

                    if (userLogOnEntity == null)
                    {
                        userLogOnEntity = new OperatorUserInfo();
                        UserLogOnEntity entity = await uniwork.FindEntity <UserLogOnEntity>(userEntity.F_Id);

                        userLogOnEntity.F_UserPassword       = entity.F_UserPassword;
                        userLogOnEntity.F_UserSecretkey      = entity.F_UserSecretkey;
                        userLogOnEntity.F_AllowEndTime       = entity.F_AllowEndTime;
                        userLogOnEntity.F_AllowStartTime     = entity.F_AllowStartTime;
                        userLogOnEntity.F_AnswerQuestion     = entity.F_AnswerQuestion;
                        userLogOnEntity.F_ChangePasswordDate = entity.F_ChangePasswordDate;
                        userLogOnEntity.F_FirstVisitTime     = entity.F_FirstVisitTime;
                        userLogOnEntity.F_LastVisitTime      = entity.F_LastVisitTime;
                        userLogOnEntity.F_LockEndDate        = entity.F_LockEndDate;
                        userLogOnEntity.F_LockStartDate      = entity.F_LockStartDate;
                        userLogOnEntity.F_LogOnCount         = entity.F_LogOnCount;
                        userLogOnEntity.F_PreviousVisitTime  = entity.F_PreviousVisitTime;
                        userLogOnEntity.F_Question           = entity.F_Question;
                        userLogOnEntity.F_Theme = entity.F_Theme;
                        await CacheHelper.Set(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity);
                    }
                    if (userLogOnEntity == null)
                    {
                        throw new Exception("账户未初始化设置密码,请联系管理员");
                    }
                    string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower();
                    if (dbPassword == userLogOnEntity.F_UserPassword)
                    {
                        if (userEntity.F_Account != "admin")
                        {
                            var list     = userEntity.F_RoleId.Split(',');
                            var rolelist = uniwork.IQueryable <RoleEntity>(a => list.Contains(a.F_Id) && a.F_EnabledMark == true).ToList();
                            if (rolelist.Count() == 0)
                            {
                                throw new Exception("账户未设置权限,请联系管理员");
                            }
                        }
                        DateTime lastVisitTime = DateTime.Now;
                        int      LogOnCount    = (userLogOnEntity.F_LogOnCount).ToInt() + 1;
                        if (userLogOnEntity.F_LastVisitTime != null)
                        {
                            userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate();
                        }
                        userLogOnEntity.F_LastVisitTime = lastVisitTime;
                        userLogOnEntity.F_LogOnCount    = LogOnCount;
                        userLogOnEntity.F_UserOnLine    = true;
                        await CacheHelper.Remove(cacheKeyOperator + "info_" + userEntity.F_Id);

                        await CacheHelper.Set(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity);

                        await OperatorProvider.Provider.ClearCurrentErrorNum();

                        return(userEntity);
                    }
                    else
                    {
                        if (userEntity.F_Account != "admin")
                        {
                            int num = await OperatorProvider.Provider.AddCurrentErrorNum();

                            string erornum = (5 - num).ToString();
                            if (num == 5)
                            {
                                userEntity.F_EnabledMark = false;
                                await repository.Update(userEntity);

                                await OperatorProvider.Provider.ClearCurrentErrorNum();

                                throw new Exception("密码不正确,账户被系统锁定");
                            }
                            else
                            {
                                throw new Exception("密码不正确,请重新输入,还有" + erornum + "次机会");
                            }
                        }
                        else
                        {
                            throw new Exception("密码不正确,请重新输入");
                        }
                    }
                }
                else
                {
                    throw new Exception("账户被系统锁定,请联系管理员");
                }
            }
            else
            {
                throw new Exception("账户不存在,请重新输入");
            }
        }