Ejemplo n.º 1
0
        public async Task <Pager <IQueryable <UserDepartRoleInfo> > > List(UserInfo userInfo)
        {
            //判断查询参数(组装查询条件)
            Expression <Func <UserDepartRoleInfo, bool> > where_search = LinqUtil.True <UserDepartRoleInfo>();

            if (!string.IsNullOrEmpty(userInfo.name))
            {
                where_search = RegexUtil.Email(userInfo.name) ? where_search.AndAlso(c => c.user_email == userInfo.name)
                    : where_search.AndAlso(c => c.user_phone == userInfo.name);
            }
            if (userInfo.gender != -1)
            {
                where_search = where_search.AndAlso(c => c.user_gender == userInfo.gender);
            }
            if (userInfo.source != -1)
            {
                where_search = where_search.AndAlso(c => c.source_type == userInfo.source);
            }
            if (userInfo.status != -1)
            {
                where_search = where_search.AndAlso(c => c.disable == userInfo.status);
            }

            //根据条件查询用户表,部门表,用户部门表查询出来用户信息
            int total = 0;
            IQueryable <UserDepartRoleInfo> user_dep_role = await userRepository.getLeftJoinDepRole(where_search,
                                                                                                    userInfo.pageindex, userInfo.pagesize, out total);

            return(new Pager <IQueryable <UserDepartRoleInfo> >(total, user_dep_role));
        }
Ejemplo n.º 2
0
        public async Task <BaseResult <bool> > checkData(string user_id, string content)
        {
            //这里可以用手机号以及电话号码和邮箱登录,判断是否重复
            Expression <Func <UserEntity, bool> > where = LinqUtil.True <UserEntity>();
            where = RegexUtil.Email(content) ? where.AndAlso(c => c.user_email == content)
                : where.AndAlso(c => c.user_phone == content);

            where = where.AndAlso(c => c.user_id != user_id);

            int count = await userRepository.CountAsync(where);

            if (count > 0)
            {
                return(new BaseResult <bool>(900, true));
            }
            return(new BaseResult <bool>(200, false));
        }
Ejemplo n.º 3
0
        public async Task <BaseResult <bool> > LoginFront(string login_name_in, string user_pwd_in)
        {
            if (string.IsNullOrEmpty(login_name_in) || string.IsNullOrEmpty(user_pwd_in))
            {
                return(new BaseResult <bool>(808, false));
            }

            //这里可以用邮箱和手机号登陆,需要判断使用什么方式登录,查询用户信息之后验证是否可以访问
            Expression <Func <UserEntity, bool> > where = LinqUtil.True <UserEntity>();
            where = RegexUtil.Email(login_name_in) ? where.AndAlso(c => c.user_email == login_name_in) :
                    where.AndAlso(c => c.user_phone == login_name_in);
            where = where.AndAlso(c => c.user_pwd == CommonUtil.Md5(user_pwd_in));

            UserEntity userEntity = await userRepository.GetAsync(where);

            if (userEntity == null)
            {
                return(new BaseResult <bool>(1000, false));
            }
            if (userEntity.disable == (int)DisableStatus.disable_true)
            {
                return(new BaseResult <bool>(1004, false));
            }
            if (userEntity.user_activation == (int)DisableStatus.disable_true)
            {
                return(new BaseResult <bool>(1005, false));
            }

            //修改用户当前时间为当前时间
            await userRepository.UpdateAsync(new UserEntity()
            {
                user_id = userEntity.user_id, last_time = DateTime.Now
            }, true, true, c => c.last_time);

            UserSession userSession = new UserSession
            {
                user_id    = userEntity.user_id,
                user_name  = userEntity.user_name + userEntity.user_code,
                user_image = userEntity.user_image
            };

            httpContextUtil.setObjectAsJson(KeyUtil.user_info_front, userSession);
            return(new BaseResult <bool>(200, true));
        }
Ejemplo n.º 4
0
        public async Task <BaseResult <bool> > Login(string login_name_in, string user_pwd_in)
        {
            if (string.IsNullOrEmpty(login_name_in) || string.IsNullOrEmpty(user_pwd_in))
            {
                return(new BaseResult <bool>(808, false));
            }

            //这里可以用邮箱和手机号登陆,需要判断使用什么方式登录,查询用户信息之后验证是否可以访问
            Expression <Func <UserEntity, bool> > where = LinqUtil.True <UserEntity>();
            where = RegexUtil.Email(login_name_in) ? where.AndAlso(c => c.user_email == login_name_in) :
                    where.AndAlso(c => c.user_phone == login_name_in);
            where = where.AndAlso(c => c.user_pwd == CommonUtil.Md5(user_pwd_in));

            UserEntity userEntity = await userRepository.GetAsync(where);

            if (userEntity == null)
            {
                return(new BaseResult <bool>(1000, false));
            }
            if (userEntity.disable == (int)DisableStatus.disable_true)
            {
                return(new BaseResult <bool>(1004, false));
            }
            if (userEntity.user_activation == (int)DisableStatus.disable_true)
            {
                return(new BaseResult <bool>(1005, false));
            }
            if (userEntity.user_visit == (int)DisableStatus.disable_true)
            {
                return(new BaseResult <bool>(1006, false));
            }

            //用户登录正常,修改用户登录时间并且将登录的信息保存到Session中
            await userRepository.UpdateAsync(new UserEntity()
            {
                user_id = userEntity.user_id, last_time = DateTime.Now
            }, true, true, c => c.last_time);

            //处理信息,如果redis连接成功,则直接判断是否存在值,如果存在,则直接使用,否则直接查询并且保存   ,如果连接失败,则直接查询
            List <string> buttionActions = null;

            if (redisHelp._conn != null)
            {
                string key = string.Format(RedisKeyUtil.login_admin, userEntity.user_id);
                if (redisHelp.KeyExists(key))
                {
                    buttionActions = JsonNetHelper.DeserializeObject <List <string> >(await redisHelp.StringGetAsync(key));
                }
                else
                {
                    buttionActions = buttonActionRepository.GetMenuInfo(userEntity.user_id, c => c.action_type != (int)ActionType.front &&
                                                                        c.action_url != null && c.disable == (int)DisableStatus.disable_false).Select(c => c.action_url).ToList();
                    await redisHelp.StringSetAsync(key, JsonNetHelper.SerializeObject(buttionActions), new TimeSpan(30, 12, 60));
                }
            }
            else
            {
                buttionActions = buttonActionRepository.GetMenuInfo(userEntity.user_id,
                                                                    c => c.action_type != (int)ActionType.front && c.action_url != null && c.disable == (int)DisableStatus.disable_false).Select(c => c.action_url).ToList();
            }

            UserSession userSession = new UserSession
            {
                user_id    = userEntity.user_id,
                user_name  = userEntity.user_name + userEntity.user_code,
                user_image = userEntity.user_image,
                full_name  = userEntity.full_name,
                action_url = buttionActions == null ? null : buttionActions
            };

            httpContextUtil.setObjectAsJson(KeyUtil.user_info, userSession);
            return(new BaseResult <bool>(200, true));
        }