예제 #1
0
 public function testPassword()
 {
     $result = SimpleValidator::password("qwer", array());
     $this->assertEquals(false, $result);
     $result = SimpleValidator::password("qwert", array());
     $this->assertEquals(true, $result);
     $result = SimpleValidator::password("123456", array());
     $this->assertEquals(true, $result);
     $result = SimpleValidator::password("qwertqwertqwertqwetq", array());
     $this->assertEquals(true, $result);
     $result = SimpleValidator::password("qwertqwertqwertq2wetq", array());
     $this->assertEquals(false, $result);
 }
예제 #2
0
 public function registerAction(Request $request)
 {
     $email = $request->get('email');
     $nickname = $request->get('nickname');
     $password = $request->get('password');
     if (!$this->getAuthService()->isRegisterEnabled()) {
         return $this->createErrorResponse($request, 'register_closed', '注册已关闭,请联系管理员');
     }
     if (!SimpleValidator::email($email)) {
         return $this->createErrorResponse($request, 'email_invalid', '邮箱地址格式不正确');
     }
     if (!SimpleValidator::nickname($nickname)) {
         return $this->createErrorResponse($request, 'nickname_invalid', '用户名格式不正确');
     }
     if (!SimpleValidator::password($password)) {
         return $this->createErrorResponse($request, 'password_invalid', '密码格式不正确');
     }
     if (!$this->getUserService()->isEmailAvaliable($email)) {
         return $this->createErrorResponse($request, 'email_exist', '该邮箱已被注册');
     }
     if (!$this->getUserService()->isNicknameAvaliable($nickname)) {
         return $this->createErrorResponse($request, 'nickname_exist', '该用户名已被注册');
     }
     $user = $this->getAuthService()->register(array('email' => $email, 'nickname' => $nickname, 'password' => $password));
     $token = $this->createToken($user, $request);
     return $this->createJson($request, array('user' => $this->filterUser($user), 'token' => $token));
 }
예제 #3
0
 public function regist()
 {
     $email = $this->getParam('email');
     $nickname = $this->getParam('nickname');
     $password = $this->getParam('password');
     $auth = $this->getSettingService()->get('auth', array());
     if (isset($auth['register_mode']) && $auth['register_mode'] == 'closed') {
         return $this->createErrorResponse('register_closed', '系统暂时关闭注册,请联系管理员');
     }
     if ($auth['register_mode'] == 'mobile') {
         return $this->createErrorResponse('register_error', '移动端暂不支持手机注册,敬请期待!');
     }
     if (!SimpleValidator::email($email)) {
         return $this->createErrorResponse('email_invalid', '邮箱地址格式不正确');
     }
     if (!SimpleValidator::nickname($nickname)) {
         return $this->createErrorResponse('nickname_invalid', '用户名格式不正确');
     }
     if (!SimpleValidator::password($password)) {
         return $this->createErrorResponse('password_invalid', '密码格式不正确');
     }
     if (!$this->controller->getUserService()->isEmailAvaliable($email)) {
         return $this->createErrorResponse('email_exist', '该邮箱已被注册');
     }
     if (!$this->controller->getUserService()->isNicknameAvaliable($nickname)) {
         return $this->createErrorResponse('nickname_exist', '该用户名已被注册');
     }
     $registTypeName = $auth['register_mode'] == "email" ? "email" : "emailOrMobile";
     $user = $this->controller->getAuthService()->register(array($registTypeName => $email, 'nickname' => $nickname, 'password' => $password));
     $token = $this->controller->createToken($user, $this->request);
     $this->log("user_regist", "用户注册", array("user" => $user));
     return array('user' => $this->controller->filterUser($user), 'token' => $token);
 }
예제 #4
0
 public function regist()
 {
     $email = $this->getParam('email');
     $password = $this->getParam('password');
     $nickname = $this->getParam('nickname');
     $phoneNumber = $this->getParam('phone');
     $smsCode = $this->getParam('smsCode');
     $result = array('meta' => null);
     $auth = $this->getSettingService()->get('auth', array());
     if (isset($auth['register_mode']) && $auth['register_mode'] == 'closed') {
         return $this->createErrorResponse('register_closed', '系统暂时关闭注册,请联系管理员');
     }
     if (!$nickname) {
         $nickname = "ES" . time();
         while (!$this->controller->getUserService()->isNicknameAvaliable($nickname)) {
             $nickname = "ES" . time();
         }
     } else {
         if (!$this->controller->getUserService()->isNicknameAvaliable($nickname)) {
             return $this->createErrorResponse('nickname_exist', '该昵称已被注册');
         }
     }
     $user = null;
     if (!empty($email)) {
         if (!SimpleValidator::email($email)) {
             return $this->createErrorResponse('email_invalid', '邮箱地址格式不正确');
         }
         if (!$this->controller->getUserService()->isEmailAvaliable($email)) {
             return $this->createErrorResponse('email_exist', '该邮箱已被注册');
         }
         if (!SimpleValidator::password($password)) {
             return $this->createErrorResponse('password_invalid', '密码格式不正确');
         }
         $registTypeName = $auth['register_mode'] == "email" ? "email" : "emailOrMobile";
         $user = $this->controller->getAuthService()->register(array($registTypeName => $email, 'nickname' => $nickname, 'password' => $password));
     } else {
         if (!$this->checkPhoneNum($phoneNumber)) {
             return $this->createErrorResponse('phone_invalid', '手机号格式不正确');
         }
         if (!$this->getUserService()->isMobileUnique($phoneNumber)) {
             return $this->createErrorResponse('phone_exist', '该手机号码已被其他用户绑定');
         }
         if ($this->controller->setting('cloud_sms.sms_enabled') == '1' && $this->controller->setting('cloud_sms.sms_registration', 'on') == 'on') {
             $requestInfo = array('sms_code' => $smsCode, 'mobile' => $phoneNumber);
             list($result, $sessionField) = $this->smsCheck($this->request, $requestInfo, 'sms_registration');
             if ($result) {
                 $user = $this->controller->getAuthService()->register(array('emailOrMobile' => $sessionField['to'], 'nickname' => $nickname, 'password' => $password));
                 $this->clearSmsSession($this->request, 'sms_registration');
             } else {
                 return $this->createErrorResponse('sms_invalid', '手机短信验证错误,请重新注册');
             }
         }
     }
     if ($nickname && !SimpleValidator::nickname($nickname)) {
         return $this->createErrorResponse('nickname_invalid', '昵称格式不正确');
     }
     $token = $this->controller->createToken($user, $this->request);
     if (!empty($user) && !isset($user["currentIp"])) {
         $user["currentIp"] = "127.0.0.1";
     }
     $this->log("user_regist", "用户注册", array("user" => $user));
     return array('user' => $this->controller->filterUser($user), 'token' => $token);
 }