示例#1
0
        public void ResetPassword(string usernaem, string oldPassword, string newPassword, string code, ValidateType codeType, string ip)
        {
            ExceptionHelper.ThrowIfNullOrEmpty(usernaem, "username");
            ExceptionHelper.ThrowIfTrue(!StringRule.VerifyPassword(newPassword), "password", "密码长度必须介于6到20位之间");
            ExceptionHelper.ThrowIfTrue(string.IsNullOrWhiteSpace(oldPassword) && String.IsNullOrWhiteSpace(code), "旧密码和验证码不能同时为空");
            if (!String.IsNullOrWhiteSpace(code))
            {
                _MobileManager.Verify(code, usernaem, codeType);
            }
            var result = _OAuth2Service.ResetPassword(OAuth2Context.Current.ClientId, OAuth2Context.Current.ClientSecret, usernaem, oldPassword, newPassword, ip, null);

            switch (result.error)
            {
            case ErrorResponseType.none:
                break;

            case ErrorResponseType.invalid_grant:
            case ErrorResponseType.invalid_request:
                throw new ExceptionWithErrorCode(ErrorCode.帐号或密码不正确, result.error_description);

            case ErrorResponseType.username_non_existent:
                throw new ExceptionWithErrorCode(ErrorCode.未找到该用户, result.error_description);

            case ErrorResponseType.server_error:
                throw new ExceptionWithErrorCode(ErrorCode.务器错误, result.error_description);

            default:
                throw new AuthorizationException("State:" + result.error.ToString() + ",Msg:" + result.error_description);
            }
        }
示例#2
0
        public long AddUserByFootChatAdmin(string mobile, string password, string ip, string from)
        {
            ExceptionHelper.ThrowIfNullOrWhiteSpace(from, "from", "注册来源不能为空");
            ExceptionHelper.ThrowIfTrue(!StringRule.VerifyPassword(password), "password", "密码格式错误");
            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);
                });
            }
            else
            {
                throw new ExceptionWithErrorCode(ErrorCode.对应条目已存在, "该用户已经存在");
            }
            return(uid);
        }
示例#3
0
 public void ChangePassword(string oldPassword, string newPasswrod)
 {
     ExceptionHelper.ThrowIfNullOrWhiteSpace(newPasswrod, "newPasswrod", "新密码");
     ExceptionHelper.ThrowIfNullOrWhiteSpace(oldPassword, "oldPassword", "旧密码");
     newPasswrod = newPasswrod.Trim();
     ExceptionHelper.ThrowIfTrue(!StringRule.VerifyPassword(newPasswrod), "password", "新密码格式不正确,密码长度为6-20位");
     if (!new Security.MD5().Verify(oldPassword.Trim(), _LazyUser.Value.pwd))
     {
         throw new FlhException(ErrorCode.ErrorUserNoOrPwd, "账号或密码错误");
     }
     _LazyUser.Value.pwd = new Security.MD5().Encrypt(newPasswrod);
     _UserRepository.SaveChanges();
 }
示例#4
0
        public void ResetPassword(string mobile, string password)
        {
            ExceptionHelper.ThrowIfNullOrWhiteSpace(mobile, "mobile", "手机号码不能为空");
            ExceptionHelper.ThrowIfTrue(!StringRule.VerifyPassword(password), "password", "密码格式不正确,密码长度为6-20位");

            var user = _UserRepository.Entities.Where(u => u.mobile == mobile.Trim()).FirstOrDefault();

            if (user == null)
            {
                throw new FlhException(ErrorCode.NotExists, "用户不存在");
            }
            user.pwd = new Security.MD5().Encrypt(password);
            _UserRepository.SaveChanges();
        }
示例#5
0
        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));
            }
        }
示例#6
0
        public ActionResult Register([Bind(Include = "userName,password")] User user)
        {
            //bool flag=_UserManager.CheckUserName(user.UserName);
            //if(flag)
            //{
            //    IUserService _UserService=_UserManager.add(user);

            //}
            string password = user.Password;
            string msg      = "";

            if (!StringRule.VerifyPassword(password))
            {
                msg = "密码长度不符合规范";
                return(JsonString(new BaseReponseModel()
                {
                    Msg = msg, Status = "no", Url = Url.RouteUrl(new { controller = "User", action = "Register" })
                }));                                                                                                                                      //JsonString return JsonStringResult(object value)
            }
            if (string.IsNullOrEmpty(user.UserName) || _UserManager.CheckUserName(user.UserName))
            {
                msg = "用户名为空或该用户已经存在";
                return(JsonString(new BaseReponseModel()
                {
                    Msg = msg, Status = "no", Url = Url.RouteUrl(new { controller = "User", action = "Register" })
                }));
            }
            var userservice = _UserManager.add(user);

            SaveLoginUser(new LoginUserModel()
            {
                UserId = userservice.UserId
            });
            return(JsonString(new BaseReponseModel()
            {
                Msg = "注册成功", Status = "ok", Url = Url.RouteUrl(new { controller = "User", action = "Login" })
            }));
        }