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>
|
<title>Create Thyme Crunch Account</title>
|
||||||
<link rel="stylesheet" th:href="@{css/create-account.css}">
|
<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">
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@@ -58,6 +59,28 @@
|
|||||||
</html>
|
</html>
|
||||||
|
|
||||||
<script>
|
<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 () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
|
||||||
const form = document.getElementById("createUserForm");
|
const form = document.getElementById("createUserForm");
|
||||||
@@ -68,10 +91,11 @@
|
|||||||
function checkPasswords() {
|
function checkPasswords() {
|
||||||
if (confirmPasswordField.value === "") {
|
if (confirmPasswordField.value === "") {
|
||||||
confirmPasswordField.classList.remove("invalid");
|
confirmPasswordField.classList.remove("invalid");
|
||||||
passwordError.textContent = "";
|
passwordError.textContent = "Password cannot be blank";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (passwordField.value !== confirmPasswordField.value) {
|
if (passwordField.value !== confirmPasswordField.value) {
|
||||||
confirmPasswordField.classList.add("invalid");
|
confirmPasswordField.classList.add("invalid");
|
||||||
passwordError.textContent = "Passwords do not match.";
|
passwordError.textContent = "Passwords do not match.";
|
||||||
@@ -89,6 +113,8 @@
|
|||||||
|
|
||||||
const password = passwordField.value;
|
const password = passwordField.value;
|
||||||
const confirmPassword = confirmPasswordField.value;
|
const confirmPassword = confirmPasswordField.value;
|
||||||
|
const name = document.getElementById("username").value;
|
||||||
|
const email = document.getElementById("email").value;
|
||||||
|
|
||||||
if (password !== confirmPassword) {
|
if (password !== confirmPassword) {
|
||||||
confirmPasswordField.classList.add("invalid");
|
confirmPasswordField.classList.add("invalid");
|
||||||
@@ -96,6 +122,13 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isProfane(document.getElementById("username").value)) {
|
||||||
|
showError(username, 'Username contains inappropriate language');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const userData = {
|
const userData = {
|
||||||
username: document.getElementById("username").value,
|
username: document.getElementById("username").value,
|
||||||
email: document.getElementById("email").value,
|
email: document.getElementById("email").value,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
<title>My Profile - Thyme Crunch</title>
|
<title>My Profile - Thyme Crunch</title>
|
||||||
<link rel="stylesheet" th:href="@{css/my-profile.css}">
|
<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">
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@
|
|||||||
<label for="bio">Bio</label>
|
<label for="bio">Bio</label>
|
||||||
<textarea id="bio" th:field="*{bio}" rows="6" maxlength="1000"></textarea>
|
<textarea id="bio" th:field="*{bio}" rows="6" maxlength="1000"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit">Save</button>
|
<button type="submit" value='submit request' onclick='return btnClick();'>Save</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -97,6 +98,56 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<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 -->
|
// For cost display <!-- Cost change -->
|
||||||
function renderCost(cost) {
|
function renderCost(cost) {
|
||||||
const num = parseInt(cost, 10);
|
const num = parseInt(cost, 10);
|
||||||
|
|||||||
Reference in New Issue
Block a user