diff options
author | Camil Staps | 2016-07-26 13:20:51 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-26 13:20:51 +0200 |
commit | 5528a63784882d11d02f5f8ce568997f751b28ec (patch) | |
tree | 811043ecfe1030b4dc5cb41dc8eaebad2e8c98de /classes | |
parent | Added braintree (diff) |
Option to add first user during installation
Diffstat (limited to 'classes')
-rw-r--r-- | classes/BusinessAdmin.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/classes/BusinessAdmin.php b/classes/BusinessAdmin.php index ce332ee..347c9c6 100644 --- a/classes/BusinessAdmin.php +++ b/classes/BusinessAdmin.php @@ -338,6 +338,27 @@ class BusinessAdmin { } /** + * Create a new user + * + * @param PDO $pdo The database connection + * @param string $username The username for the new user + * @param string $password The password for the new user + * + * @throws PDOException If something went wrong with the database + * + * @return user|bool A new instance of the user object, or false on failure + */ + public static function createUser($pdo, $username, $password) { + $stmt = $pdo->prepare("INSERT INTO `".constants::db_prefix."user` (`username`, `password`) VALUES (?,?)"); + $stmt->execute([$username, user::hash($password)]); + if ($stmt->rowCount() == 1) { + return new user($pdo, $pdo->lastInsertId()); + } else { + return false; + } + } + + /** * Format a date nicely * * @todo implement $relatively = true |