profanity checking for user profile and account creation

This commit is contained in:
durn
2026-04-23 19:57:49 -06:00
parent 317d45bad3
commit e594eb909b
2 changed files with 86 additions and 2 deletions
@@ -8,6 +8,7 @@
<title>Create Thyme Crunch Account</title>
<link rel="stylesheet" th:href="@{css/create-account.css}">
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
<script th:src="@{/js/bad-words-list.js}"></script>
</head>
<body>
@@ -58,6 +59,28 @@
</html>
<script>
function isProfane(str) {
const lower = str.toLowerCase();
return bannedWords.some(word => lower.includes(word));
}
function showError(input, message) {
input.classList.add('invalid');
let error = input.parentElement.querySelector('.error-message');
if (!error) {
error = document.createElement('p');
error.className = 'error-message';
error.style.color = 'red';
error.style.fontSize = '0.9em';
error.style.marginTop = '6px';
input.parentElement.appendChild(error);
}
error.textContent = message;
}
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("createUserForm");
@@ -68,9 +91,10 @@
function checkPasswords() {
if (confirmPasswordField.value === "") {
confirmPasswordField.classList.remove("invalid");
passwordError.textContent = "";
passwordError.textContent = "Password cannot be blank";
return;
}
if (passwordField.value !== confirmPasswordField.value) {
confirmPasswordField.classList.add("invalid");
@@ -89,12 +113,21 @@
const password = passwordField.value;
const confirmPassword = confirmPasswordField.value;
const name = document.getElementById("username").value;
const email = document.getElementById("email").value;
if (password !== confirmPassword) {
confirmPasswordField.classList.add("invalid");
passwordError.textContent = "Passwords do not match.";
return;
}
if (isProfane(document.getElementById("username").value)) {
showError(username, 'Username contains inappropriate language');
return;
}
const userData = {
username: document.getElementById("username").value,