public override UserLoginResponseBody ExecuteCore() { UserLoginResponseBody res = new UserLoginResponseBody(); using (HWLEntities db = new HWLEntities()) { 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) } Redis.UserAction userAction = new Redis.UserAction(); ////获取用户之前是否已经登录过,如果登录过则需要发送消息通知用户在其它位置登录 //string oldToken = userAction.GetUserToken(user.id); //if (!string.IsNullOrEmpty(oldToken)) //{ // //AndroidChatMessage.SendLogoutMessage(user.id, oldToken, "您的帐号已经在其它位置登录,如果不是您本人操作,建议重新登录后立即更换密码!"); //} //清除用户之前登录用过的TOKEN userAction.RemoveUserToken(user.id); string userToken = UserUtility.BuildToken(user.id); bool succ = userAction.SaveUserToken(user.id, userToken); if (!succ) { throw new Exception("用户登录token生成失败"); } //获取地址信息 var 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 { CountryName = country.name, ProvinceName = province.name, CityName = city.name, DistName = dist.name, }).FirstOrDefault(); List <int> posIdList = new List <int>() { user.register_country, user.register_province, user.register_city, user.register_district, }; List <string> posList = new List <string>() { pos != null?pos.CountryName:string.Empty, pos != null?pos.ProvinceName:string.Empty, pos != null?pos.CityName:string.Empty, pos != null?pos.DistName:string.Empty, }; //输出 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, 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() }; //new Redis.ImMessageAction().AddWelcomeImMessage(user.id,, pos != null ? pos.DistName : string.Empty); } return(res); }
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); }
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); }