Skip to content

Commit

Permalink
The profainWords list is also now injected into createaccount.js befo…
Browse files Browse the repository at this point in the history
…re visiting that page, so no more needing to request that data after loading the page!
  • Loading branch information
Naviary2 committed Jul 16, 2024
1 parent 21f26df commit 647d356
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/client/scripts/createaccount.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// THIS LINE WILL BE INJECTED by HTMLScriptInjector!
// THESE LINES WILL BE INJECTED by the HTMLScriptInjector!
// const reservedUsernames = [...];
// const profainWords = [...];

const element_usernameInput = document.getElementById('username');
const element_emailInput = document.getElementById('email');
Expand Down Expand Up @@ -249,8 +249,8 @@ function onlyLettersAndNumbers(string) {

// Returns true if bad word is found
function checkProfanity(string) {
for (let i = 0; i < data.profainWords.length; i++) {
profanity = data.profainWords[i];
for (let i = 0; i < profainWords.length; i++) {
profanity = profainWords[i];
if (string.toLowerCase().includes(profanity)) return true;
}
return false;
Expand Down
11 changes: 10 additions & 1 deletion src/server/controllers/createaccountController.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ function getReservedUsernames() {
return reservedUsernames;
}

/**
* Returns the server list of profain words, that aren't allowed to be in usernames.
* @returns {string[]} The list of profain words
*/
function getProfainWords() {
return profainWords;
}

// Called when create account form submitted
const createNewMember = async (req, res) => {
if (!req.body) {
Expand Down Expand Up @@ -268,5 +276,6 @@ module.exports = {
checkUsernameAssociated,
generateID,
generateAccount,
getReservedUsernames
getReservedUsernames,
getProfainWords
};
10 changes: 6 additions & 4 deletions src/server/utility/HTMLScriptInjector.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const { getReservedUsernames } = require('../controllers/createaccountController');
const { getReservedUsernames, getProfainWords } = require('../controllers/createaccountController');

/**
* A cache object that has file paths for the keys, and for the values-
Expand Down Expand Up @@ -145,12 +145,14 @@ function getCachedHTML(htmlFilePath) {
prepareAndCacheHTML(htmlFilePath, jsFilePath, {string: HTML_callGame_JS_string, injectafter: injectafter_string});
}

// Inject the reserved usernames into createaccount.html, then SAVE it in /dist!
// Does using synchronious read and write methods slow down startup?
// Inject the reserved usernames, and profain words, into createaccount.html, then SAVE it in /dist!
// Does using synchronious read and write methods slow down startup???? Should asynchronious be used????
{
// Retrieve the reserved usernames
const reservedUsernames = getReservedUsernames();
const reservedUsernamesJS = `const reservedUsernames = ${JSON.stringify(reservedUsernames)};`
const profainWords = getProfainWords();
const profainWordsJS = `const profainWords = ${JSON.stringify(profainWords)};`

// Read the HTML file and inject the script tag
const createAccountScriptFilePath = path.join(__dirname, '..', '..', '..', 'dist', 'scripts', 'createaccount.js');
Expand All @@ -162,7 +164,7 @@ function getCachedHTML(htmlFilePath) {
return;
}

const modifiedScript = `// Injected by HTMLScriptInjector\n${reservedUsernamesJS}\n\n${createAccountScript}`;
const modifiedScript = `// Injected by HTMLScriptInjector\n${reservedUsernamesJS}\n${profainWordsJS}\n\n${createAccountScript}`;

// Write new script to /dist
fs.writeFileSync(createAccountScriptFilePath, modifiedScript);
Expand Down

0 comments on commit 647d356

Please sign in to comment.