Fixed user update screen

This commit is contained in:
Pinga 2025-02-06 11:38:15 +02:00
parent 88277bdc95
commit 843451406e
2 changed files with 26 additions and 1 deletions

View file

@ -305,12 +305,36 @@ class UsersController extends Controller
return $response->withHeader('Location', '/user/update/'.$old_username)->withStatus(302);
}
// Check if username already exists (excluding the current user)
if ($username) {
$existingUsername = $db->selectValue('SELECT COUNT(*) FROM users WHERE username = ? AND username != ?', [$username, $old_username]);
if ($existingUsername > 0) {
$errors[] = 'Username already exists';
}
}
// Check if email already exists (excluding the current user)
if ($email) {
$existingEmail = $db->selectValue('SELECT COUNT(*) FROM users WHERE email = ? AND username != ?', [$email, $old_username]);
if ($existingEmail > 0) {
$errors[] = 'Email already exists';
}
}
// Handle errors
if (!empty($errors)) {
foreach ($errors as $error) {
$this->container->get('flash')->addMessage('error', $error);
}
return $response->withHeader('Location', '/user/update/' . $old_username)->withStatus(302);
}
if (empty($email)) {
$this->container->get('flash')->addMessage('error', 'No email specified for update');
return $response->withHeader('Location', '/user/update/'.$old_username)->withStatus(302);
}
if (in_array($roles_mask, [0, '0'], true)) {
if (!$roles_mask) {
$this->container->get('flash')->addMessage('error', 'No roles assigned. Please assign at least one role');
return $response->withHeader('Location', '/user/update/' . $old_username)->withStatus(302);
}

View file

@ -136,6 +136,7 @@
<div class="mb-3">
<label class="form-label">{{ __('Roles') }}</label>
<span class="badge bg-blue-lt">{{ __('Registrar Administrator') }}</span>
<input type="hidden" name="roles_mask" value="4">
</div>
</div>
{% else %}