Beispiel #1
0
        public override UserLoginAndRegisterResponseBody ExecuteCore()
        {
            UserLoginAndRegisterResponseBody res = new UserLoginAndRegisterResponseBody();
            IQueryable <t_user>      query       = db.t_user;
            IQueryable <t_user_code> codeQuery   = db.t_user_code;

            if (this.isMobile)
            {
                query     = query.Where(u => u.mobile == this.request.Mobile);
                codeQuery = db.t_user_code.Where(u => u.user_account == this.request.Mobile);
            }
            else
            {
                query     = query.Where(u => u.email == this.request.Email);
                codeQuery = db.t_user_code.Where(u => u.user_account == this.request.Email);
            }

            t_user_code oldCode = null;

            if (this.request.CheckCode != AppConfigManager.CheckCodeForDebug)
            {
                oldCode = codeQuery.OrderByDescending(u => u.id).FirstOrDefault();
                if (oldCode == null || oldCode.code != this.request.CheckCode)
                {
                    throw new Exception("验证码错误");
                }
                if (oldCode.expire_time <= DateTime.Now)
                {
                    throw new Exception("验证码已过期");
                }
            }

            t_user user = query.FirstOrDefault();

            if (user == null)
            {
                user = this.CreateUser();
            }
            if (user.status != UserStatus.Normal)
            {
                throw new Exception("用户已经被禁用");
            }

            string userToken = UserUtility.BuildToken(user.id);
            bool   succ      = UserStore.SaveUserToken(user.id, userToken);

            if (!succ)
            {
                throw new Exception("用户登录token生成失败");
            }

            UserRegisterAreaInfo pos = null;

            if (user.register_country > 0 || user.register_province > 0 || user.register_city > 0 || user.register_district > 0)
            {
                pos = (from country in db.t_country
                       join province in db.t_province on country.id equals province.country_id
                       join city in db.t_city on province.id equals city.province_id
                       join dist in db.t_district on city.id equals dist.city_id
                       where country.id == user.register_country &&
                       province.id == user.register_province &&
                       city.id == user.register_city &&
                       dist.id == user.register_district
                       select new UserRegisterAreaInfo
                {
                    CountryId = country.id,
                    Country = country.name,
                    ProvinceId = province.id,
                    Province = province.name,
                    CityId = city.id,
                    City = city.name,
                    DistrictId = dist.id,
                    District = dist.name,
                }).FirstOrDefault();
            }

            res.UserInfo = new UserBaseInfo()
            {
                Id              = user.id,
                Symbol          = user.symbol,
                Email           = user.email,
                Mobile          = user.mobile,
                Name            = user.name,
                Token           = userToken,
                HeadImage       = user.head_image,
                CircleBackImage = user.circle_back_image,
                UserSex         = user.sex,
                LifeNotes       = user.life_notes,
                RegAreaInfo     = pos,
                FriendCount     = db.t_user_friend.Where(f => f.user_id == user.id).Count(),
                GroupCount      = db.t_group_user.Where(f => f.user_id == user.id).Count()
            };

            //设置注册码过期
            if (oldCode != null)
            {
                oldCode.expire_time = oldCode.expire_time.AddDays(-1);
                db.SaveChanges();
            }

            return(res);
        }
Beispiel #2
0
        public override UserLoginResponseBody ExecuteCore()
        {
            UserLoginResponseBody res   = new UserLoginResponseBody();
            IQueryable <t_user>   query = db.t_user;

            if (!string.IsNullOrEmpty(this.request.Mobile))
            {
                query = query.Where(u => u.mobile == this.request.Mobile);
            }
            else
            {
                query = query.Where(u => u.email == this.request.Email);
            }

            t_user user = query.FirstOrDefault();

            if (user == null)
            {
                throw new Exception("用户不存在");
            }
            if (user.status != UserStatus.Normal)
            {
                throw new Exception("用户已经被禁用");
            }
            if (user.password != this.request.Password)
            {
                throw new Exception("密码错误");                                        //CommonCs.GetMd5Str32(this.request.Password)
            }
            UserStore.RemoveUserToken(user.id);
            string userToken = UserUtility.BuildToken(user.id);
            bool   succ      = UserStore.SaveUserToken(user.id, userToken);

            if (!succ)
            {
                throw new Exception("用户登录token生成失败");
            }

            UserRegisterAreaInfo pos = (from country in db.t_country
                                        join province in db.t_province on country.id equals province.country_id
                                        join city in db.t_city on province.id equals city.province_id
                                        join dist in db.t_district on city.id equals dist.city_id
                                        where country.id == user.register_country &&
                                        province.id == user.register_province &&
                                        city.id == user.register_city &&
                                        dist.id == user.register_district
                                        select new UserRegisterAreaInfo
            {
                CountryId = country.id,
                Country = country.name,
                ProvinceId = province.id,
                Province = province.name,
                CityId = city.id,
                City = city.name,
                DistrictId = dist.id,
                District = dist.name,
            }).FirstOrDefault();

            res.UserInfo = new Entity.Extends.UserBaseInfo()
            {
                Id              = user.id,
                Symbol          = user.symbol,
                Email           = user.email,
                Mobile          = user.mobile,
                Name            = user.name,
                Token           = userToken,
                HeadImage       = user.head_image,
                CircleBackImage = user.circle_back_image,
                UserSex         = user.sex,
                LifeNotes       = user.life_notes,
                //RegisterPosIdList = posIdList,
                //RegisterPosList = posList,
                RegAreaInfo = pos,
                FriendCount = db.t_user_friend.Where(f => f.user_id == user.id).Count(),
                GroupCount  = db.t_group_user.Where(f => f.user_id == user.id).Count()
            };

            return(res);
        }