public AccessTokenResult Register(string mobile, string code, string password, string ip, string from) { ExceptionHelper.ThrowIfNullOrWhiteSpace(from, "from", "注册来源不能为空"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyPassword(password), "password", "密码格式错误"); _MobileManager.Verify(code, mobile, ValidateType.登陆); var areaNo = "0001"; var area = _StaticResourceManager.GetIPArea(ip); if (area != null) { areaNo = area.area_no; } long uid; using (var service = _UserManagerServiceChannelProvider.NewChannelProvider()) { uid = service.Channel.GetUidIfNonexistentRegister(new OAuth2ClientIdentity(), mobile, true, password, ip, from); } ExceptionHelper.ThrowIfTrue(uid <= 0, "uid", "创建用户失败"); var securityPsw = string.Empty; using (var provider = _UserManagerServiceChannelProvider.NewChannelProvider()) { var id = Tgnet.Security.NumberConfuse.Confuse(uid); securityPsw = provider.Channel.GetPassword(new OAuth2ClientIdentity(), id); } if (!_UserRepository.Entities.Any(p => p.uid == uid)) { _UserRepository.Add(new FootUser() { mobile = mobile, uid = uid, password = securityPsw, areaNo = areaNo, isInner = false, isLocked = false, loginCount = 1, lastLogin = DateTime.Now, created = DateTime.Now, verifyImage = String.Empty, verifyStatus = VerifyStatus.None, cover = "", }); _UserRepository.SaveChanges(); //推送到图数据库 var taskFactory = new TaskFactory(); taskFactory.StartNew(() => { _PushManager.AddUser(uid, mobile, false); }); } return(VerificationCodeLogin(mobile, code, ip)); }
private void AddUser(long uid) { var now = DateTime.Now; var verifiedlockDate = new DateTime(1900, 1, 1); var uids = new long[] { uid }; var user = _UserManager.GetTgUserInfos(uids).FirstOrDefault(); if (user != null) { ExceptionHelper.ThrowIfNullOrWhiteSpace(nameof(user), "查询不到用户资料"); } ExceptionHelper.ThrowIfNullOrWhiteSpace(nameof(user.mobile), "用户手机号为空"); string[] businesAreaNos = null; string[] products = null; string[] brands = null; var businessAreasDic = _UserManager.GetTgUserBusinessAreas(uids); if (businessAreasDic.ContainsKey(uid)) { businesAreaNos = businessAreasDic[uid]; } var tgProducts = _UserManager.GetTgUserProducts(uid); if (tgProducts != null && tgProducts.Count() > 0) { products = tgProducts.Where(p => !string.IsNullOrWhiteSpace(p.Name) && p.Name.Length < 50).Select(p => p.Name).Distinct().ToArray(); brands = tgProducts.SelectMany(p => p.Brands).Where(p => !string.IsNullOrWhiteSpace(p) && p.Length < 50).Distinct().ToArray(); } var password = GetRandomPsw(); var areaNo = _StaticResourceManager.GetAreaByAreaName(user.area_province, user.area_city, user.area_county); using (var scope = new TransactionScope()) { if (!CheckExistFootUser(uid)) { _FootChatUserRepository.Add(new FootUser() { mobile = user.mobile, uid = uid, password = password, areaNo = areaNo, isInner = false, isLocked = false, loginCount = 0, lastLogin = now, created = now, verifyImage = String.Empty, verifyStatus = VerifyStatus.None, cover = "", name = user.name, company = user.company, sex = user.sex == "男" ? UserSex.Man : user.sex == "女" ? UserSex.Woman : new UserSex?(), job = user.job, }); _FootChatUserRepository.SaveChanges(); var userService = _UserServiceFactory.GetService(uid); userService.UpdateBusinessAreaNos(businesAreaNos); userService.UpdateProducts(products); userService.UpdateBrands(brands); _ImportUserRecordRepository.Add(new ImportUserRecord() { importTime = now, uid = uid }); _ImportUserRecordRepository.SaveChanges(); //推送到图数据库 _PushManager.AddUser(uid, user.mobile, true); } scope.Complete(); } }