public void UpdateMobile(string mobile) { ExceptionHelper.ThrowIfNullOrWhiteSpace(mobile, nameof(mobile)); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(mobile), "手机号不符合格式"); if (mobile != _LazyValue.Value.mobile) { using (var scope = new TransactionScope()) { var isExist = _UserRepository.Entities.FirstOrDefault(p => p.mobile == mobile) != null; if (isExist) { throw new ExceptionWithErrorCode(ErrorCode.该手机号码已被注册); } _LazyValue.Value.mobile = mobile; _UserRepository.SaveChanges(); scope.Complete(); } //推送到图数据库 var taskFactory = new TaskFactory(); taskFactory.StartNew(() => { _FCRMAPIPushManager.UpdateFootUserMobile(_Uid, mobile, false); }); } }
public void ChangeMobile(string mobile) { ExceptionHelper.ThrowIfNullOrEmpty(mobile, "mobile"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(mobile), "mobile", "手机号码格式不正确"); ExceptionHelper.ThrowIfTrue(!_UserManager.IsUsableMobile(mobile), "mobile", "此手机已经被注册"); _LazyUser.Value.mobile = mobile.Trim(); _UserRepository.SaveChanges(); }
public IQueryable <Data.AddressBookMobile> GetHas(string mobile) { if (!StringRule.VerifyMobile(mobile)) { return(Enumerable.Empty <Data.AddressBookMobile>().AsQueryable()); } return(_AddressBookMobileRepository.Entities.Where(b => b.mobile == mobile && !b.haveRecommended)); }
public void SendVerifyCode(string mobile, ValidateType verifyType, long?uid, string signName, string ip, string from) { ExceptionHelper.ThrowIfNullOrWhiteSpace(mobile, "mobile", "手机号码不能为空"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(mobile), "mobile", "手机号码格式错误"); using (var service = _UserManagerService.NewChannelProvider()) { service.Channel.SendCode(new OAuth2ClientIdentity(), mobile, verifyType, uid, signName, ip, from); } }
public void SetRecommendedState(bool recommended, string mobile, long[] uids) { if (StringRule.VerifyMobile(mobile) && uids != null && uids.Length > 0) { _AddressBookMobileRepository.Update(a => a.mobile == mobile && uids.Contains(a.uid), a => new Data.AddressBookMobile { haveRecommended = recommended }); } }
public string Verify(string code, string mobile, ValidateType verifyType) { ExceptionHelper.ThrowIfNullOrWhiteSpace(code, "code", "手机验证码不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(mobile, "mobile"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(mobile), "mobile", "手机号码格式错误"); var result = String.Empty; result = _VerifyHelper.Verify(mobile, code, verifyType); return(result); }
public void SendVerifyCode(string mobile, VerifyType verifyType) { ExceptionHelper.ThrowIfNullOrWhiteSpace(mobile, "mobile"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(mobile), "mobile", "手机号码格式不正确"); switch (verifyType) { case VerifyType.Common: case VerifyType.FormatPwd: if (!_UserRepository.Entities.Any(u => u.mobile == mobile.Trim())) { throw new Flh.FlhException(ErrorCode.NotExists, "该手机未注册"); } break; case VerifyType.ChangeMobile: case VerifyType.Register: if (_UserRepository.Entities.Any(u => u.mobile == mobile.Trim())) { throw new Flh.FlhException(ErrorCode.Exists, "该手机已被注册"); } break; } var entity = GetValidityCode(mobile); var message = String.Empty; if (entity == null || entity.createDate.AddMinutes(10) < DateTime.Now) { var code = CreateCode(); using (var scope = new TransactionScope()) { _VerifyCodeRepository.Delete(vc => vc.mobile == mobile); _VerifyCodeRepository.Add(entity = new Data.VerifyCode { code = code, createDate = DateTime.Now, mobile = mobile, endDate = DateTime.Now.AddMinutes(30) }); _VerifyCodeRepository.SaveChanges(); SendSmsMessage(mobile, verifyType, code); scope.Complete(); } } else { SendSmsMessage(mobile, verifyType, entity.code); } }
public string Verify(string mobile, string code, ValidateType type) { var error = ErrorCode.None; ExceptionHelper.ThrowIfNullOrWhiteSpace(mobile, "mobile", "手机号码不能为空"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(mobile), "mobile", "手机号码格式错误"); using (var service = _UserManagerService.NewChannelProvider()) { return(service.Channel.Verify(new OAuth2ClientIdentity(), mobile, code, type)); } }
public IEnumerable <AddressBookMobile> Change(IEnumerable <AddressBookItem> items) { List <AddressBookMobile> result = new List <AddressBookMobile>(); if (items == null) { return(Enumerable.Empty <AddressBookMobile>().ToArray()); } var books = items.Where(b => StringRule.VerifyMobile(b.Mobile) && (b.TgUid == null || b.TgUid != _User.Uid)).ToArray(); if (books.Length == 0) { return(Enumerable.Empty <AddressBookMobile>().ToArray()); } foreach (var item in books) { item.Mobile = (item.Mobile ?? String.Empty).Trim(); item.Name = (item.Name ?? String.Empty).Trim().Left(50); item.Company = (item.Company ?? String.Empty).Trim().Left(100); } var mobiles = books.Select(b => b.Mobile).Distinct().ToArray(); lock (_Locker) { var exist = _AddressBookMobileRepository.Entities.Where(m => m.uid == _User.Uid && mobiles.Contains(m.mobile)).Select(m => m.mobile).ToArray(); if (exist.Length > 0) { mobiles = mobiles.Except(exist).ToArray(); } if (mobiles.Length > 0) { result.AddRange(mobiles.Select(m => new Data.AddressBookMobile { mobile = m, createDate = DateTime.Now, uid = _User.Uid, tguid = books.Where(b => b.Mobile == m).Select(b => b.TgUid).FirstOrDefault(), company = books.Where(b => b.Mobile == m).Select(b => b.Company).FirstOrDefault(), name = books.Where(b => b.Mobile == m).Select(b => b.Name).FirstOrDefault() })); _AddressBookMobileRepository.AddRange(result); _AddressBookMobileRepository.SaveChanges(); } _PushManager.GenContact(_User.Uid, _User.Mobile, result.Select(b => new FCRMAPI.Request.Contact() { Aid = b.id, Mobile = b.mobile }).ToArray()); } return(result); }
public IUserService Login(string mobileOrEmail, string password, string ip) { ExceptionHelper.ThrowIfNullOrWhiteSpace(mobileOrEmail, "mobileOrEmail", "账号不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(password, "password", "密码不能为空"); var source = _UserRepository.Entities; if (StringRule.VerifyMobile(mobileOrEmail)) { source = source.Where(u => u.mobile == mobileOrEmail.Trim()); } else if (StringRule.VerifyEmail(mobileOrEmail)) { source = source.Where(u => u.email == mobileOrEmail.Trim()); } else { ExceptionHelper.ThrowIfTrue(true, "mobileOrEmail", "请输入手机或者邮箱进行登陆"); } var user = source.FirstOrDefault(); if (user == null) { throw new FlhException(ErrorCode.NotExists, "账号不存在"); } if (!user.enabled) { throw new FlhException(ErrorCode.Locked, "账号已被锁定"); } if (!new Security.MD5().Verify(password.Trim(), user.pwd)) { throw new FlhException(ErrorCode.ErrorUserNoOrPwd, "账号或密码错误"); } ip = (ip ?? String.Empty).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? String.Empty; user.last_login_date = DateTime.Now; _UserRepository.SaveChanges(); var history = new Data.LoginHistory { ip = ip, login_date = DateTime.Now, uid = user.uid }; _LoginHistoryRepository.Add(history); _LoginHistoryRepository.SaveChanges(); return(GetUser(user)); }
public UserSimpleInfo[] GetTgUserInfoByMobiles(IEnumerable <string> mobiles) { if (mobiles == null) { return(new Tgnet.FootChat.UserService.UserSimpleInfo[0]); } mobiles = mobiles.Where(m => StringRule.VerifyMobile(m)).ToArray(); if (mobiles.Count() == 0) { return(new Tgnet.FootChat.UserService.UserSimpleInfo[0]); } using (var provider = _UserInfoServiceChannelProvider.NewChannelProvider()) { return(provider.Channel.GetUsersSimpleInfoByMobiles(new OAuth2ClientIdentity(), mobiles.ToArray())); } }
public IUserService Register(IRegisterInfo info) { ExceptionHelper.ThrowIfNull(info, "info"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(info.Mobile), "mobile", "手机格式不正确"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyEmail(info.Email), "email", "邮箱格式不正确"); ExceptionHelper.ThrowIfTrue(!StringRule.VerifyPassword(info.Password), "password", "密码格式不正确,密码长度为6-20位"); ExceptionHelper.ThrowIfNullOrWhiteSpace(info.Name, "name", "名称不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(info.Company, "company", "公司不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(info.AreaNo, "areaNo", "没有选择地区"); ExceptionHelper.ThrowIfNullOrWhiteSpace(info.Address, "address", "地址不能为空"); ExceptionHelper.ThrowIfNullOrWhiteSpace(info.IndustryNo, "industryNo", "没有选择行业类别"); ExceptionHelper.ThrowIfTrue(!IsUsableMobile(info.Mobile), "mobile", "此手机号已经被注册"); ExceptionHelper.ThrowIfTrue(!IsUsableEmail(info.Email), "email", "此邮箱已经被注册"); using (var scope = new System.Transactions.TransactionScope()) { _MobileManager.Verify(info.Code, info.Mobile); var entity = new Data.User { address = info.Address.SafeTrim(), area_no = info.AreaNo.SafeTrim(), industry_no = info.IndustryNo.SafeTrim(), company = info.Company.Trim(), email = info.Email.Trim(), employees_count_type = info.EmployeesCountRange, is_purchaser = info.IsPurchaser, mobile = info.Mobile.Trim(), name = info.Name.Trim(), neet_invoice = info.NeetInvoice, tel = info.Tel == null ? null : info.Tel.Trim(), pwd = new Security.MD5().Encrypt(info.Password.Trim()), last_login_date = DateTime.Now, register_date = DateTime.Now, enabled = true, }; _UserRepository.Add(entity); _UserRepository.SaveChanges(); scope.Complete(); return(GetUser(entity)); } }
public bool IsUsableMobile(string mobile) { ExceptionHelper.ThrowIfTrue(!StringRule.VerifyMobile(mobile), "mobile", "手机格式不正确"); return(!_UserRepository.Entities.Any(u => u.mobile == mobile.Trim())); }