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

createUser() public method

Create a new user account
public createUser ( array $post = [] ) : integer
$post array
return integer
    public function createUser(array $post = []) : int
    {
        $state = State::instance();
        $fingerprint = '';
        if (!empty($post['gpg_public_key'])) {
            try {
                $fingerprint = $state->gpgMailer->import($post['gpg_public_key']);
            } catch (\Crypt_GPG_Exception $ex) {
                // We'll fail silently for now.
            }
        }
        $this->db->insert('airship_users', ['username' => $post['username'], 'password' => $this->airship_auth->createHash(new HiddenString($post['passphrase'])), 'uniqueid' => $this->generateUniqueId(), 'email' => $post['email'] ?? '', 'display_name' => $post['display_name'] ?? '', 'real_name' => $post['real_name'] ?? '', 'allow_reset' => !empty($post['allow_reset']), 'gpg_public_key' => $fingerprint]);
        $userid = $this->db->cell('SELECT
                userid
            FROM
                airship_users
            WHERE
                username = ?', $post['username']);
        // Overrideable, but default to "Registered User".
        $default_groups = $state->universal['default-groups'] ?? [2];
        foreach ($default_groups as $grp) {
            $this->db->insert('airship_users_groups', ['userid' => $userid, 'groupid' => $grp]);
        }
        // Create preferences record.
        $this->db->insert('airship_user_preferences', ['userid' => $userid, 'preferences' => \json_encode($post['preferences'] ?? [])]);
        return $userid;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Create a new user
  *
  * @route crew/users/new
  * @param string $userId
  */
 public function createUser(string $userId = '')
 {
     $userId = (int) $userId;
     $user = $this->account->getUserAccount($userId, true);
     $post = $this->post(new NewUserFilter());
     if ($post) {
         if (!empty($post['preferences'])) {
             if (\is_string($post['preferences'])) {
                 $post['preferences'] = \json_decode($post['preferences'], true);
             }
         } else {
             $post['preferences'] = [];
         }
         $userId = $this->account->createUser($post);
         if ($userId) {
             $this->account->editUserCustomFields($userId, $post['custom_fields'] ?? '[]');
             \Airship\redirect($this->airship_cabin_prefix . '/crew/users');
         }
     }
     $this->lens('crew/user_new', ['active_link' => 'bridge-link-admin-crew-users', 'user' => $user, 'groups' => $this->account->getGroupTree()]);
 }
All Usage Examples Of Airship\Cabin\Bridge\Blueprint\UserAccounts::createUser