Refactor admin panel: enhance user management and security features
- Added role-based access control for user management links in admin navigation. - Improved user account display with a dedicated account link. - Implemented form submission confirmation for delete actions in the admin interface. - Introduced a password visibility toggle on the login page. - Added login throttling to prevent brute-force attacks, recording failed attempts. - Created a CLI script for creating an admin user, replacing the previous hardcoded admin credentials. - Updated database schema to support login attempt tracking. - Enhanced user editing functionality, allowing role changes with restrictions. - Improved modal handling for user actions, ensuring better focus management. - Added styles for new account management page and improved modal transitions.
This commit is contained in:
1 parent
91ec95a4a9
commit
242c5165e1
21 files changed
+669
-77
No files matched your search
@@ -0,0 +1 @@
|
||||
Require all denied
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* CLI-only: create an admin account.
|
||||
*
|
||||
* Replaces the old admin/password seed in inc/db.php. Run inside the
|
||||
* container as www-data, so a newly created fitz.sqlite isn't owned by root:
|
||||
* docker exec -it -u www-data the-old-fitz php /var/www/html/bin/create-user.php
|
||||
*/
|
||||
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
http_response_code(404);
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../inc/users.php';
|
||||
|
||||
function prompt(string $label, bool $hidden = false): string {
|
||||
fwrite(STDOUT, $label);
|
||||
if ($hidden) {
|
||||
shell_exec('stty -echo');
|
||||
}
|
||||
$value = fgets(STDIN);
|
||||
if ($hidden) {
|
||||
shell_exec('stty echo');
|
||||
fwrite(STDOUT, PHP_EOL);
|
||||
}
|
||||
return trim((string) $value);
|
||||
}
|
||||
|
||||
$username = prompt('Username: ');
|
||||
if ($username === '') {
|
||||
fwrite(STDERR, "Username is required.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (username_exists($username)) {
|
||||
fwrite(STDERR, "User '$username' already exists.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$password = prompt('Password (' . MIN_PASSWORD_LENGTH . '+ chars): ', true);
|
||||
if (strlen($password) < MIN_PASSWORD_LENGTH) {
|
||||
fwrite(STDERR, 'Password must be at least ' . MIN_PASSWORD_LENGTH . " characters.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (prompt('Confirm password: ', true) !== $password) {
|
||||
fwrite(STDERR, "Passwords don't match.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$id = create_user($username, $password, 'admin');
|
||||
fwrite(STDOUT, "Created admin '$username' (id $id).\n");
|
||||
Reference in new issue
Block a user