Ejemplo n.º 1
0
 public function usernameExists()
 {
     if (isset($_GET['username'])) {
         $response = array("exists" => false);
         $username = $_GET['username'];
         if ($_GET['username'] != '' && \CODOF\User\User::usernameExists($username)) {
             $response['exists'] = true;
         }
         echo json_encode($response);
     }
 }
Ejemplo n.º 2
0
 /**
  * Constraints defined for username
  * @param type $username
  */
 public function username($username)
 {
     $username_len = strlen($username);
     $min_username_len = \CODOF\Util::get_opt('register_username_min');
     $errors = array();
     if ($username_len < $min_username_len) {
         $errors[] = _t("username cannot be less than {$min_username_len} characters!");
     }
     if (preg_match('/^[A-Za-z0-9_-]+$/', $username) === 0) {
         $errors[] = _t("username can have only letters digits and underscores");
     }
     if (\CODOF\User\User::usernameExists($username)) {
         $errors[] = _t("user already exists");
     }
     $this->errors = array_merge($errors, $this->errors);
     if (empty($errors)) {
         \CODOF\Hook::call('on_username_ok');
         return TRUE;
         //passed
     }
     \CODOF\Hook::call('on_username_fail');
     return FALSE;
     //Fail
 }
Ejemplo n.º 3
0
     $secret = CODOF\Util::get_opt('sso_secret');
     if (!empty($user)) {
         unset($user['token']);
         $sso_token = md5(urlencode(json_encode($user)) . $secret . $_POST['timestamp']);
     }
     $username = $user['name'];
     $mail = $user['mail'];
     if ($sso_token != $posted_token) {
         echo 'error';
         exit;
     }
     $db = DB::getPDO();
     if (!CODOF\User\User::mailExists($mail)) {
         //this user does not have an account in codoforum
         $reg = new \CODOF\User\Register($db);
         if (\CODOF\User\User::usernameExists($username)) {
             $username .= time();
         }
         $reg->username = $username;
         $reg->name = $username;
         $reg->mail = $mail;
         $reg->user_status = 1;
         $ret = $reg->register_user();
         $reg->login();
         if (!empty($ret)) {
             echo "error";
         }
     } else {
         CODOF\User\User::loginByMail($mail);
     }
 }