diff options
Diffstat (limited to '')
| -rw-r--r-- | app/model/common.mod.php | 56 | 
1 files changed, 54 insertions, 2 deletions
| diff --git a/app/model/common.mod.php b/app/model/common.mod.php index 1398598..1d5f036 100644 --- a/app/model/common.mod.php +++ b/app/model/common.mod.php @@ -38,8 +38,9 @@ class CommonModel extends MasterModel      {          switch ($input['action'])          { -            case "common-setting-user":  $this->saveSettingUser($input);  break; -            case "common-setting-admin": $this->saveSettingAdmin($input); break; +            case "common-setting-user":             $this->saveSettingUser($input);            break; +            case "common-setting-admin":            $this->saveSettingAdmin($input);           break; +            case "common-setting-allusers-adduser": $this->saveSettingAllusersAdduser($input); break;          }      } @@ -128,6 +129,57 @@ class CommonModel extends MasterModel          Setting::settSSL($form->settSSL);          Setting::allowPublicSignup($form->allowPublicSignup);      } + +    /* +     * Allow an admin to create a new user account +     */ +    function saveSettingAllusersAdduser($input) +    { +        $form = new Form(); +        $form->field_text("username"); +        $form->field_text("password", null, false); +        $form->field_text("cPassword", null, false); +        $form->field_bool("admin"); +        $form->field_text("alias", "", false); +        $form->field_text("email", "", false); + +        if (!$form->populate($input)) +        { +            $this->logFormErrors($form); +            return; +        } + +        $user = $this->getCurrentUser(); + +        if (!$user || $user->admin == 0) +        { +            $this->logError("Admin permissions required"); +            return; +        } + +        if ($form->password != $form->cPassword) +        { +            $this->logError("Passwords do not match"); +            return; +        } + +        $user = new User(); + +        if (!$user->createNewUser($form->username, $form->password)) +        { +            $this->logError("Username " . $form->username . " is not available"); +            return; +        } + +        if ($form->admin) +            $user->admin = 1; + +        $user->alias = $form->alias; +        $user->setEmail($form->email); +        $user->saveObj(); + +        $this->logNotice("Created new user " . $form->username); +    }  }  ?> | 
