Airship\Cabin\Bridge\Blueprint\UserAccounts::isUsernameTaken PHP Method

isUsernameTaken() public method

Is the username already taken by another account?
public isUsernameTaken ( string $username ) : boolean
$username string
return boolean
    public function isUsernameTaken(string $username) : bool
    {
        $num = $this->db->cell('SELECT
                count(userid)
            FROM
                airship_users
            WHERE
                username = ?', $username);
        return $num > 0;
    }

Usage Example

Esempio n. 1
0
 /**
  * Process a user account registration request
  *
  * @param array $post
  */
 protected function processBoard(array $post = [])
 {
     if (empty($post['username']) || empty($post['passphrase'])) {
         $this->lens('board', ['post_response' => ['message' => \__('Please fill out the form entirely'), 'status' => 'error']]);
     }
     if ($this->acct->isUsernameTaken($post['username'])) {
         $this->lens('board', ['post_response' => ['message' => \__('Username is not available'), 'status' => 'error']]);
     }
     if ($this->acct->isPasswordWeak($post)) {
         $this->lens('board', ['post_response' => ['message' => \__('Supplied password is too weak.'), 'status' => 'error']]);
     }
     $userID = $this->acct->createUser($post);
     $_SESSION['userid'] = (int) $userID;
     \Airship\redirect($this->airship_cabin_prefix);
 }