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

add password validator (#1418)

This commit is contained in:
Ludy 2024-06-08 23:36:23 +02:00 committed by GitHub
parent 517e54517c
commit 7a15930453
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,7 @@
<!-- Change Username Form --> <!-- Change Username Form -->
<h4 th:text="#{changeCreds.changePassword}">Change password</h4> <h4 th:text="#{changeCreds.changePassword}">Change password</h4>
<form action="api/v1/user/change-password-on-login" method="post"> <form action="api/v1/user/change-password-on-login" method="post" id="formsavechangecreds">
<div class="mb-3"> <div class="mb-3">
<label for="currentPassword" th:text="#{changeCreds.oldPassword}">Old Password</label> <label for="currentPassword" th:text="#{changeCreds.oldPassword}">Old Password</label>
<input type="password" class="form-control" name="currentPassword" id="currentPassword" th:placeholder="#{changeCreds.oldPassword}"> <input type="password" class="form-control" name="currentPassword" id="currentPassword" th:placeholder="#{changeCreds.oldPassword}">
@ -41,20 +41,39 @@
<input type="password" class="form-control" name="confirmNewPassword" id="confirmNewPassword" th:placeholder="#{account.confirmNewPassword}"> <input type="password" class="form-control" name="confirmNewPassword" id="confirmNewPassword" th:placeholder="#{account.confirmNewPassword}">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<span id="confirmPasswordError" style="display: none;" th:text="#{confirmPasswordErrorMessage}">New Password and Confirm New Password must match.</span>
<button type="submit" class="btn btn-primary" th:text="#{changeCreds.submit}">Change credentials!</button> <button type="submit" class="btn btn-primary" th:text="#{changeCreds.submit}">Change credentials!</button>
</div> </div>
</form> </form>
<script> <script th:inline="javascript">
document.addEventListener("DOMContentLoaded", function() { $(document).ready(function() {
const form = document.querySelector('form[action="api/v1/user/change-password-on-login"]'); $.validator.addMethod("passwordMatch", function(value, element) {
return $('#newPassword').val() === $('#confirmNewPassword').val();
form.addEventListener('submit', function(event) { }, /*[[#{confirmPasswordErrorMessage}]]*/ "New Password and Confirm New Password must match.");
const newPassword = document.getElementById('newPassword').value; $('#formsavechangecreds').validate({
const confirmNewPassword = document.getElementById('confirmNewPassword').value; rules: {
currentPassword: {
if (newPassword !== confirmNewPassword) { required: true
alert('New Password and Confirm New Password must match.'); },
event.preventDefault(); // Prevent form submission newPassword: {
required: true
},
confirmNewPassword: {
required: true,
passwordMatch: true
},
errorPlacement: function(error, element) {
if ($(element).attr("name") === "newPassword" || $(element).attr("name") === "confirmNewPassword") {
$("#confirmPasswordError").text(error.text()).show();
} else {
error.insertAfter(element);
}
},
success: function(label, element) {
if ($(element).attr("name") === "newPassword" || $(element).attr("name") === "confirmNewPassword") {
$("#confirmPasswordError").hide();
}
}
} }
}); });
}); });