mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
profanity checking for user profile and account creation
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<title>My Profile - Thyme Crunch</title>
|
||||
<link rel="stylesheet" th:href="@{css/my-profile.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>
|
||||
|
||||
@@ -88,7 +89,7 @@
|
||||
<label for="bio">Bio</label>
|
||||
<textarea id="bio" th:field="*{bio}" rows="6" maxlength="1000"></textarea>
|
||||
</div>
|
||||
<button type="submit">Save</button>
|
||||
<button type="submit" value='submit request' onclick='return btnClick();'>Save</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
@@ -97,6 +98,56 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function isProfane(str) {
|
||||
const lower = str.toLowerCase();
|
||||
return bannedWords.some(word => lower.includes(word));
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function btnClick() {
|
||||
const displayNameEl = document.getElementById('displayName');
|
||||
const bioEl = document.getElementById('bio');
|
||||
|
||||
clearError(displayNameEl);
|
||||
clearError(bioEl);
|
||||
|
||||
if (isProfane(displayNameEl.value)) {
|
||||
showError(displayNameEl, "Display name contains inappropriate language.");
|
||||
return false;
|
||||
}
|
||||
if (isProfane(bioEl.value)) {
|
||||
showError(bioEl, "Bio contains inappropriate language.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function clearError(input) {
|
||||
input.classList.remove('invalid');
|
||||
const error = input.parentElement.querySelector('.error-message');
|
||||
if (error) error.remove();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
// For cost display <!-- Cost change -->
|
||||
function renderCost(cost) {
|
||||
const num = parseInt(cost, 10);
|
||||
|
||||
Reference in New Issue
Block a user