From f4c10ec42537241fb77c93fa0eb1e31824c3aa73 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 25 Mar 2017 21:19:09 -0400 Subject: Add function user::initNew() --- app/class/user.class.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'app/class') 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 @@ -173,6 +173,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 */ -- cgit v1.2.3