1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-09-29 16:10:11 +02:00

dipslay stuf

This commit is contained in:
Anthony Stirling 2023-09-04 00:12:27 +01:00
parent 0bb2df135b
commit fd08513212
7 changed files with 85 additions and 87 deletions

View File

@ -13,7 +13,7 @@ import jakarta.servlet.http.HttpServletResponse;
public class CleanUrlInterceptor implements HandlerInterceptor {
private static final List<String> ALLOWED_PARAMS = Arrays.asList("lang", "endpoint", "endpoints", "logout", "error", "file");
private static final List<String> ALLOWED_PARAMS = Arrays.asList("lang", "endpoint", "endpoints", "logout", "error", "file", "messageType");
@Override
@ -32,7 +32,6 @@ public class CleanUrlInterceptor implements HandlerInterceptor {
if (keyValue.length != 2) {
continue;
}
if (ALLOWED_PARAMS.contains(keyValue[0])) {
parameters.put(keyValue[0], keyValue[1]);
}

View File

@ -39,5 +39,4 @@ public class ConfigInitializer implements ApplicationContextInitializer<Configur
}
}
}
}

View File

@ -50,28 +50,26 @@ public class UserController {
HttpServletResponse response,
RedirectAttributes redirectAttributes) {
if (principal == null) {
redirectAttributes.addFlashAttribute("notAuthenticated", true);
return new RedirectView("/change-creds");
return new RedirectView("/change-creds?messageType=notAuthenticated");
}
Optional<User> userOpt = userService.findByUsername(principal.getName());
if (userOpt == null || userOpt.isEmpty()) {
redirectAttributes.addFlashAttribute("userNotFound", true);
return new RedirectView("/change-creds");
return new RedirectView("/change-creds?messageType=userNotFound");
}
User user = userOpt.get();
if (!userService.isPasswordCorrect(user, currentPassword)) {
redirectAttributes.addFlashAttribute("incorrectPassword", true);
return new RedirectView("/change-creds");
return new RedirectView("/change-creds?messageType=incorrectPassword");
}
if (!user.getUsername().equals(newUsername) && userService.usernameExists(newUsername)) {
redirectAttributes.addFlashAttribute("usernameExists", true);
return new RedirectView("/change-creds");
return new RedirectView("/change-creds?messageType=usernameExists");
}
userService.changePassword(user, newPassword);
if(!user.getUsername().equals(newUsername)) {
userService.changeUsername(user, newUsername);
@ -81,8 +79,7 @@ public class UserController {
// Logout using Spring's utility
new SecurityContextLogoutHandler().logout(request, response, null);
redirectAttributes.addFlashAttribute("credsUpdated", true);
return new RedirectView("/login");
return new RedirectView("/login?messageType=credsUpdated");
}
@ -95,35 +92,32 @@ public class UserController {
HttpServletResponse response,
RedirectAttributes redirectAttributes) {
if (principal == null) {
redirectAttributes.addFlashAttribute("notAuthenticated", true);
return new RedirectView("/account");
return new RedirectView("/account?messageType=notAuthenticated");
}
Optional<User> userOpt = userService.findByUsername(principal.getName());
if (userOpt == null || userOpt.isEmpty()) {
redirectAttributes.addFlashAttribute("userNotFound", true);
return new RedirectView("/account");
return new RedirectView("/account?messageType=userNotFound");
}
User user = userOpt.get();
if (!userService.isPasswordCorrect(user, currentPassword)) {
redirectAttributes.addFlashAttribute("incorrectPassword", true);
return new RedirectView("/account");
return new RedirectView("/account?messageType=incorrectPassword");
}
if (userService.usernameExists(newUsername)) {
redirectAttributes.addFlashAttribute("usernameExists", true);
return new RedirectView("/account");
if (!user.getUsername().equals(newUsername) && userService.usernameExists(newUsername)) {
return new RedirectView("/account?messageType=usernameExists");
}
userService.changeUsername(user, newUsername);
// Logout using Spring's utility
new SecurityContextLogoutHandler().logout(request, response, null);
redirectAttributes.addFlashAttribute("message", "Username updated successfully.");
return new RedirectView("/login");
return new RedirectView("/login?messageType=credsUpdated");
}
@PostMapping("/change-password")
@ -134,21 +128,19 @@ public class UserController {
HttpServletResponse response,
RedirectAttributes redirectAttributes) {
if (principal == null) {
redirectAttributes.addFlashAttribute("notAuthenticated", true);
return new RedirectView("/account");
return new RedirectView("/account?messageType=notAuthenticated");
}
Optional<User> userOpt = userService.findByUsername(principal.getName());
if (userOpt == null || userOpt.isEmpty()) {
redirectAttributes.addFlashAttribute("userNotFound", true);
return new RedirectView("/account");
return new RedirectView("/account?messageType=userNotFound");
}
User user = userOpt.get();
if (!userService.isPasswordCorrect(user, currentPassword)) {
redirectAttributes.addFlashAttribute("incorrectPassword", true);
return new RedirectView("/account");
return new RedirectView("/account?messageType=incorrectPassword");
}
userService.changePassword(user, newPassword);
@ -156,8 +148,7 @@ public class UserController {
// Logout using Spring's utility
new SecurityContextLogoutHandler().logout(request, response, null);
redirectAttributes.addFlashAttribute("message", "Password updated successfully.");
return new RedirectView("/login");
return new RedirectView("/login?messageType=credsUpdated");
}

View File

@ -42,8 +42,8 @@ red=Red
green=Green
blue=Blue
custom=Custom...
changedCredsMessage=Credentials changed!
changedCredsMessage=Credentials changed!
notAuthenticatedMessage=User not authenticated.
userNotFoundMessage=User not found.
incorrectPasswordMessage=Current password is incorrect.
@ -75,6 +75,19 @@ settings.zipThreshold=Zip files when the number of downloaded files exceeds
settings.signOut=Sign Out
settings.accountSettings=Account Settings
changeCreds.title=Change Credentials
changeCreds.header=Update Your Account Details
changeCreds.changeUserAndPassword=You are using default login credentials. Please enter a new password (and username if wanted)
changeCreds.newUsername=New Username
changeCreds.oldPassword=Current Password
changeCreds.newPassword=New Password
changeCreds.confirmNewPassword=Confirm New Password
changeCreds.submit=Submit Changes
account.title=Account Settings
account.accountSettings=Account Settings
account.adminSettings=Admin Settings - View and Add Users

View File

@ -16,22 +16,24 @@
<!-- User Settings Title -->
<h2 class="text-center" th:text="#{account.accountSettings}">User Settings</h2>
<hr>
<div th:if="${notAuthenticated}" class="alert alert-danger" role="alert">
User not authenticated.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'notAuthenticated'}" class="alert alert-danger">
<span th:text="#{notAuthenticatedMessage}">Default message if not found</span>
</div>
<div th:if="${userNotFound}" class="alert alert-danger" role="alert">
User not found.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'userNotFound'}" class="alert alert-danger">
<span th:text="#{userNotFoundMessage}">Default message if not found</span>
</div>
<div th:if="${incorrectPassword}" class="alert alert-danger" role="alert">
Current password is incorrect.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'incorrectPassword'}" class="alert alert-danger">
<span th:text="#{incorrectPasswordMessage}">Default message if not found</span>
</div>
<div th:if="${usernameExists}" class="alert alert-danger" role="alert">
New username already exists.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'usernameExists'}" class="alert alert-danger">
<span th:text="#{usernameExistsMessage}">Default message if not found</span>
</div>
<!-- At the top of the user settings -->
<h3 class="text-center"><span th:text="#{welcome} + ' ' + ${username}">User</span>!</h3>

View File

@ -16,19 +16,19 @@
<!-- User Settings Title -->
<h2 class="text-center" th:text="#{changeCreds.header}">User Settings</h2>
<hr>
<div th:if="${notAuthenticated}" class="alert alert-danger" role="alert">
User not authenticated.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'notAuthenticated'}" class="alert alert-danger">
<span th:text="#{notAuthenticatedMessage}">Default message if not found</span>
</div>
<div th:if="${userNotFound}" class="alert alert-danger" role="alert">
User not found.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'userNotFound'}" class="alert alert-danger">
<span th:text="#{userNotFoundMessage}">Default message if not found</span>
</div>
<div th:if="${incorrectPassword}" class="alert alert-danger" role="alert">
Current password is incorrect.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'incorrectPassword'}" class="alert alert-danger">
<span th:text="#{incorrectPasswordMessage}">Default message if not found</span>
</div>
<div th:if="${usernameExists}" class="alert alert-danger" role="alert">
New username already exists.
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'usernameExists'}" class="alert alert-danger">
<span th:text="#{usernameExistsMessage}">Default message if not found</span>
</div>
<div th:if="${changeCredsFlag}" class="alert alert-success" th:text="#{changeCredsMessage}"></div>
<!-- At the top of the user settings -->
<h3 class="text-center"><span th:text="#{welcome} + ' ' + ${username}">User</span>!</h3>

View File

@ -179,17 +179,10 @@ document.addEventListener('DOMContentLoaded', function() {
const urlParams = currentURL.searchParams;
const currentLangParam = urlParams.get('lang') || defaultLocale;
console.log("defaultLocale", defaultLocale);
console.log("storedLocale", storedLocale);
console.log("currentLangParam", currentLangParam);
if (defaultLocale !== storedLocale && currentLangParam !== storedLocale) {
console.log("currentLangParam", currentLangParam)
console.log("storedLocale", storedLocale)
urlParams.set('lang', storedLocale);
currentURL.search = urlParams.toString();
console.log("redirecting to", currentURL.toString());
window.location.href = currentURL.toString();
return;
}
@ -263,8 +256,9 @@ function handleDropdownItemClick(event) {
<div th:if="${logoutMessage}" class="alert alert-success"
th:text="${logoutMessage}"></div>
<div th:if="${param.messageType != null and param.messageType.size() > 0 and param.messageType[0] == 'credsUpdated'}" class="alert alert-success">
<span th:text="#{changedCredsMessage}">Default message if not found</span>
</div>
<form th:action="@{login}" method="post">
<img class="mb-4" src="favicon.svg" alt="" width="144" height="144">
<h1 class="h1 mb-3 fw-normal" th:text="${@appName}">Stirling-PDF</h1>