diff options
author | Camil Staps | 2016-07-26 14:27:14 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-26 14:27:14 +0200 |
commit | d8055192991ac8504e48c137038879790c762d2d (patch) | |
tree | 0738603efca98c26d6d04cbd091898d4b6e9a34d /include/users-new.php | |
parent | Option to add first user during installation (diff) |
Adding and deleting users
Diffstat (limited to 'include/users-new.php')
-rw-r--r-- | include/users-new.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/include/users-new.php b/include/users-new.php new file mode 100644 index 0000000..5d86a83 --- /dev/null +++ b/include/users-new.php @@ -0,0 +1,42 @@ +<?php +/** + * BusinessAdmin: administrative software for small companies + * Copyright (C) 2015 Camil Staps (ViviSoft) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +define('REQUIRE_ADMIN', true); + +require_once('./conf.php'); +require_once('./login-ajax.php'); + +$response = new response(); + +try { + $pass = user::generateRandomPassword(); + $user = BusinessAdmin::createUser($_pdo, $_REQUEST['username'], $pass); + + if ($user === false) { + $response->success = false; + $response->message = "The user could not be created due to an error."; + } else { + $response->success = true; + $response->message = "User <i>'{$user->getUsername()}'</i> has been created with password <code>$pass</code>. <a class='alert-link' href='javascript:location.reload(true);'>Refresh the page</a>."; + } +} catch (PDOException $e) { + $response->success = false; + $response->message = "The user could not be created due to a PDO error ({$e->getMessage()})."; +} +echo $response->getJson(); |