summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-03-25 21:19:09 -0400
committerMalf Furious <m@lfurio.us>2017-03-25 21:19:09 -0400
commitf4c10ec42537241fb77c93fa0eb1e31824c3aa73 (patch)
treecf2033106a0ee2b95cb113663c9df9bca7a87366 /app
parentea46bd0a4a040040c9cadd45441089bce9769bea (diff)
downloadscrott-f4c10ec42537241fb77c93fa0eb1e31824c3aa73.tar.gz
scrott-f4c10ec42537241fb77c93fa0eb1e31824c3aa73.zip
Add function user::initNew()
Diffstat (limited to '')
-rw-r--r--app/class/user.class.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/class/user.class.php b/app/class/user.class.php
index 7defa8f..b0b3435 100644
--- a/app/class/user.class.php
+++ b/app/class/user.class.php
@@ -174,6 +174,31 @@ class user extends agent
}
/*
+ * Initialize a new user object with the given username and plain
+ * text password. This function returns NULL if $uname is already
+ * being used.
+ */
+ public static function initNew(string $uname, string $passwd) : ?user
+ {
+ if (self::getByUname($uname))
+ return NULL;
+
+ $user = new user();
+
+ /* if there exist no users already, make this new one an admin */
+ if (count(self::getAll_ordByUname()) == 0)
+ $user->admin = 1;
+
+ $user->name = $uname;
+ $user->objtype = "user";
+ $user->setPasswd($passwd);
+ $user->setEmail("");
+ $user->reg = 1;
+
+ return $user;
+ }
+
+ /*
* Get the salted and hashed form of a password
*/
private static function getAuth(string $passwd, string $salt) : string