Beispiel #1
0
 public function testNickname()
 {
     $result = SimpleValidator::nickname("ffgifghjfdggg", array());
     $this->assertEquals(true, $result);
     $result = SimpleValidator::nickname("s", array());
     $this->assertEquals(false, $result);
     $result = SimpleValidator::nickname("qertyuiosdfghjklxcvbnmvb", array());
     $this->assertEquals(false, $result);
 }
Beispiel #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));
 }
 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);
 }
Beispiel #4
0
 protected function generateUser($type, $token, $oauthUser, $setData)
 {
     $registration = array();
     $randString = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
     $oauthUser['name'] = preg_replace('/[^\\x{4e00}-\\x{9fa5}a-zA-z0-9_.]+/u', '', $oauthUser['name']);
     $oauthUser['name'] = str_replace(array('-'), array('_'), $oauthUser['name']);
     if (!SimpleValidator::nickname($oauthUser['name'])) {
         $oauthUser['name'] = '';
     }
     $tempType = $type;
     if (empty($oauthUser['name'])) {
         if ($type == 'weixinmob' || $type == 'weixinweb') {
             $tempType = 'weixin';
         }
         $oauthUser['name'] = "{$tempType}" . substr($randString, 9, 3);
     }
     $nameLength = mb_strlen($oauthUser['name'], 'utf-8');
     if ($nameLength > 10) {
         $oauthUser['name'] = mb_substr($oauthUser['name'], 0, 11, 'utf-8');
     }
     if (!empty($setData['nickname']) && !empty($setData['email'])) {
         $registration['nickname'] = $setData['nickname'];
         $registration['email'] = $setData['email'];
         $registration['emailOrMobile'] = $setData['email'];
     } else {
         $nicknames = array();
         $nicknames[] = isset($setData['nickname']) ? $setData['nickname'] : $oauthUser['name'];
         $nicknames[] = mb_substr($oauthUser['name'], 0, 8, 'utf-8') . substr($randString, 0, 3);
         $nicknames[] = mb_substr($oauthUser['name'], 0, 8, 'utf-8') . substr($randString, 3, 3);
         $nicknames[] = mb_substr($oauthUser['name'], 0, 8, 'utf-8') . substr($randString, 6, 3);
         foreach ($nicknames as $name) {
             if ($this->getUserService()->isNicknameAvaliable($name)) {
                 $registration['nickname'] = $name;
                 break;
             }
         }
         if (empty($registration['nickname'])) {
             return null;
         }
         $registration['email'] = 'u_' . substr($randString, 0, 12) . '@edusoho.net';
     }
     $registration['password'] = substr(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36), 0, 8);
     $registration['token'] = $token;
     $registration['createdIp'] = $oauthUser['createdIp'];
     if (isset($setData['mobile']) && !empty($setData['mobile'])) {
         $registration['mobile'] = $setData['mobile'];
         $registration['emailOrMobile'] = $setData['mobile'];
     }
     /*if($this->setting("auth.register_mode", "email") == "email_or_mobile") {
           $registration['emailOrMobile'] = $registration['email'];
           unset($registration['email']);
       }*/
     $user = $this->getAuthService()->register($registration, $type);
     return $user;
 }
 public function register($registration, $type = 'default')
 {
     if (!SimpleValidator::nickname($registration['nickname'])) {
         throw $this->createServiceException('nickname error!');
     }
     if (!$this->isNicknameAvaliable($registration['nickname'])) {
         throw $this->createServiceException('昵称已存在');
     }
     if (!SimpleValidator::email($registration['email'])) {
         throw $this->createServiceException('email error!');
     }
     if (!$this->isEmailAvaliable($registration['email'])) {
         throw $this->createServiceException('Email已存在');
     }
     $user = array();
     if (isset($registration['verifiedMobile'])) {
         $user['verifiedMobile'] = $registration['verifiedMobile'];
     } else {
         $user['verifiedMobile'] = '';
     }
     $user['email'] = $registration['email'];
     $user['emailVerified'] = isset($registration['emailVerified']) ? $registration['emailVerified'] : 0;
     $user['nickname'] = $registration['nickname'];
     $user['roles'] = array('ROLE_USER');
     $user['type'] = isset($registration['type']) ? $registration['type'] : $type;
     $user['createdIp'] = empty($registration['createdIp']) ? '' : $registration['createdIp'];
     $user['createdTime'] = time();
     $thirdLoginInfo = $this->getSettingService()->get('login_bind', array());
     if (in_array($type, array('default', 'phpwind', 'discuz'))) {
         $user['salt'] = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
         $user['password'] = $this->getPasswordEncoder()->encodePassword($registration['password'], $user['salt']);
         $user['setup'] = 1;
     } elseif (in_array($type, array('qq', 'weibo', 'renren', 'weixinweb', 'weixinmob')) && isset($thirdLoginInfo["{$type}_set_fill_account"]) && $thirdLoginInfo["{$type}_set_fill_account"]) {
         $user['salt'] = '';
         $user['password'] = '';
         $user['setup'] = 1;
     } else {
         $user['salt'] = '';
         $user['password'] = '';
         $user['setup'] = 0;
     }
     $user = UserSerialize::unserialize($this->getUserDao()->addUser(UserSerialize::serialize($user)));
     if (!empty($registration['invite_code'])) {
         $inviteUser = $this->getUserDao()->getUserByInviteCode($registration['invite_code']);
     }
     if (!empty($inviteUser)) {
         $this->getInviteRecordService()->createInviteRecord($inviteUser['id'], $user['id']);
         $inviteCoupon = $this->getCouponService()->generateInviteCoupon($user['id'], 'register');
         if (!empty($inviteCoupon)) {
             $card = $this->getCardService()->getCardByCardId($inviteCoupon['id']);
             $this->getInviteRecordService()->addInviteRewardRecordToInvitedUser($user['id'], array('invitedUserCardId' => $card['cardId']));
         }
     }
     if (isset($registration['mobile']) && $registration['mobile'] != "" && !SimpleValidator::mobile($registration['mobile'])) {
         throw $this->createServiceException('mobile error!');
     }
     if (isset($registration['idcard']) && $registration['idcard'] != "" && !SimpleValidator::idcard($registration['idcard'])) {
         throw $this->createServiceException('idcard error!');
     }
     if (isset($registration['truename']) && $registration['truename'] != "" && !SimpleValidator::truename($registration['truename'])) {
         throw $this->createServiceException('truename error!');
     }
     $profile = array();
     $profile['id'] = $user['id'];
     $profile['mobile'] = empty($registration['mobile']) ? '' : $registration['mobile'];
     $profile['idcard'] = empty($registration['idcard']) ? '' : $registration['idcard'];
     $profile['truename'] = empty($registration['truename']) ? '' : $registration['truename'];
     $profile['company'] = empty($registration['company']) ? '' : $registration['company'];
     $profile['job'] = empty($registration['job']) ? '' : $registration['job'];
     $profile['weixin'] = empty($registration['weixin']) ? '' : $registration['weixin'];
     $profile['weibo'] = empty($registration['weibo']) ? '' : $registration['weibo'];
     $profile['qq'] = empty($registration['qq']) ? '' : $registration['qq'];
     $profile['site'] = empty($registration['site']) ? '' : $registration['site'];
     $profile['gender'] = empty($registration['gender']) ? 'secret' : $registration['gender'];
     for ($i = 1; $i <= 5; $i++) {
         $profile['intField' . $i] = empty($registration['intField' . $i]) ? null : $registration['intField' . $i];
         $profile['dateField' . $i] = empty($registration['dateField' . $i]) ? null : $registration['dateField' . $i];
         $profile['floatField' . $i] = empty($registration['floatField' . $i]) ? null : $registration['floatField' . $i];
     }
     for ($i = 1; $i <= 10; $i++) {
         $profile['varcharField' . $i] = empty($registration['varcharField' . $i]) ? "" : $registration['varcharField' . $i];
         $profile['textField' . $i] = empty($registration['textField' . $i]) ? "" : $registration['textField' . $i];
     }
     $this->getProfileDao()->addProfile($profile);
     if ($type != 'default') {
         $this->bindUser($type, $registration['token']['userId'], $user['id'], $registration['token']);
     }
     $this->getDispatcher()->dispatch('user.service.registered', new ServiceEvent($user));
     return $user;
 }
 public function register($registration, $type = 'default')
 {
     if (!SimpleValidator::nickname($registration['nickname'])) {
         throw $this->createServiceException('nickname error!');
     }
     if (!$this->isNicknameAvaliable($registration['nickname'])) {
         throw $this->createServiceException('用户名已存在');
     }
     if (!SimpleValidator::email($registration['email'])) {
         throw $this->createServiceException('email error!');
     }
     if (!$this->isEmailAvaliable($registration['email'])) {
         throw $this->createServiceException('Email已存在');
     }
     $user = array();
     if (isset($registration['verifiedMobile'])) {
         $user['verifiedMobile'] = $registration['verifiedMobile'];
     } else {
         $user['verifiedMobile'] = '';
     }
     $user['email'] = $registration['email'];
     $user['nickname'] = $registration['nickname'];
     $user['roles'] = array('ROLE_USER');
     $user['type'] = $type;
     $user['createdIp'] = empty($registration['createdIp']) ? '' : $registration['createdIp'];
     $user['createdTime'] = time();
     if (in_array($type, array('default', 'phpwind', 'discuz'))) {
         $user['salt'] = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
         $user['password'] = $this->getPasswordEncoder()->encodePassword($registration['password'], $user['salt']);
         $user['setup'] = 1;
     } else {
         $user['salt'] = '';
         $user['password'] = '';
         $user['setup'] = 0;
     }
     $user = UserSerialize::unserialize($this->getUserDao()->addUser(UserSerialize::serialize($user)));
     if (isset($registration['mobile']) && $registration['mobile'] != "" && !SimpleValidator::mobile($registration['mobile'])) {
         throw $this->createServiceException('mobile error!');
     }
     if (isset($registration['idcard']) && $registration['idcard'] != "" && !SimpleValidator::idcard($registration['idcard'])) {
         throw $this->createServiceException('idcard error!');
     }
     if (isset($registration['truename']) && $registration['truename'] != "" && !SimpleValidator::truename($registration['truename'])) {
         throw $this->createServiceException('truename error!');
     }
     $profile = array();
     $profile['id'] = $user['id'];
     $profile['mobile'] = empty($registration['mobile']) ? '' : $registration['mobile'];
     $profile['idcard'] = empty($registration['idcard']) ? '' : $registration['idcard'];
     $profile['truename'] = empty($registration['truename']) ? '' : $registration['truename'];
     $profile['company'] = empty($registration['company']) ? '' : $registration['company'];
     $profile['job'] = empty($registration['job']) ? '' : $registration['job'];
     $profile['weixin'] = empty($registration['weixin']) ? '' : $registration['weixin'];
     $profile['weibo'] = empty($registration['weibo']) ? '' : $registration['weibo'];
     $profile['qq'] = empty($registration['qq']) ? '' : $registration['qq'];
     $profile['site'] = empty($registration['site']) ? '' : $registration['site'];
     $profile['gender'] = empty($registration['gender']) ? 'secret' : $registration['gender'];
     for ($i = 1; $i <= 5; $i++) {
         $profile['intField' . $i] = empty($registration['intField' . $i]) ? null : $registration['intField' . $i];
         $profile['dateField' . $i] = empty($registration['dateField' . $i]) ? null : $registration['dateField' . $i];
         $profile['floatField' . $i] = empty($registration['floatField' . $i]) ? null : $registration['floatField' . $i];
     }
     for ($i = 1; $i <= 10; $i++) {
         $profile['varcharField' . $i] = empty($registration['varcharField' . $i]) ? "" : $registration['varcharField' . $i];
         $profile['textField' . $i] = empty($registration['textField' . $i]) ? "" : $registration['textField' . $i];
     }
     $this->getProfileDao()->addProfile($profile);
     if ($type != 'default') {
         $this->bindUser($type, $registration['token']['userId'], $user['id'], $registration['token']);
     }
     $this->getDispatcher()->dispatch('user.service.registered', new ServiceEvent($user));
     return $user;
 }
Beispiel #7
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);
 }