diff options
author | Malf Furious <m@lfurio.us> | 2016-03-26 23:23:39 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2016-03-27 20:16:32 -0400 |
commit | 4fef70c3afd276c8509efdf06d41cedb467ababe (patch) | |
tree | fe6e56260b67729a973cc94926803d142a7a1041 /app/model/common.mod.php | |
parent | 99ec6644fc93ee4d6bd8569148de6a03d64f69cb (diff) | |
download | scrott-4fef70c3afd276c8509efdf06d41cedb467ababe.tar.gz scrott-4fef70c3afd276c8509efdf06d41cedb467ababe.zip |
Add form handler for setting modal, all users, create new user pane
This handler is requires admin status and allows you to create a new application user
Diffstat (limited to 'app/model/common.mod.php')
-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); + } } ?> |