From 5528a63784882d11d02f5f8ce568997f751b28ec Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 26 Jul 2016 13:20:51 +0200 Subject: Option to add first user during installation --- classes/BusinessAdmin.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'classes') diff --git a/classes/BusinessAdmin.php b/classes/BusinessAdmin.php index ce332ee..347c9c6 100644 --- a/classes/BusinessAdmin.php +++ b/classes/BusinessAdmin.php @@ -337,6 +337,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 * -- cgit v1.2.3