/** * Create an admin account. Will prompt for email address and password. */ public function executeCreateAdmin() { do { if (!empty($email_input)) { $this->out('That is not a valid email.'); } $email_input = $this->readline('Email: '); } while (!($email = Scrub::email($email_input))); do { $password = $this->readline('Password: '******'success']) { $user = UserModel::loadById($res['data']); $user->setType(UserModel::TYPE_ADMIN); } else { $this->out('Failed to create user.'); } }
/** * Insert a new user if he doesn't already exist. * * @param string $email * The new email * @param string $pass * The new password * @param string $first_name * The first name * @param string $last_name * The last name. * * @return integer * The new user's ID. */ protected static function insertUser($email, $pass = NULL, $first_name = '', $last_name = '') { $user_details = array('email' => Scrub::email(strtolower($email)), 'first' => $first_name, 'last' => $last_name, 'created' => Time::today(), 'confirmed' => static::requiresConfirmation() ? static::UNCONFIRMED : static::CONFIRMED, 'type' => 0, 'referrer' => 0); if ($pass) { $salt = static::getSalt(); $user_details['password'] = static::passHash($pass, $salt); $user_details['salt'] = bin2hex($salt); $user_details['registered'] = Time::today(); } return Database::getInstance()->insert('user', $user_details); }