diff options
| author | Malf Furious <m@lfurio.us> | 2017-03-25 21:19:09 -0400 | 
|---|---|---|
| committer | Malf Furious <m@lfurio.us> | 2017-03-25 21:19:09 -0400 | 
| commit | f4c10ec42537241fb77c93fa0eb1e31824c3aa73 (patch) | |
| tree | cf2033106a0ee2b95cb113663c9df9bca7a87366 | |
| parent | ea46bd0a4a040040c9cadd45441089bce9769bea (diff) | |
| download | scrott-f4c10ec42537241fb77c93fa0eb1e31824c3aa73.tar.gz scrott-f4c10ec42537241fb77c93fa0eb1e31824c3aa73.zip | |
Add function user::initNew()
| -rw-r--r-- | app/class/user.class.php | 25 | 
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 | 
