Skip to content

Commit

Permalink
Add error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludy87 committed Mar 4, 2024
1 parent 74bbc5a commit febad34
Show file tree
Hide file tree
Showing 29 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,22 @@ public RedirectView saveUser(

@PreAuthorize("hasRole('ROLE_ADMIN')")
@PostMapping("/admin/deleteUser/{username}")
public String deleteUser(@PathVariable String username, Authentication authentication) {
public RedirectView deleteUser(@PathVariable String username, Authentication authentication) {

if (!userService.usernameExists(username)) {
return new RedirectView("/addUsers?messageType=deleteUsernameExists");
}

// Get the currently authenticated username
String currentUsername = authentication.getName();

// Check if the provided username matches the current session's username
if (currentUsername.equals(username)) {
throw new IllegalArgumentException("Cannot delete currently logined in user.");
return new RedirectView("/addUsers?messageType=deleteCurrentUser");
}
invalidateUserSessions(username);
userService.deleteUser(username);
return "redirect:/addUsers";
return new RedirectView("/addUsers");
}

@Autowired private SessionRegistry sessionRegistry;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_ar_AR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=لا يمكن حذف المستخدم الذي قام بتسجيل الدخول حاليًا.
deleteUsernameExistsMessage=اسم المستخدم غير موجود ولا يمكن حذفه.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_bg_BG.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Потребителят не е автентикира
userNotFoundMessage=Потребителят не е намерен
incorrectPasswordMessage=Текущата парола е неправилна.
usernameExistsMessage=Новият потребител вече съществува.
deleteCurrentUserMessage=Не може да се изтрие влезлият в момента потребител.
deleteUsernameExistsMessage=Потребителското име не съществува и не може да бъде изтрито.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_ca_CA.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=No es pot suprimir l'usuari connectat actualment.
deleteUsernameExistsMessage=El nom d'usuari no existeix i no es pot suprimir.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Benutzer nicht authentifiziert.
userNotFoundMessage=Benutzer nicht gefunden.
incorrectPasswordMessage=Das Passwort ist falsch.
usernameExistsMessage=Neuer Benutzername existiert bereits.
deleteCurrentUserMessage=Der aktuell angemeldete Benutzer kann nicht gelöscht werden.
deleteUsernameExistsMessage=Der Benutzername existiert nicht und kann nicht gelöscht werden.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_el_GR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=\u039F \u03C7\u03C1\u03AE\u03C3\u03C4\u03B7\u03C2 \u03B4
userNotFoundMessage=\u039F \u03C7\u03C1\u03AE\u03C3\u03C4\u03B7\u03C2 \u03B4\u03B5\u03BD \u03B2\u03C1\u03AD\u03B8\u03B7\u03BA\u03B5.
incorrectPasswordMessage=\u039F \u03C4\u03C1\u03AD\u03C7\u03C9\u03BD \u03BA\u03C9\u03B4\u03B9\u03BA\u03CC\u03C2 \u03C0\u03C1\u03CC\u03C3\u03B2\u03B1\u03C3\u03B7\u03C2 \u03B5\u03AF\u03BD\u03B1\u03B9 \u03BB\u03B1\u03BD\u03B8\u03B1\u03C3\u03BC\u03AD\u03BD\u03BF\u03C2.
usernameExistsMessage=\u03A4\u03BF \u03BD\u03AD\u03BF \u03CC\u03BD\u03BF\u03BC\u03B1 \u03C7\u03C1\u03AE\u03C3\u03C4\u03B7 \u03C5\u03C0\u03AC\u03C1\u03C7\u03B5\u03B9 \u03AE\u03B4\u03B7.
deleteCurrentUserMessage=Δεν είναι δυνατή η διαγραφή του τρέχοντος συνδεδεμένου χρήστη.
deleteUsernameExistsMessage=Το όνομα χρήστη δεν υπάρχει και δεν μπορεί να διαγραφεί.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_en_GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Cannot delete currently logged in user.
deleteUsernameExistsMessage=The username does not exist and cannot be deleted.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Cannot delete currently logged in user.
deleteUsernameExistsMessage=The username does not exist and cannot be deleted.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_es_ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Usuario no autentificado.
userNotFoundMessage=Usuario no encontrado.
incorrectPasswordMessage=La contraseña actual no es correcta.
usernameExistsMessage=El nuevo nombre de usuario está en uso.
deleteCurrentUserMessage=No se puede eliminar el usuario actualmente conectado.
deleteUsernameExistsMessage=El nombre de usuario no existe y no se puede eliminar.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_eu_ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Ezin da ezabatu saioa hasita dagoen erabiltzailea.
deleteUsernameExistsMessage=Erabiltzaile izena ez dago eta ezin da ezabatu.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_fr_FR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Utilisateur non authentifié.
userNotFoundMessage=Utilisateur non trouvé.
incorrectPasswordMessage=Le mot de passe actuel est incorrect.
usernameExistsMessage=Le nouveau nom d\u2019utilisateur existe déjà.
deleteCurrentUserMessage=Impossible de supprimer l'utilisateur actuellement connecté.
deleteUsernameExistsMessage=Le nom d'utilisateur n'existe pas et ne peut pas être supprimé.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_hi_IN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=उपयोगकर्ता प्रमाणित
userNotFoundMessage=उपयोगकर्ता नहीं मिला।
incorrectPasswordMessage=वर्तमान पासवर्ड गलत है।
usernameExistsMessage=नया उपयोगकर्ता नाम पहले से मौजूद है।
deleteCurrentUserMessage=वर्तमान में लॉग इन उपयोगकर्ता को हटाया नहीं जा सकता.
deleteUsernameExistsMessage=उपयोगकर्ता नाम मौजूद नहीं है और उसे हटाया नहीं जा सकता.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_hu_HU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Felhasználó nincs hitelesítve.
userNotFoundMessage=A felhasználó nem található.
incorrectPasswordMessage=A jelenlegi jelszó helytelen.
usernameExistsMessage=Az új felhasználónév már létezik.
deleteCurrentUserMessage=A jelenleg bejelentkezett felhasználót nem lehet törölni.
deleteUsernameExistsMessage=A felhasználónév nem létezik és nem törölhető.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_id_ID.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Pengguna tidak ter-autentikasi.
userNotFoundMessage=Pengguna tidak ditemukan.
incorrectPasswordMessage=Kata sandi saat ini salah.
usernameExistsMessage=Nama pengguna baru sudah ada.
deleteCurrentUserMessage=Tidak dapat menghapus pengguna yang sedang login.
deleteUsernameExistsMessage=Nama pengguna tidak ada dan tidak dapat dihapus.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_it_IT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Utente non autenticato.
userNotFoundMessage=Utente non trovato.
incorrectPasswordMessage=La password attuale non è corretta.
usernameExistsMessage=Il nuovo nome utente esiste già.
deleteCurrentUserMessage=Impossibile eliminare l'utente attualmente connesso.
deleteUsernameExistsMessage=Il nome utente non esiste e non può essere eliminato.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_ja_JP.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=ユーザーが認証されていません。
userNotFoundMessage=ユーザーが見つかりません。
incorrectPasswordMessage=現在のパスワードが正しくありません。
usernameExistsMessage=新しいユーザー名はすでに存在します。
deleteCurrentUserMessage=現在ログインしているユーザーは削除できません。
deleteUsernameExistsMessage=ユーザー名は存在しないため、削除できません。


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_ko_KR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=사용자를 찾을 수 없습니다.
incorrectPasswordMessage=현재 비밀번호가 틀립니다.
usernameExistsMessage=새 사용자명이 이미 존재합니다.
deleteCurrentUserMessage=현재 로그인된 사용자를 삭제할 수 없습니다.
deleteUsernameExistsMessage=사용자 이름이 존재하지 않으며 삭제할 수 없습니다.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_nl_NL.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Gebruiker niet ingelogd.
userNotFoundMessage=Gebruiker niet gevonden.
incorrectPasswordMessage=Huidige wachtwoord is onjuist.
usernameExistsMessage=Nieuwe gebruikersnaam bestaat al.
deleteCurrentUserMessage=Kan momenteel ingelogde gebruiker niet verwijderen.
deleteUsernameExistsMessage=De gebruikersnaam bestaat niet en kan niet worden verwijderd.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_pl_PL.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Nie można usunąć aktualnie zalogowanego użytkownika.
deleteUsernameExistsMessage=Nazwa użytkownika nie istnieje i nie można jej usunąć.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Não é possível excluir o usuário conectado no momento.
deleteUsernameExistsMessage=O nome de usuário não existe e não pode ser excluído.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_pt_PT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ notAuthenticatedMessage=Utilizador não autenticado.
userNotFoundMessage=Utilizador inexistente.
incorrectPasswordMessage=Senha incorreta.
usernameExistsMessage=Esse utilizador já existe.
deleteCurrentUserMessage=Não é possível excluir o usuário conectado no momento.
deleteUsernameExistsMessage=O nome de usuário não existe e não pode ser excluído.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_ro_RO.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Nu se poate șterge utilizatorul conectat în prezent.
deleteUsernameExistsMessage=Numele de utilizator nu există și nu poate fi șters.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_ru_RU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Невозможно удалить вошедшего в систему пользователя.
deleteUsernameExistsMessage=Имя пользователя не существует и не может быть удалено.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_sr_LATN_RS.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Korisnik nije autentifikovan.
userNotFoundMessage=Korisnik nije pronađen.
incorrectPasswordMessage=Trenutna šifra je netačna.
usernameExistsMessage=Novi korisnik već postoji
deleteCurrentUserMessage=Није могуће избрисати тренутно пријављеног корисника.
deleteUsernameExistsMessage=Корисничко име не постоји и не може се избрисати.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_sv_SE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
usernameExistsMessage=New Username already exists.
deleteCurrentUserMessage=Kan inte ta bort inloggad användare.
deleteUsernameExistsMessage=Användarnamnet finns inte och kan inte raderas.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_tr_TR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=Kullanıcı doğrulanmadı.
userNotFoundMessage=Kullanıcı bulunamadı.
incorrectPasswordMessage=Mevcut şifre yanlış.
usernameExistsMessage=Yeni Kullanıcı Adı zaten var.
deleteCurrentUserMessage=Şu anda oturum açmış olan kullanıcı silinemiyor.
deleteUsernameExistsMessage=Kullanıcı adı mevcut değil ve silinemez.


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=用户未经过身份验证。
userNotFoundMessage=未找到用户。
incorrectPasswordMessage=当前密码不正确。
usernameExistsMessage=新用户名已存在。
deleteCurrentUserMessage=无法删除当前登录的用户。
deleteUsernameExistsMessage=用户名不存在,无法删除。


###############
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_zh_TW.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ notAuthenticatedMessage=使用者未認證。
userNotFoundMessage=找不到使用者。
incorrectPasswordMessage=目前密碼不正確。
usernameExistsMessage=新使用者名稱已存在。
deleteCurrentUserMessage=無法刪除目前登入的使用者。
deleteUsernameExistsMessage=使用者名稱不存在,無法刪除。


###############
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/templates/addUsers.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

<!-- User Settings Title -->
<h2 class="text-center" th:text="#{adminUserSettings.header}">Admin User Control Settings</h2>
<div th:if="${param.messageType != null and param.messageType.size() > 0 and (param.messageType[0] == 'deleteCurrentUser' or param.messageType[0] == 'deleteUsernameExists')}" class="alert alert-danger">
<span th:if="${param.messageType[0] == 'deleteCurrentUser'}" th:text="#{deleteCurrentUserMessage}">Cannot delete currently logged in user.</span>
<span th:if="${param.messageType[0] == 'deleteUsernameExists'}" th:text="#{deleteUsernameExistsMessage}">The username does not exist and cannot be deleted.</span>
</div>
<table class="table">
<thead>
<tr>
Expand Down

0 comments on commit febad34

Please sign in to comment.