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 --- include/clients-overview.php | 2 +- include/settings.php | 170 ++++++++++++++++++++++++++++++++++++------- include/users-new.php | 42 +++++++++++ 3 files changed, 188 insertions(+), 26 deletions(-) create mode 100644 include/users-new.php (limited to 'include') 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');
diff --git a/include/settings.php b/include/settings.php index 7dfbbc3..896152c 100644 --- a/include/settings.php +++ b/include/settings.php @@ -35,43 +35,163 @@ require('./header.php'); + isAdmin()) { + try { + $user = new user($_pdo, $_GET['delete_user']); + if ($user->delete()) { + echo "
The user with username {$user->getUsername()} has been removed.
"; + } else { + echo "
The user with username {$user->getUsername()} could not be removed.
"; + } + } catch (PDOException $e) { + echo "
The user with username {$user->getUsername()} could not be removed due to a PDO error.
"; + } catch (Exception $e) { + echo "
The user with id {$_GET['delete_user']} could not be found.
"; + } + } + ?> +
Password
-
- The passwords don\'t match.
'; - } else if (!$_user->verifyPassword($_POST['password_current'])) { - echo '
The current password was incorrect.
'; - } else { - try { - $_user->setPassword($_POST['password_update']); - echo '
Password successfully changed.
'; - } catch (PDOException $e) { - echo '
An unknown error occurred.
'; - } +
+ The passwords don\'t match.
'; + } else if (!$_user->verifyPassword($_POST['password_current'])) { + echo '
The current password was incorrect.
'; + } else { + try { + $_user->setPassword($_POST['password_update']); + echo '
Password successfully changed.
'; + } catch (PDOException $e) { + echo '
An unknown error occurred.
'; } } - ?> -
-
- -
-
- -
+ } + ?> + +
+ +
+
+ +
+
+ +
+ +
+
+
+
+ +
+
+
Users
+
+ + + + + + isAdmin()) echo ''; ?> + + + + getId()}' + data-mixer-order-username='{$user->getUsername()}'> + + "; + if ($_user->isAdmin()) { + if ($user->getId() == $_user->getId()) { + echo ""; + } else { + echo ""; + } + } + echo ""; + } + ?> + +
#UsernameTools
{$user->getId()}{$user->getUsername()} + + + +
+
+
+
+ + isAdmin()) : ?> +
+
+
Create new
+
+
+
- + +
- +
+
- + 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 @@ +. + */ + +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 '{$user->getUsername()}' has been created with password $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(); -- cgit v1.2.3