From d8055192991ac8504e48c137038879790c762d2d Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 26 Jul 2016 14:27:14 +0200 Subject: Adding and deleting users --- classes/user.php | 19 +++++ include/clients-overview.php | 2 +- include/settings.php | 170 ++++++++++++++++++++++++++++++++++++------- include/users-new.php | 42 +++++++++++ index.php | 73 ++++++++++--------- install/index.php | 2 +- login-ajax.php | 7 +- login.php | 11 +++ 8 files changed, 262 insertions(+), 64 deletions(-) create mode 100644 include/users-new.php diff --git a/classes/user.php b/classes/user.php index e50f773..750e8bb 100644 --- a/classes/user.php +++ b/classes/user.php @@ -33,6 +33,16 @@ class user { */ protected $pdo, $id, $username, $password; + /** + * Generate a random password + * + * @return string The password + */ + public static function generateRandomPassword() { + return preg_replace('/[^\w]/', '', + base64_encode(bin2hex(openssl_random_pseudo_bytes(4)))); + } + /** * Hash a password * @@ -140,6 +150,15 @@ class user { // Other functions //------------------------------------------------------------------------------ + /** + * Check if a user has administrator rights + * + * @return bool True iff the user has administrator rights + */ + public function isAdmin() { + return $this->getId() == 1; + } + /** * Verify a password * diff --git a/include/clients-overview.php b/include/clients-overview.php index 7ce45a6..fc2c3a0 100644 --- a/include/clients-overview.php +++ b/include/clients-overview.php @@ -70,7 +70,7 @@ require_once('./login.php');
$pass
. Refresh the page.";
+ }
+} catch (PDOException $e) {
+ $response->success = false;
+ $response->message = "The user could not be created due to a PDO error ({$e->getMessage()}).";
+}
+echo $response->getJson();
diff --git a/index.php b/index.php
index 3c8d842..a689f7e 100644
--- a/index.php
+++ b/index.php
@@ -1,31 +1,31 @@
.
+ * along with this program. If not, see You need to be an administrator to access this page.
+