This commit is contained in:
SowinskiBraeden committed 2020-12-17 10:18:33 -08:00
1 parent 4f15788983
commit eaabb7cc65
36 files changed
+2091 -55

No files matched your search

+1 -1
View File
@@ -1 +1 @@
/routes/uploads
/test
+4 -4
View File
@@ -1,11 +1,11 @@
const fs = require('fs');
const path = require('../routes/users.js').path;
const imagePath = require('../routes/users.js').defaultPath;
let image = {
data: fs.readFileSync(path),
data: fs.readFileSync(imagePath),
contentType: "image/png"
}
};
module.exports = {
defaultImage: image
}
};
+4
View File
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "8"
script: npm test
+123
View File
@@ -0,0 +1,123 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [3.0.4](https://github.com/web-mech/badwords/compare/v3.0.3...v3.0.4) (2020-11-16)
<a name="3.0.3"></a>
## [3.0.3](https://github.com/web-mech/badwords/compare/v3.0.2...v3.0.3) (2019-07-25)
<a name="3.0.2"></a>
## [3.0.2](https://github.com/web-mech/badwords/compare/v3.0.1...v3.0.2) (2019-03-14)
### Bug Fixes
* **lang.json:** remove gay from badwords ([88d1aed](https://github.com/web-mech/badwords/commit/88d1aed))
<a name="3.0.1"></a>
## [3.0.1](https://github.com/web-mech/badwords/compare/v3.0.0...v3.0.1) (2019-02-19)
### Bug Fixes
* update removeWords functionality to be case-insensitive ([235121d](https://github.com/web-mech/badwords/commit/235121d))
<a name="3.0.0"></a>
# [3.0.0](https://github.com/web-mech/badwords/compare/v2.0.0...v3.0.0) (2018-10-23)
### Code Refactoring
* utilize es6 spread in addWords/removeWords ([656b87c](https://github.com/web-mech/badwords/commit/656b87c))
### BREAKING CHANGES
* changes the way addWords is used, no longer accepts a single array as a parameter unless used with the spread operator
<a name="2.0.0"></a>
# [2.0.0](https://github.com/web-mech/badwords/compare/v1.6.5...v2.0.0) (2018-10-23)
### Documentation
* update documentation. add requirements for using lib moving forward ([9b2831d](https://github.com/web-mech/badwords/commit/9b2831d))
### Features
* **profane:** support profane phrases and well as words ([995ea1e](https://github.com/web-mech/badwords/commit/995ea1e))
### BREAKING CHANGES
* moving into es2016+ language features
<a name="1.6.5"></a>
## [1.6.5](https://github.com/web-mech/badwords/compare/v1.6.4...v1.6.5) (2018-10-23)
<a name="1.6.4"></a>
## [1.6.4](https://github.com/web-mech/badwords/compare/v1.6.3...v1.6.4) (2018-09-21)
### Bug Fixes
* **isProfane:** Adding regex word boundary for isProfane ([3908f3c](https://github.com/web-mech/badwords/commit/3908f3c))
<a name="1.6.3"></a>
## [1.6.3](https://github.com/web-mech/badwords/compare/v1.6.2...v1.6.3) (2018-08-02)
<a name="1.6.2"></a>
## [1.6.2](https://github.com/web-mech/badwords/compare/v1.6.1...v1.6.2) (2018-08-02)
### Bug Fixes
* **isProfaneLike:** abort trying to match every instance of profane words. ([31126d6](https://github.com/web-mech/badwords/commit/31126d6))
<a name="1.6.1"></a>
## [1.6.1](https://github.com/web-mech/badwords/compare/v1.6.0...v1.6.1) (2017-10-25)
### Bug Fixes
* **isProfaneLike:** fix case sensitive checks within list ([bfa05ce](https://github.com/web-mech/badwords/commit/bfa05ce))
<a name="1.6.0"></a>
# [1.6.0](https://github.com/web-mech/badwords/compare/v1.5.2...v1.6.0) (2017-10-16)
### Features
* fixes and updates ([8049222](https://github.com/web-mech/badwords/commit/8049222))
<a name="1.5.2"></a>
## [1.5.2](https://github.com/web-mech/badwords/compare/v1.5.1...v1.5.2) (2017-10-16)
### Bug Fixes
* support for better filtering ([7c8d0e2](https://github.com/web-mech/badwords/commit/7c8d0e2))
+20
View File
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2015 Michael Price
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+4
View File
@@ -0,0 +1,4 @@
test:
@./node_modules/mocha/bin/_mocha -R $(REPORTER)
.PHONY: test
+175
View File
@@ -0,0 +1,175 @@
# bad-words
A javascript filter for badwords
[![Build Status](https://travis-ci.org/web-mech/badwords.svg?branch=master)](https://travis-ci.org/web-mech/badwords)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
## Requirements
As of version 2, requires you either have an environment that understands ES2016 and beyond or a transpiler like Babel.
## Installation
npm install bad-words --save
## Usage
```js
var Filter = require('bad-words'),
filter = new Filter();
console.log(filter.clean("Don't be an ash0le")); //Don't be an ******
```
### Placeholder Overrides
```js
var Filter = require('bad-words');
var customFilter = new Filter({ placeHolder: 'x'});
customFilter.clean("Don't be an ash0le"); //Don't be an xxxxxx
```
### Regex Overrides
```js
var filter = new Filter({ regex: /\*|\.|$/gi });
var filter = new Filter({ replaceRegex: /[A-Za-z0-9가-힣_]/g });
//multilingual support for word filtering
```
### Add words to the blacklist
```js
var filter = new Filter();
filter.addWords('some', 'bad', 'word');
filter.clean("some bad word!") //**** *** ****!
//or use an array using the spread operator
var newBadWords = ['some', 'bad', 'word'];
filter.addWords(...newBadWords);
filter.clean("some bad word!") //**** *** ****!
//or
var filter = new Filter({ list: ['some', 'bad', 'word'] });
filter.clean("some bad word!") //**** *** ****!
```
### Instantiate with an empty list
```js
var filter = new Filter({ emptyList: true });
filter.clean('hell this wont clean anything'); //hell this wont clean anything
```
### Remove words from the blacklist
```js
let filter = new Filter();
filter.removeWords('hells', 'sadist');
filter.clean("some hells word!"); //some hells word!
//or use an array using the spread operator
let removeWords = ['hells', 'sadist'];
filter.removeWords(...removeWords);
filter.clean("some sadist hells word!"); //some sadist hells word!
```
### API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
#### constructor
Filter constructor.
**Parameters**
- `options` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Filter instance options (optional, default `{}`)
- `options.emptyList` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Instantiate filter with no blacklist
- `options.list` **[array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** Instantiate filter with custom list
- `options.placeHolder` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Character used to replace profane words.
- `options.regex` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Regular expression used to sanitize words before comparing them to blacklist.
- `options.replaceRegex` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Regular expression used to replace profane words with placeHolder.
#### isProfane
Determine if a string contains profane language.
**Parameters**
- `string` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** String to evaluate for profanity.
#### replaceWord
Replace a word with placeHolder characters;
**Parameters**
- `string` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** String to replace.
#### clean
Evaluate a string for profanity and return an edited version.
**Parameters**
- `string` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Sentence to filter.
#### addWords
Add word(s) to blacklist filter / remove words from whitelist filter
**Parameters**
- `word` **...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Word(s) to add to blacklist
#### removeWords
Add words to whitelist filter
**Parameters**
- `word` **...[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Word(s) to add to whitelist.
## Testing
npm test
## License
The MIT License (MIT)
Copyright (c) 2013 Michael Price
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+88
View File
@@ -0,0 +1,88 @@
const localList = require('./lang.json').words;
const baseList = require('badwords-list').array;
class Filter {
/**
* Filter constructor.
* @constructor
* @param {object} options - Filter instance options
* @param {boolean} options.emptyList - Instantiate filter with no blacklist
* @param {array} options.list - Instantiate filter with custom list
* @param {string} options.placeHolder - Character used to replace profane words.
* @param {string} options.regex - Regular expression used to sanitize words before comparing them to blacklist.
* @param {string} options.replaceRegex - Regular expression used to replace profane words with placeHolder.
* @param {string} options.splitRegex - Regular expression used to split a string into words.
*/
constructor(options = {}) {
Object.assign(this, {
list: options.emptyList && [] || Array.prototype.concat.apply(localList, [baseList, options.list || []]),
exclude: options.exclude || [],
splitRegex: options.splitRegex || /\b/,
placeHolder: options.placeHolder || '*',
regex: options.regex || /[^a-zA-Z0-9|\$|\@]|\^/g,
replaceRegex: options.replaceRegex || /\w/g
})
}
/**
* Determine if a string contains profane language.
* @param {string} string - String to evaluate for profanity.
*/
isProfane(string) {
return this.list
.filter((word) => {
const wordExp = new RegExp(`\\b${word.replace(/(\W)/g, '\\$1')}\\b`, 'gi');
return !this.exclude.includes(word.toLowerCase()) && wordExp.test(string);
})
.length > 0 || false;
}
/**
* Replace a word with placeHolder characters;
* @param {string} string - String to replace.
*/
replaceWord(string) {
return string
.replace(this.regex, '')
.replace(this.replaceRegex, this.placeHolder);
}
/**
* Evaluate a string for profanity and return an edited version.
* @param {string} string - Sentence to filter.
*/
clean(string) {
return string.split(this.splitRegex).map((word) => {
return this.isProfane(word) ? this.replaceWord(word) : word;
}).join(this.splitRegex.exec(string)[0]);
}
/**
* Add word(s) to blacklist filter / remove words from whitelist filter
* @param {...string} word - Word(s) to add to blacklist
*/
addWords() {
let words = Array.from(arguments);
this.list.push(...words);
words
.map(word => word.toLowerCase())
.forEach((word) => {
if (this.exclude.includes(word)) {
this.exclude.splice(this.exclude.indexOf(word), 1);
}
});
}
/**
* Add words to whitelist filter
* @param {...string} word - Word(s) to add to whitelist.
*/
removeWords() {
this.exclude.push(...Array.from(arguments).map(word => word.toLowerCase()));
}
}
module.exports = Filter;
+451
View File
@@ -0,0 +1,451 @@
{
"words":[
"ahole",
"anus",
"ash0le",
"ash0les",
"asholes",
"ass",
"Ass Monkey",
"Assface",
"assh0le",
"assh0lez",
"asshole",
"assholes",
"assholz",
"asswipe",
"azzhole",
"bassterds",
"bastard",
"bastards",
"bastardz",
"basterds",
"basterdz",
"Biatch",
"bitch",
"bitches",
"Blow Job",
"boffing",
"butthole",
"buttwipe",
"c0ck",
"c0cks",
"c0k",
"Carpet Muncher",
"cawk",
"cawks",
"Clit",
"cnts",
"cntz",
"cock",
"cockhead",
"cock-head",
"cocks",
"CockSucker",
"cock-sucker",
"crap",
"cum",
"cunt",
"cunts",
"cuntz",
"dick",
"dild0",
"dild0s",
"dildo",
"dildos",
"dilld0",
"dilld0s",
"dominatricks",
"dominatrics",
"dominatrix",
"dyke",
"enema",
"f u c k",
"f u c k e r",
"fag",
"fag1t",
"faget",
"fagg1t",
"faggit",
"faggot",
"fagg0t",
"fagit",
"fags",
"fagz",
"faig",
"faigs",
"fart",
"flipping the bird",
"fuck",
"fucker",
"fuckin",
"fucking",
"fucks",
"Fudge Packer",
"fuk",
"Fukah",
"Fuken",
"fuker",
"Fukin",
"Fukk",
"Fukkah",
"Fukken",
"Fukker",
"Fukkin",
"g00k",
"God-damned",
"h00r",
"h0ar",
"h0re",
"hells",
"hoar",
"hoor",
"hoore",
"jackoff",
"jap",
"japs",
"jerk-off",
"jisim",
"jiss",
"jizm",
"jizz",
"knob",
"knobs",
"knobz",
"kunt",
"kunts",
"kuntz",
"Lezzian",
"Lipshits",
"Lipshitz",
"masochist",
"masokist",
"massterbait",
"masstrbait",
"masstrbate",
"masterbaiter",
"masterbate",
"masterbates",
"Motha Fucker",
"Motha Fuker",
"Motha Fukkah",
"Motha Fukker",
"Mother Fucker",
"Mother Fukah",
"Mother Fuker",
"Mother Fukkah",
"Mother Fukker",
"mother-fucker",
"Mutha Fucker",
"Mutha Fukah",
"Mutha Fuker",
"Mutha Fukkah",
"Mutha Fukker",
"n1gr",
"nastt",
"nigger;",
"nigur;",
"niiger;",
"niigr;",
"orafis",
"orgasim;",
"orgasm",
"orgasum",
"oriface",
"orifice",
"orifiss",
"packi",
"packie",
"packy",
"paki",
"pakie",
"paky",
"pecker",
"peeenus",
"peeenusss",
"peenus",
"peinus",
"pen1s",
"penas",
"penis",
"penis-breath",
"penus",
"penuus",
"Phuc",
"Phuck",
"Phuk",
"Phuker",
"Phukker",
"polac",
"polack",
"polak",
"Poonani",
"pr1c",
"pr1ck",
"pr1k",
"pusse",
"pussee",
"pussy",
"puuke",
"puuker",
"qweir",
"recktum",
"rectum",
"retard",
"sadist",
"scank",
"schlong",
"screwing",
"semen",
"sex",
"sexy",
"Sh!t",
"sh1t",
"sh1ter",
"sh1ts",
"sh1tter",
"sh1tz",
"shit",
"shits",
"shitter",
"Shitty",
"Shity",
"shitz",
"Shyt",
"Shyte",
"Shytty",
"Shyty",
"skanck",
"skank",
"skankee",
"skankey",
"skanks",
"Skanky",
"slag",
"slut",
"sluts",
"Slutty",
"slutz",
"son-of-a-bitch",
"tit",
"turd",
"va1jina",
"vag1na",
"vagiina",
"vagina",
"vaj1na",
"vajina",
"vullva",
"vulva",
"w0p",
"wh00r",
"wh0re",
"whore",
"xrated",
"xxx",
"b!+ch",
"bitch",
"blowjob",
"clit",
"arschloch",
"fuck",
"shit",
"ass",
"asshole",
"b!tch",
"b17ch",
"b1tch",
"bastard",
"bi+ch",
"boiolas",
"buceta",
"c0ck",
"cawk",
"chink",
"cipa",
"clits",
"cock",
"cum",
"cunt",
"dildo",
"dirsa",
"ejakulate",
"fatass",
"fcuk",
"fuk",
"fux0r",
"hoer",
"hore",
"jism",
"kawk",
"l3itch",
"l3i+ch",
"masturbate",
"masterbat*",
"masterbat3",
"motherfucker",
"s.o.b.",
"mofo",
"nazi",
"nigga",
"nigger",
"nutsack",
"phuck",
"pimpis",
"pusse",
"pussy",
"scrotum",
"sh!t",
"shemale",
"shi+",
"sh!+",
"slut",
"smut",
"teets",
"tits",
"boobs",
"b00bs",
"teez",
"testical",
"testicle",
"titt",
"w00se",
"jackoff",
"wank",
"whoar",
"whore",
"*damn",
"*dyke",
"*fuck*",
"*shit*",
"@$$",
"amcik",
"andskota",
"arse*",
"assrammer",
"ayir",
"bi7ch",
"bitch*",
"bollock*",
"breasts",
"butt-pirate",
"cabron",
"cazzo",
"chraa",
"chuj",
"Cock*",
"cunt*",
"d4mn",
"daygo",
"dego",
"dick*",
"dike*",
"dupa",
"dziwka",
"ejackulate",
"Ekrem*",
"Ekto",
"enculer",
"faen",
"fag*",
"fanculo",
"fanny",
"feces",
"feg",
"Felcher",
"ficken",
"fitt*",
"Flikker",
"foreskin",
"Fotze",
"Fu(*",
"fuk*",
"futkretzn",
"gook",
"guiena",
"h0r",
"h4x0r",
"hell",
"helvete",
"hoer*",
"honkey",
"Huevon",
"hui",
"injun",
"jizz",
"kanker*",
"kike",
"klootzak",
"kraut",
"knulle",
"kuk",
"kuksuger",
"Kurac",
"kurwa",
"kusi*",
"kyrpa*",
"lesbo",
"mamhoon",
"masturbat*",
"merd*",
"mibun",
"monkleigh",
"mouliewop",
"muie",
"mulkku",
"muschi",
"nazis",
"nepesaurio",
"nigger*",
"orospu",
"paska*",
"perse",
"picka",
"pierdol*",
"pillu*",
"pimmel",
"piss*",
"pizda",
"poontsee",
"poop",
"porn",
"p0rn",
"pr0n",
"preteen",
"pula",
"pule",
"puta",
"puto",
"qahbeh",
"queef*",
"rautenberg",
"schaffer",
"scheiss*",
"schlampe",
"schmuck",
"screw",
"sh!t*",
"sharmuta",
"sharmute",
"shipal",
"shiz",
"skribz",
"skurwysyn",
"sphencter",
"spic",
"spierdalaj",
"splooge",
"suka",
"b00b*",
"testicle*",
"titt*",
"twat",
"vittu",
"wank*",
"wetback*",
"wichser",
"wop*",
"yed",
"zabourah"
]
}
+68
View File
@@ -0,0 +1,68 @@
{
"_from": "bad-words",
"_id": "bad-words@3.0.4",
"_inBundle": false,
"_integrity": "sha512-v/Q9uRPH4+yzDVLL4vR1+S9KoFgOEUl5s4axd6NIAq8SV2mradgi4E8lma/Y0cw1ltVdvyegCQQKffCPRCp8fg==",
"_location": "/bad-words",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "bad-words",
"name": "bad-words",
"escapedName": "bad-words",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/bad-words/-/bad-words-3.0.4.tgz",
"_shasum": "044c83935c4c363a905d47b5e0179f7241fecaec",
"_spec": "bad-words",
"_where": "C:\\Users\\flami\\OneDrive\\Desktop\\Projects\\XP-System",
"author": {
"name": "Mike P."
},
"bugs": {
"url": "https://github.com/web-mech/badwords/issues"
},
"bundleDependencies": false,
"dependencies": {
"badwords-list": "^1.0.0"
},
"deprecated": false,
"description": "A javascript filter for bad words",
"devDependencies": {
"better-assert": "1.0.0",
"documentation": "^5.3.3",
"mocha": "^5.2.0"
},
"directories": {
"test": "test"
},
"engines": {
"node": ">=8.0.0"
},
"homepage": "https://github.com/web-mech/badwords#readme",
"keywords": [
"curse",
"words",
"profanity",
"filter"
],
"license": "MIT",
"main": "./lib/badwords",
"name": "bad-words",
"repository": {
"type": "git",
"url": "git://github.com/web-mech/badwords.git"
},
"scripts": {
"docs": "documentation readme --section API ./lib/badwords.js",
"test": "mocha -R spec"
},
"version": "3.0.4"
}
+28
View File
@@ -0,0 +1,28 @@
require('assert');
var Filter = require('../lib/badwords.js'),
filter = new Filter(),
assert = require('better-assert');
describe('filter', function(){
describe('addWords',function(){
it('Should append words to the filter list.', function(){
filter.addWords('dog', 'go');
assert(filter.clean('Go dog go') === '** *** **');
});
it('Should append words to the filter using an array', () => {
let addWords = ['go', 'dog'];
filter = new Filter()
filter.addWords(...addWords);
assert(filter.clean('Go dog go') === '** *** **');
});
it('Should allow a list to be passed to the constructor', function() {
filter = new Filter({
list: ['dog']
});
assert(filter.clean('Go dog go') === 'Go *** go');
});
});
});
+47
View File
@@ -0,0 +1,47 @@
require('assert');
var Filter = require('../lib/badwords.js'),
filter = new Filter(),
assert = require('better-assert');
describe('filter', function(){
describe('clean',function(){
it('Should replace a bad word within a sentence asterisks (******)',function(){
console.log(filter.clean('Don\'t be an ash0le'));
assert(filter.clean('Don\'t be an ash0le') === 'Don\'t be an ******');
});
it('Should replace multiple instances of any bad words within a sentence asterisks (******)',function(){
assert(filter.clean('cnts ash0le knob xxx') === '**** ****** **** ***');
});
it('Should not replace anything within a sentence if there are no bad words',function(){
assert(filter.clean('The cat ran fast') === 'The cat ran fast');
});
it('Should replace a string with proper placeholder when overridden', function(){
var customFilter = new Filter({ placeHolder: 'x'});
assert(customFilter.clean('This is a hells good test') === 'This is a xxxxx good test');
});
it('Should allow an instance of filter with an empty blacklist', function() {
var customFilter = new Filter({
emptyList: true
});
assert(customFilter.clean('This is a hells good test') === 'This is a hells good test');
});
it('Should tokenize words according to regex word boundaries',function(){
assert(filter.clean('what a bitch...fuck you') === 'what a *****...**** you');
assert(filter.clean('<p>Don\'t be an asshole</p>') === '<p>Don\'t be an *******</p>');
});
xit('Should filter words that are derivatives of words from the filter blacklist', function() {
assert(filter.clean('shitshit') === '********');
});
it('Shouldn\'t filter words that aren\'t profane.', function() {
assert(filter.clean('hello there') === 'hello there');
});
});
});
+44
View File
@@ -0,0 +1,44 @@
require('assert');
var Filter = require('../lib/badwords.js'),
filter = new Filter(),
assert = require('better-assert');
describe('filter', function(){
describe('isProfane',function(){
it("Should detect a bad word and return a boolean value",function(){
assert(filter.isProfane("ash0le"));
});
it("Should return false when no bad word is detected",function(){
assert(filter.isProfane("wife") === false);
});
it("Should be able to detect a bad word in a sentence",function(){
assert(filter.isProfane("that person is an ash0le"));
});
it('Filters out special characters appropriately', function() {
assert(filter.isProfane("You're an asshole^ you are"));
});
it('Should detect filtered words from badwords-list', function(){
assert(filter.isProfane('willies'));
});
it('Should detect filtered words regardless of type case', function() {
var filter = new Filter({
list: ['Test']
});
assert(filter.isProfane('test'));
});
it('Should tokenize words according to regex word boundaries', function() {
assert(filter.isProfane("that person is an\nasshole"));
});
it('Should detect bad word phrases', function () {
filter.addWords('oh no');
assert(filter.isProfane("oh no! this is profane!"));
});
});
});
+24
View File
@@ -0,0 +1,24 @@
require('assert');
var Filter = require('../lib/badwords.js'),
assert = require('better-assert');
describe('options', function() {
describe('split regex', function() {
it('default value', function() {
filter = new Filter();
filter.addWords('français');
assert(filter.clean('fucking asshole') == '******* *******');
assert(filter.clean('mot en français') == 'mot en français');
});
it('override value', function() {
filter = new Filter({splitRegex: / /});
filter.addWords('français');
assert(filter.clean('fucking asshole') == '******* *******');
assert(filter.clean('mot en français') == 'mot en *******');
});
});
});
+21
View File
@@ -0,0 +1,21 @@
require('assert');
var Filter = require('../lib/badwords.js'),
filter = new Filter(),
assert = require('better-assert');
describe('filter', () => {
describe('removeWords',() => {
it('Should allow you to remove words from the filter blacklist and no longer filter them (case-insensitive)', () => {
filter.removeWords('Hells');
assert(filter.clean('This is a hells good test') === 'This is a hells good test');
});
it ('Should allow you to remove an array of words from the filter blacklist and no longer filter them', () => {
let removingWords = ['hells', 'sadist'];
filter = new Filter();
filter.removeWords(...removingWords);
assert(filter.clean('This is a hells sadist test') === 'This is a hells sadist test');
});
});
});
+12
View File
@@ -0,0 +1,12 @@
require('assert');
var Filter = require('../lib/badwords.js'),
filter = new Filter(),
assert = require('better-assert');
describe('filter', function(){
describe('replaceWord',function(){
it("Should replace a bad word with asterisks (******)",function(){
assert(filter.replaceWord("ash0le") == '******');
});
});
});
+15
View File
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
npm-debug.log
node_modules/
+20
View File
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 Maurice Butler
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+4
View File
@@ -0,0 +1,4 @@
test:
@./node_modules/mocha/bin/_mocha -R $(REPORTER)
.PHONY: test
+57
View File
@@ -0,0 +1,57 @@
badwords-list v1.0.0
========
A highly consumable list of bad (profanity) english words based on the nice short and simple list found in [Google's "what do you love" project](http://www.wdyl.com/) made accessable by [Jamie Wilkinson](https://gist.github.com/jamiew) [here](https://gist.github.com/jamiew/1112488)
Inspired by [badwords](https://github.com/MauriceButler/badwords)
This data has been exposed as an object that contains
- an array
- an object
- a regular expression
depending on what is required for your purposes.
Install
=======
npm install badwords-list
Usage
=====
```
var list = require('badwords-list'),
array = list.array,
object = list.object,
regex = list.regex;
```
Testing
=======
####Requires
- Mocha
- better-assert
```
npm test
```
**or**
```
REPORTER=spec make
```
**or**
```
mocha
```
+1
View File
@@ -0,0 +1 @@
module.exports = ["4r5e", "5h1t", "5hit", "a55", "anal", "anus", "ar5e", "arrse", "arse", "ass", "ass-fucker", "asses", "assfucker", "assfukka", "asshole", "assholes", "asswhole", "a_s_s", "b!tch", "b00bs", "b17ch", "b1tch", "ballbag", "balls", "ballsack", "bastard", "beastial", "beastiality", "bellend", "bestial", "bestiality", "bi+ch", "biatch", "bitch", "bitcher", "bitchers", "bitches", "bitchin", "bitching", "bloody", "blow job", "blowjob", "blowjobs", "boiolas", "bollock", "bollok", "boner", "boob", "boobs", "booobs", "boooobs", "booooobs", "booooooobs", "breasts", "buceta", "bugger", "bum", "bunny fucker", "butt", "butthole", "buttmuch", "buttplug", "c0ck", "c0cksucker", "carpet muncher", "cawk", "chink", "cipa", "cl1t", "clit", "clitoris", "clits", "cnut", "cock", "cock-sucker", "cockface", "cockhead", "cockmunch", "cockmuncher", "cocks", "cocksuck", "cocksucked", "cocksucker", "cocksucking", "cocksucks", "cocksuka", "cocksukka", "cok", "cokmuncher", "coksucka", "coon", "cox", "crap", "cum", "cummer", "cumming", "cums", "cumshot", "cunilingus", "cunillingus", "cunnilingus", "cunt", "cuntlick", "cuntlicker", "cuntlicking", "cunts", "cyalis", "cyberfuc", "cyberfuck", "cyberfucked", "cyberfucker", "cyberfuckers", "cyberfucking", "d1ck", "damn", "dick", "dickhead", "dildo", "dildos", "dink", "dinks", "dirsa", "dlck", "dog-fucker", "doggin", "dogging", "donkeyribber", "doosh", "duche", "dyke", "ejaculate", "ejaculated", "ejaculates", "ejaculating", "ejaculatings", "ejaculation", "ejakulate", "f u c k", "f u c k e r", "f4nny", "fag", "fagging", "faggitt", "faggot", "faggs", "fagot", "fagots", "fags", "fanny", "fannyflaps", "fannyfucker", "fanyy", "fatass", "fcuk", "fcuker", "fcuking", "feck", "fecker", "felching", "fellate", "fellatio", "fingerfuck", "fingerfucked", "fingerfucker", "fingerfuckers", "fingerfucking", "fingerfucks", "fistfuck", "fistfucked", "fistfucker", "fistfuckers", "fistfucking", "fistfuckings", "fistfucks", "flange", "fook", "fooker", "fuck", "fucka", "fucked", "fucker", "fuckers", "fuckhead", "fuckheads", "fuckin", "fucking", "fuckings", "fuckingshitmotherfucker", "fuckme", "fucks", "fuckwhit", "fuckwit", "fudge packer", "fudgepacker", "fuk", "fuker", "fukker", "fukkin", "fuks", "fukwhit", "fukwit", "fux", "fux0r", "f_u_c_k", "gangbang", "gangbanged", "gangbangs", "gaylord", "gaysex", "goatse", "God", "god-dam", "god-damned", "goddamn", "goddamned", "hardcoresex", "hell", "heshe", "hoar", "hoare", "hoer", "homo", "hore", "horniest", "horny", "hotsex", "jack-off", "jackoff", "jap", "jerk-off", "jism", "jiz", "jizm", "jizz", "kawk", "knob", "knobead", "knobed", "knobend", "knobhead", "knobjocky", "knobjokey", "kock", "kondum", "kondums", "kum", "kummer", "kumming", "kums", "kunilingus", "l3i+ch", "l3itch", "labia", "lust", "lusting", "m0f0", "m0fo", "m45terbate", "ma5terb8", "ma5terbate", "masochist", "master-bate", "masterb8", "masterbat*", "masterbat3", "masterbate", "masterbation", "masterbations", "masturbate", "mo-fo", "mof0", "mofo", "mothafuck", "mothafucka", "mothafuckas", "mothafuckaz", "mothafucked", "mothafucker", "mothafuckers", "mothafuckin", "mothafucking", "mothafuckings", "mothafucks", "mother fucker", "motherfuck", "motherfucked", "motherfucker", "motherfuckers", "motherfuckin", "motherfucking", "motherfuckings", "motherfuckka", "motherfucks", "muff", "mutha", "muthafecker", "muthafuckker", "muther", "mutherfucker", "n1gga", "n1gger", "nazi", "nigg3r", "nigg4h", "nigga", "niggah", "niggas", "niggaz", "nigger", "niggers", "nob", "nob jokey", "nobhead", "nobjocky", "nobjokey", "numbnuts", "nutsack", "orgasim", "orgasims", "orgasm", "orgasms", "p0rn", "pawn", "pecker", "penis", "penisfucker", "phonesex", "phuck", "phuk", "phuked", "phuking", "phukked", "phukking", "phuks", "phuq", "pigfucker", "pimpis", "piss", "pissed", "pisser", "pissers", "pisses", "pissflaps", "pissin", "pissing", "pissoff", "poop", "porn", "porno", "pornography", "pornos", "prick", "pricks", "pron", "pube", "pusse", "pussi", "pussies", "pussy", "pussys", "rectum", "retard", "rimjaw", "rimming", "s hit", "s.o.b.", "sadist", "schlong", "screwing", "scroat", "scrote", "scrotum", "semen", "sex", "sh!+", "sh!t", "sh1t", "shag", "shagger", "shaggin", "shagging", "shemale", "shi+", "shit", "shitdick", "shite", "shited", "shitey", "shitfuck", "shitfull", "shithead", "shiting", "shitings", "shits", "shitted", "shitter", "shitters", "shitting", "shittings", "shitty", "skank", "slut", "sluts", "smegma", "smut", "snatch", "son-of-a-bitch", "spac", "spunk", "s_h_i_t", "t1tt1e5", "t1tties", "teets", "teez", "testical", "testicle", "tit", "titfuck", "tits", "titt", "tittie5", "tittiefucker", "titties", "tittyfuck", "tittywank", "titwank", "tosser", "turd", "tw4t", "twat", "twathead", "twatty", "twunt", "twunter", "v14gra", "v1gra", "vagina", "viagra", "vulva", "w00se", "wang", "wank", "wanker", "wanky", "whoar", "whore", "willies", "willy", "xrated", "xxx"];
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
object: require('./object'),
array: require('./array'),
regex: require('./regexp')
};
+1
View File
File diff suppressed because one or more lines are too long.
+1
View File
@@ -0,0 +1 @@
module.exports = /\b(4r5e|5h1t|5hit|a55|anal|anus|ar5e|arrse|arse|ass|ass-fucker|asses|assfucker|assfukka|asshole|assholes|asswhole|a_s_s|b!tch|b00bs|b17ch|b1tch|ballbag|balls|ballsack|bastard|beastial|beastiality|bellend|bestial|bestiality|bi\+ch|biatch|bitch|bitcher|bitchers|bitches|bitchin|bitching|bloody|blow job|blowjob|blowjobs|boiolas|bollock|bollok|boner|boob|boobs|booobs|boooobs|booooobs|booooooobs|breasts|buceta|bugger|bum|bunny fucker|butt|butthole|buttmuch|buttplug|c0ck|c0cksucker|carpet muncher|cawk|chink|cipa|cl1t|clit|clitoris|clits|cnut|cock|cock-sucker|cockface|cockhead|cockmunch|cockmuncher|cocks|cocksuck|cocksucked|cocksucker|cocksucking|cocksucks|cocksuka|cocksukka|cok|cokmuncher|coksucka|coon|cox|crap|cum|cummer|cumming|cums|cumshot|cunilingus|cunillingus|cunnilingus|cunt|cuntlick|cuntlicker|cuntlicking|cunts|cyalis|cyberfuc|cyberfuck|cyberfucked|cyberfucker|cyberfuckers|cyberfucking|d1ck|damn|dick|dickhead|dildo|dildos|dink|dinks|dirsa|dlck|dog-fucker|doggin|dogging|donkeyribber|doosh|duche|dyke|ejaculate|ejaculated|ejaculates|ejaculating|ejaculatings|ejaculation|ejakulate|f u c k|f u c k e r|f4nny|fag|fagging|faggitt|faggot|faggs|fagot|fagots|fags|fanny|fannyflaps|fannyfucker|fanyy|fatass|fcuk|fcuker|fcuking|feck|fecker|felching|fellate|fellatio|fingerfuck|fingerfucked|fingerfucker|fingerfuckers|fingerfucking|fingerfucks|fistfuck|fistfucked|fistfucker|fistfuckers|fistfucking|fistfuckings|fistfucks|flange|fook|fooker|fuck|fucka|fucked|fucker|fuckers|fuckhead|fuckheads|fuckin|fucking|fuckings|fuckingshitmotherfucker|fuckme|fucks|fuckwhit|fuckwit|fudge packer|fudgepacker|fuk|fuker|fukker|fukkin|fuks|fukwhit|fukwit|fux|fux0r|f_u_c_k|gangbang|gangbanged|gangbangs|gaylord|gaysex|goatse|God|god-dam|god-damned|goddamn|goddamned|hardcoresex|hell|heshe|hoar|hoare|hoer|homo|hore|horniest|horny|hotsex|jack-off|jackoff|jap|jerk-off|jism|jiz|jizm|jizz|kawk|knob|knobead|knobed|knobend|knobhead|knobjocky|knobjokey|kock|kondum|kondums|kum|kummer|kumming|kums|kunilingus|l3i\+ch|l3itch|labia|lust|lusting|m0f0|m0fo|m45terbate|ma5terb8|ma5terbate|masochist|master-bate|masterb8|masterbat*|masterbat3|masterbate|masterbation|masterbations|masturbate|mo-fo|mof0|mofo|mothafuck|mothafucka|mothafuckas|mothafuckaz|mothafucked|mothafucker|mothafuckers|mothafuckin|mothafucking|mothafuckings|mothafucks|mother fucker|motherfuck|motherfucked|motherfucker|motherfuckers|motherfuckin|motherfucking|motherfuckings|motherfuckka|motherfucks|muff|mutha|muthafecker|muthafuckker|muther|mutherfucker|n1gga|n1gger|nazi|nigg3r|nigg4h|nigga|niggah|niggas|niggaz|nigger|niggers|nob|nob jokey|nobhead|nobjocky|nobjokey|numbnuts|nutsack|orgasim|orgasims|orgasm|orgasms|p0rn|pawn|pecker|penis|penisfucker|phonesex|phuck|phuk|phuked|phuking|phukked|phukking|phuks|phuq|pigfucker|pimpis|piss|pissed|pisser|pissers|pisses|pissflaps|pissin|pissing|pissoff|poop|porn|porno|pornography|pornos|prick|pricks|pron|pube|pusse|pussi|pussies|pussy|pussys|rectum|retard|rimjaw|rimming|s hit|s.o.b.|sadist|schlong|screwing|scroat|scrote|scrotum|semen|sex|sh!\+|sh!t|sh1t|shag|shagger|shaggin|shagging|shemale|shi\+|shit|shitdick|shite|shited|shitey|shitfuck|shitfull|shithead|shiting|shitings|shits|shitted|shitter|shitters|shitting|shittings|shitty|skank|slut|sluts|smegma|smut|snatch|son-of-a-bitch|spac|spunk|s_h_i_t|t1tt1e5|t1tties|teets|teez|testical|testicle|tit|titfuck|tits|titt|tittie5|tittiefucker|titties|tittyfuck|tittywank|titwank|tosser|turd|tw4t|twat|twathead|twatty|twunt|twunter|v14gra|v1gra|vagina|viagra|vulva|w00se|wang|wank|wanker|wanky|whoar|whore|willies|willy|xrated|xxx)\b/gi;
+62
View File
@@ -0,0 +1,62 @@
{
"_from": "badwords-list@^1.0.0",
"_id": "badwords-list@1.0.0",
"_inBundle": false,
"_integrity": "sha1-XphW2/E0gqKVw7CzBK+51M/FxXk=",
"_location": "/badwords-list",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "badwords-list@^1.0.0",
"name": "badwords-list",
"escapedName": "badwords-list",
"rawSpec": "^1.0.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
},
"_requiredBy": [
"/bad-words"
],
"_resolved": "https://registry.npmjs.org/badwords-list/-/badwords-list-1.0.0.tgz",
"_shasum": "5e9856dbf13482a295c3b0b304afb9d4cfc5c579",
"_spec": "badwords-list@^1.0.0",
"_where": "C:\\Users\\flami\\OneDrive\\Desktop\\Projects\\XP-System\\node_modules\\bad-words",
"author": {
"name": "Michael Price",
"email": "webmech@gmail.com"
},
"bugs": {
"url": "https://github.com/web-mech/badwords-list/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "A highly consumable list of bad (profanity) english words (forked from badwords)",
"devDependencies": {
"better-assert": "1.0.0",
"mocha": "1.14.0"
},
"homepage": "https://github.com/web-mech/badwords-list#readme",
"keywords": [
"bad",
"word",
"words",
"profanity",
"filter",
"blacklist",
"black",
"list",
"swear"
],
"license": "MIT",
"main": "./lib/index",
"name": "badwords-list",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/web-mech/badwords-list.git"
},
"scripts": {
"test": "mocha -R nyan"
},
"version": "1.0.0"
}
+18
View File
@@ -0,0 +1,18 @@
var assert = require('better-assert');
describe('filter', function(){
it('Should contain property object', function(){
var list = require('../lib/index');
assert(list.hasOwnProperty('object'));
});
it('Should contain property array', function(){
var list = require('../lib/index');
assert(list.hasOwnProperty('array'));
});
it('Should contain property regex', function(){
var list = require('../lib/index');
assert(list.hasOwnProperty('regex'));
});
});
+13
View File
@@ -105,6 +105,19 @@
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
"dev": true
},
"bad-words": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/bad-words/-/bad-words-3.0.4.tgz",
"integrity": "sha512-v/Q9uRPH4+yzDVLL4vR1+S9KoFgOEUl5s4axd6NIAq8SV2mradgi4E8lma/Y0cw1ltVdvyegCQQKffCPRCp8fg==",
"requires": {
"badwords-list": "^1.0.0"
}
},
"badwords-list": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/badwords-list/-/badwords-list-1.0.0.tgz",
"integrity": "sha1-XphW2/E0gqKVw7CzBK+51M/FxXk="
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
+1
View File
@@ -11,6 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"bad-words": "^3.0.4",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"connect-flash": "^0.1.1",
+243 -20
View File
@@ -5,6 +5,11 @@ const bcrypt = require('bcryptjs');
const passport = require('passport');
const MongoClient = require('mongodb').MongoClient;
const ObjectId = require('mongodb').ObjectId;
// Load Profanity filter
const Filter = require('bad-words');
const filter = new Filter();
// Load User model
const User = require('../models/User');
const { forwardAuthenticated } = require('../config/auth');
@@ -37,16 +42,66 @@ router.get('/register', forwardAuthenticated, (req, res) => res.render('register
// Edit page
router.get('/edit', (req, res) => res.render('edit'));
// Add XP
router.post('/addXP', (req, res, next) => {
const { _id_add, current_xp, amount } = req.body;
if(amount > 50) {
// Takes to Dahsboard on success
let value = encodeURIComponent('addXP > 50')
res.redirect('/dashboard?successRate=' + value);
}
if(amount < 0 || amount == 0) {
// Takes to Dahsboard on success
let value = encodeURIComponent('addXP <= 0')
res.redirect('/dashboard?successRate=' + value);
}
if (amount < 50 && amount > 0 && current_xp < 800) {
let newXP = current_xp + amount;
if (newXP > 800) {
newXP = 800;
}
try {
// Creates updated object
let updated = {
xp: newXP
}
// Updates user xp
MongoClient.connect(db, {
useUnifiedTopology: true,
useNewUrlParser: true}, function(err, db) {
if (err) throw err;
let dbo = db.db("XPmockDB");
dbo.collection('users').updateOne({ _id: ObjectId(_id_add) }, { $set: updated }, { upsert: true }, function(err, res) {
if (err) throw err;
db.close()
});
// Takes to Dahsboard on success
let value = encodeURIComponent(amount.toString())
res.redirect('/dashboard?successRate=' + value);
}
);
}
catch(err) {
console.log(err);
}
}
});
// Edit
router.post('/edit', upload.single('image'), (req, res, next) => {
// Passes image path to defaultImage Model
imagePath = __dirname + '/uploads/image-1606947471396';
imagePath = __dirname + '/uploads/default-image';
module.exports = {
path: imagePath
defaultPath: imagePath
}
// Gets inputs
const { _id, name, newPassword, newPassword2 } = req.body;
let { _id, name, newPassword, newPassword2 } = req.body;
let errors = [];
let useName = true;
let useNewPassword = true;
@@ -55,6 +110,11 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
useName = false;
}
if (filter.isProfane(name)) {
errors.push({ msg: "Name contains profanity" });
name = filter.clean(name);
}
if (!newPassword) {
if (newPassword2.length > 0) {
errors.push({ msg: 'You need to enter your new password' })
@@ -81,13 +141,22 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
}
}
if (filter.isProfane(newPassword)) {
errors.push({ msg: "Password contains profanity" });
newPassword = filter.clean(newPassword);
}
if (filter.isProfane(newPassword2)) {
errors.push({ msg: "Password contains profanity" });
newPassword2 = filter.clean(newPassword2);
}
// Error Handling
if (errors.length > 0) {
// Redirects to edit page with errors
res.render('edit', {
errors,
name,
currPassword,
newPassword,
newPassword2
});
@@ -106,9 +175,6 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
});
});
console.log(newPassword);
console.log(hashPass);
//creates updated image object
updated = {
name: name,
@@ -151,6 +217,12 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
}
}
}
// Deletes File for its not needed
fs.unlink(path.join(__dirname + '/uploads/' + req.file.filename), function (err) {
if (err) throw err;
});
//Updates user and redirects to dashboard
MongoClient.connect(db, {
useUnifiedTopology: true,
@@ -159,8 +231,6 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
let dbo = db.db("XPmockDB");
dbo.collection('users').updateOne({ _id: ObjectId(_id) }, { $set: updated }, { upsert: true }, function(err, res) {
if (err) throw err;
console.log('1 Document Updated');
console.log('With customImage');
db.close()
});
res.redirect('/users/login');
@@ -168,7 +238,6 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
);
}
catch(err) {
console.log(err);
if (useName && useNewPassword) {
// Encrypts password
bcrypt.genSalt(10, (err, salt) => {
@@ -178,9 +247,6 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
});
});
console.log(newPassword);
console.log(hashPass);
//creates updated image object
updated = {
name: name,
@@ -219,8 +285,6 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
let dbo = db.db("XPmockDB");
dbo.collection('users').updateOne({ _id: ObjectId(_id) }, { $set: updated }, { upsert: true }, function(err, res) {
if (err) throw err;
console.log('1 Document Updated');
console.log('With defaultImage');
db.close()
});
res.redirect('/users/login');
@@ -230,16 +294,16 @@ router.post('/edit', upload.single('image'), (req, res, next) => {
}
});
// Register
router.post('/register', upload.single('image'), (req, res, next) => {
// Register Teacher
router.post('/registerTeacher', upload.single('image'), (req, res, next) => {
// Passes image path to defaultImage Model
path = __dirname + '/uploads/image-1606947471396';
imagePath = __dirname + '/uploads/default-image';
module.exports = {
path: path
defaultPath: imagePath
}
// Collects input
const { name, email, password, password2 } = req.body;
let { name, email, password, password2 } = req.body;
let errors = [];
// Check for blanks
@@ -247,6 +311,160 @@ router.post('/register', upload.single('image'), (req, res, next) => {
errors.push({ msg: 'Please enter all fields' });
}
if (filter.isProfane(name)) {
errors.push({ msg: 'Name contains profanity' });
name = filter.clean(name);
}
if (filter.isProfane(password)) {
errors.push({ msg: "Password contains profanity" })
password = filter.clean(password);
}
if(filter.isProfane(password2)) {
errors.push({ msg: "Password contains profanity" })
password2 = filter.clean(password2);
}
// Check if password is confirmed
if (password != password2) {
errors.push({ msg: 'Passwords do not match' });
}
// Validates password is to required length
if (password.length < 6) {
errors.push({ msg: 'Password must be at least 6 characters' });
}
// Error handling
if (errors.length > 0) {
// Redirects to register page with errors
res.render('register', {
errors,
name,
email,
password,
password2
});
} else {
// Verifies Email isnt taken
User.findOne({ email: email }).then(user => {
if (user) {
errors.push({ msg: 'Email already exists' });
// Redirect to dashboard page with errors
res.render('dashboard', {
errors,
name,
email,
password,
password2
});
} else {
try {
// Creates new User Object
const newUser = new User({
name,
email,
password,
image: {
data: fs.readFileSync(path.join(__dirname + '/uploads/' + req.file.filename)),
contentType: 'image/png'
}
});
// Deletes File for its not needed
fs.unlink(path.join(__dirname + '/uploads/' + req.file.filename), function (err) {
if (err) throw err;
});
// Encrypts password
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(newUser.password, salt, (err, hash) => {
if (err) throw err;
newUser.password = hash;
newUser.role = "Teacher";
newUser
.save()
.then(user => {
req.flash(
'success_msg'
);
// Takes to Dashboard on success
let value = encodeURIComponent('success')
res.redirect('/dashboard?createTeacher=' + value);
})
.catch(err => console.log(err));
});
});
}
catch(err) {
const defaultImage = require('../models/defaultImage').defaultImage;
// Creates new User Object
const newUser = new User({
name,
email,
password,
image: defaultImage
});
// Encrypts password
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(newUser.password, salt, (err, hash) => {
if (err) throw err;
newUser.password = hash;
newUser.role = "Teacher";
newUser
.save()
.then(user => {
req.flash(
'success_msg'
);
// Takes to Dashboard on success
let value = encodeURIComponent('success')
res.redirect('/dashboard?createTeacher=' + value);
})
.catch(err => console.log(err));
});
});
}
}
});
}
});
// Register
router.post('/register', upload.single('image'), (req, res, next) => {
// Passes image path to defaultImage Model
imagePath = __dirname + '/uploads/default-image';
module.exports = {
defaultPath: imagePath
}
// Collects input
let { name, email, password, password2 } = req.body;
let errors = [];
// Check for blanks
if (!name || !email || !password || !password2) {
errors.push({ msg: 'Please enter all fields' });
}
if(filter.isProfane(name)) {
errors.push({ msg: "Name contains profanity" });
name = filter.clean(name);
}
if(filter.isProfane(password)) {
errors.push({ msg: "Password contains profanity" });
password = filter.clean(password);
}
if(filter.isProfane(password2)) {
errors.push({ msg: "Password contains profanity" });
password2 = filter.clean(password2);
}
// Check if password is confirmed
if (password != password2) {
errors.push({ msg: 'Passwords do not match' });
@@ -294,6 +512,11 @@ router.post('/register', upload.single('image'), (req, res, next) => {
}
});
// Deletes File for its not needed
fs.unlink(path.join(__dirname + '/uploads/' + req.file.filename), function (err) {
if (err) throw err;
});
// Encrypts password
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(newUser.password, salt, (err, hash) => {
+323
View File
@@ -0,0 +1,323 @@
<!-- Simple Styling for layout -->
<style>
.members {
width: 230px;
display: inline-block;
}
.buttons-container {
position: absolute;
width: 174px;
height: 500px;
top: 25px;
right: 25px;
border: solid #5b94f0 2px;
border-style: solid;
border-radius: 10px;
background-color: rgba(112, 196, 255, .3);
}
#newTeacher-btn {
margin-left: 25px;
margin-top: 10px;
}
#logout-btn {
margin-left: 50px;
margin-top: 10px;
}
#user-pro-pic {
position: absolute;
top: 0px;
left: 150px;
width: 50px;
height: 50px;
display: block;
border-radius: 50px;
border: 1px solid black;
margin:5px;
}
h2 {
font: 350 35px/1.5 Helvetica, Verdana, sans-serif;
margin: 0;
padding: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
font: 200 20px/1.5 Helvetica, Verdana, sans-serif;
border-bottom: 1px solid #ccc;
}
li:last-child {
border: none;
}
li a {
text-decoration: none;
color: #000;
display: block;
width: 200px;
-webkit-transition: font-size 0.3s ease, background-color 0.3s ease;
-moz-transition: font-size 0.3s ease, background-color 0.3s ease;
-o-transition: font-size 0.3s ease, background-color 0.3s ease;
-ms-transition: font-size 0.3s ease, background-color 0.3s ease;
transition: font-size 0.3s ease, background-color 0.3s ease;
}
li a:hover {
font-size: 30px;
background: #f6f6f6;
}
</style>
<!-- Header -->
<h1 class="mt-4">Site Admin</h1>
<div class='head'>
<div id='teacher-container'>
<div>
<p id='welcome' class="lead mb-3">Welcome Admin</p>
</div>
<br>
<div class="buttons-container">
<!-- Action Buttons -->
<a id='logout-btn' href="/users/logout" class="btn btn-secondary">Logout</a>
<!-- Button trigger modal -->
<button id="newTeacher-btn" onClick='openModal()' type="button" class="btn btn-outline-info btn-sm">
Create New Teacher
</button>
</div>
</div>
</div>
<script>
function openModal() {
$("#exampleModal").modal()
}
// Creates unique ID
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
// Create Div
function createDiv(type, message) {
let id = makeid(8);
if (type == 'error') {
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none;" class="alert alert-warning alert-dismissible fade show" role="alert">';
}
if (type == 'message') {
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none;" class="alert alert-info alert-dismissible fade show" role="alert">';
}
document.getElementById('new-div-'+id).innerHTML += '<div id="message'+id+'">'+message+'</div>';
document.getElementById('new-div-'+id).innerHTML += '<button id="close-btn-'+id+'" class="close" data-dismiss="alert" aria-label="Close"></button>';
document.getElementById('close-btn-'+id).innerHTML += '<span aria-hidden="true">&times;</span>';
document.getElementById('new-div-'+id).style.display = "block";
}
</script>
<!-- Catching url Parameters -->
<script>
window.onload = function () {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const isSuccess = urlParams.get('createTeacher')
if(isSuccess == 'success') {
createDiv('message', 'Successfully Created Teacher')
}
}
</script>
<!-- Sets Variables for calculating users data -->
<div>
<script>
let xp;
let currRank;
let ranks = [
{"Digital Noob": 0}, // index 0
{"Digital Novice": 48}, // index 1
{"Digital Novice II": 100}, // index 2
{"Digital Amature": 148}, // index 3
{"Digital Amature II": 200}, // index 4
{"Digital Apprentice": 248}, // index 5
{"Digital Apprentice II": 300}, // index 6
{"Digital Journeyman": 396}, // index 7
{"Digital Journeyman II": 476}, // index 8
{"Digital Journeyman III": 532}, // index 9
{"Digital Crafter": 580}, // index 10
{"Expert Digital Crafter": 648}, // index 11
{"Master Digital Crafter": 800} // index 12
]
let indexes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12]
// Students should't be on this page sooooo...
console.log("Students Also Shouldnt be here");
</script>
<!-- Alert container -->
<div id='div-container'></div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Create New Teacher</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<% include ./partials/messages %>
<form action="/users/registerTeacher" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Name</label>
<input
type="name"
id="name"
name="name"
class="form-control"
placeholder="Enter Name"
value="<%= typeof name != 'undefined' ? name : '' %>"
/>
</div>
<div class="form-group">
<label for='image'>Upload Profile Picture</label>
<input class="form-control-file" type="file" id="image" name="image" value="">
</div>
<div class="form-group">
<label for="email">Email</label>
<input
type="email"
id="email"
name="email"
class="form-control"
placeholder="Enter Email"
value="<%= typeof email != 'undefined' ? email : '' %>"
/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input
type="password"
id="password"
name="password"
class="form-control"
placeholder="Create Password"
value="<%= typeof password != 'undefined' ? password : '' %>"
/>
</div>
<div class="form-group">
<label for="password2">Confirm Password</label>
<input
type="password"
id="password2"
name="password2"
class="form-control"
placeholder="Confirm Password"
value="<%= typeof password2 != 'undefined' ? password2 : '' %>"
/>
</div>
<button type="submit" class="btn btn-primary btn-block">
Register Teacher
</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- List of all site students and teachers -->
<div class='members'>
<h2>All Site Members</h2>
<ul>
<!-- Loops through all members -->
<% members.forEach(function (member) { %>
<% if (member.role == "Student") { %>
<!-- Creates User Button link -->
<li><button class='btn btn-link mt-2' onclick='openProfile("<%= member.id %>")'><%= member.name %></button></li>
<!-- Creates hidden Div with user specific Data -->
<div style='display: none; position: relative;' data-role='page' id='<%= member._id %>'>
<img id='user-pro-pic' src='data:image/<%=member.image.contentType%>;base64,<%=member.image.data.toString('base64')%>'>
<p id='memberName' class='lead mb-3'><%= member.name %></p>
<p class='lead mb-3'><%= member.email %></p>
<div>
<p id='userRank-<%= member.id %>'></p>
<p>XP: <%= member.xp %></p>
<p><%= member.role %></p>
</div>
<br>
<!-- Calculates user specific Rank -->
<script>
xp = <%= member.xp %>;
// Get current rank
if (xp == 0) {
currRank = 'Digital Noob';
} else {
if (xp < 800 && xp > 0) {
for(var i = 0; i < ranks.length; i++) {
for (let rank in ranks[i]) {
let nextIndex = indexes[i];
for (let nextRank in ranks[nextIndex]) {
if (xp >= ranks[i][rank] && xp < ranks[nextIndex][nextRank]) {
currRank = rank;
}
}
}
}
} else {
if (xp == 800) {
currRank = "Master Digital Crafter";
}
}
}
// Display Rank
document.getElementById('userRank-<%= member.id %>').innerHTML = currRank;
</script>
</div>
<% } %>
<% if (member.role == "Teacher") { %>
<!-- Creates User Button link -->
<li><button class='btn btn-link mt-2' onclick='openProfile("<%= member.id %>")'><%= member.name %></button></li>
<!-- Creates hidden Div with user specific Data -->
<div style='display: none; position: relative;' data-role='page' id='<%= member._id %>'>
<img id='user-pro-pic' src='data:image/<%=member.image.contentType%>;base64,<%=member.image.data.toString('base64')%>'>
<p id='memberName' class='lead mb-3'><%= member.name %></p>
<p class='lead mb-3'><%= member.email %></p>
<div>
<p><%= member.role %></p>
</div>
<br>
</div>
<% } %>
<% }) %>
</ul>
</div>
</div>
<!-- Script for show/hide user profile data -->
<script>
function openProfile(id) {
let state = document.getElementById(id).style.display;
if (state == "block") {
document.getElementById(id).style.display = 'none';
} else {
document.getElementById(id).style.display = 'block';
}
}
</script>
+3
View File
@@ -1,4 +1,7 @@
<!-- Shows user specific Dashboard -->
<% if (user.role == "Admin") { %>
<% include admin %>
<% } %>
<% if (user.role == "Teacher") { %>
<% include teacherDashboard %>
<% } %>
+1 -1
View File
@@ -34,7 +34,7 @@
</div>
<div class='form-group'>
<label for='image'>Upload Profile Picture</label>
<input class='form-control' type="file" id="image" name="image" value="">
<input class='form-control-file' type="file" id="image" name="image" value="">
</div>
<div class="form-group">
<label for="password2">New Password</label>
+6 -4
View File
@@ -5,15 +5,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<link
rel="stylesheet"
href="https://bootswatch.com/4/journal/bootstrap.min.css"
/>
<link rel="stylesheet" href="https://bootswatch.com/4/journal/bootstrap.min.css"/>
<title>XP-System</title>
</head>
<body>
<div class="container"><%- body %></div>
<!-- Load Scripts for Modal -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
-4
View File
@@ -17,10 +17,6 @@
value="<%= typeof name != 'undefined' ? name : '' %>"
/>
</div>
<div class='form-group'>
<label for='image'>Upload Profile Picture</label>
<input class='form-control' type="file" id="image" name="image" value="" required>
</div>
<div class="form-group">
<label for='image'>Upload Profile Picture</label>
<input class="form-control-file" type="file" id="image" name="image" value="">
+47 -9
View File
@@ -2,32 +2,62 @@
<style>
#myProgress {
position: relative;
height: 150px;
width: 150px;
height: 200px;
width: 200px;
background-color: #ddd;
border-style: solid;
border-color: rgba(0, 0, 0, .5);
border-color: rgba(0, 0, 0, .4);
border-radius: 12px;
overflow: hidden;
}
#myBar {
position: absolute;
bottom: 0px;
left: 0px;
width: 145px;
width: 100%;
height: 1%;
background-color: #46c7f2;
}
#pro-pic {
position: absolute;
margin: 27px;
width: 90px;
height: 90px;
top: 25px;
left: 23px;
width: 150px;
height: 150px;
display: block;
border-radius: 50px;
border-style: solid;
border-width: 5px;
border-radius: 100px;
border-color: rgba(0, 0, 0, .4);
}
.buttons-container {
width: 100px;
height: 80px;
}
.buttons-content {
margin: 5px;
margin-top: 5px;
}
.student-container {
position: absolute;
width: 400px;
height: 700px;
top: 25px;
left: 25px;
border: solid #5b94f0 2px;
border-style: solid;
border-radius: 10px;
background-color: rgba(112, 196, 255, .3);
}
.content {
margin-left: 25px;
}
</style>
<div class="student-container">
<div class='content'>
<!-- Welcome message & Profile Picture/Progress bar -->
<h1 class="mt-4">Student Dashboard</h1>
<p class="lead mb-3">Welcome <%= user.name %></p>
@@ -48,11 +78,16 @@
<p id='XP-Till'></p>
</div>
<br>
<br>
<div class="buttons-container">
<div class="buttons-content">
<!-- Action Buttons -->
<a href="/users/logout" class="btn btn-secondary">Logout</a>
<button onClick='passData()' class='btn btn-secondary'>Edit</button>
</div>
</div>
</div>
</div>
<!-- Passing user _id to edit page script -->
<script>
@@ -123,6 +158,9 @@
currRank = "Master Digital Crafter";
remain = 0;
rankUp = 'No higher Rank, Good Job!';
let elem = document.getElementById("myBar");
let percent = 100;
elem.style.height = percent + '%';
}
// Display Data
+156 -12
View File
@@ -7,8 +7,10 @@
.head {
margin-bottom: 100px;
}
#teacher-container {
position: relative;
.teacher-container {
position: absolute;
width: 300px;
left: 205px;
}
#pro-pic {
position: absolute;
@@ -31,15 +33,26 @@
border: 1px solid black;
margin:5px;
}
#logout-btn {
.buttons-container {
position: absolute;
top: 0px;
right: 0px;
width: 151px;
height: 500px;
top: 25px;
right: 25px;
border: solid #5b94f0 2px;
border-style: solid;
border-radius: 10px;
background-color: rgba(112, 196, 255, .3);
}
#edit-btn {
position: absolute;
top: 0px;
right: 85px;
width: 95px;
margin-left: 28px;
margin-top: 10px;
}
#logout-btn {
width: 95px;
margin-left: 28px;
margin-top: 10px;
}
#welcome {
position: absolute;
@@ -83,17 +96,19 @@
<!-- Welcome Message & Profile Picture -->
<h1 class="mt-4">Teacher Dashboard</h1>
<div class='head'>
<div id='teacher-container'>
<div>
<div class="teacher-container">
<p id='welcome' class="lead mb-3">Welcome <%= user.name %></p>
<img id='pro-pic' src='data:image/<%=user.image.contentType%>;base64,
<%=user.image.data.toString('base64')%>'>
</div>
<br>
<div class="buttons-container">
<!-- Action Buttons -->
<a id='logout-btn' href="/users/logout" class="btn btn-secondary">Logout</a>
<button id='edit-btn' onClick='passData()' class='btn btn-secondary'>Edit</button>
<a id='logout-btn' href="/users/logout" class="btn btn-info">Logout</a>
<button id='edit-btn' onClick='passData()' class='btn btn-info'>Edit</button>
</div>
<!-- Passing user _id to edit page script -->
<script>
@@ -133,8 +148,131 @@
console.log("Students Shouldnt be here");
</script>
<!-- Alert container -->
<div id='div-container'></div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form action="/users/addXP" method="POST">
<div>
<input id='_id_add' type='text' name='_id_add' value='' style='display: none'></input>
<input id="current_xp" type="text" name="current_xp" value="" style="display: none"></input>
</div>
<div>
<p>Minimum: 1</p>
<p>Maximum: 50</p>
</div>
<div class="form-group">
<label for="amount">Amount</label>
<input
id="amount"
name="amount"
type="number"
min="1"
max="50"
value=""
class="form-control"
>
</div>
<button type="submit" class="btn btn-primary">
Add XP
</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
// Creates unique ID
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
// Create Div
function createDiv(type, message) {
let id = makeid(8);
if (type == 'error') {
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none;" class="alert alert-warning alert-dismissible fade show" role="alert">';
}
if (type == 'message') {
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none;" class="alert alert-info alert-dismissible fade show" role="alert">';
}
document.getElementById('new-div-'+id).innerHTML += '<div id="message'+id+'">'+message+'</div>';
document.getElementById('new-div-'+id).innerHTML += '<button id="close-btn-'+id+'" class="close" data-dismiss="alert" aria-label="Close"></button>';
document.getElementById('close-btn-'+id).innerHTML += '<span aria-hidden="true">&times;</span>';
document.getElementById('new-div-'+id).style.display = "block";
}
// // Check amount
// function amountCheck(_id) {
// const amount = document.getElementById("amount").value;
// if (amount > 50) {
// createDiv('error', "Can't add more than 50 XP");
// }
// if (amount == 0 || amount < 0) {
// createDiv('error', "XP Must be more than 0");
// }
//
// if (amount > 0 && amount < 50) {
//
// createDiv('message', "Succesfully added XP");
// }
// }
// Pass name to Modal
function passName(name, xp, member_id) {
if (xp < 800) {
document.getElementById("exampleModalLabel").innerHTML = "Give " + name + " XP";
document.getElementById("_id_add").value = member_id;
document.getElementById("current_xp").value = xp;
$("#exampleModal").modal()
}
if (xp >= 800) {
// Construct and show Max XP Alert
message = name + ' has reached max XP!';
createDiv('message', message);
}
}
// Catching url Parameters
window.onload = function () {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const successRate = urlParams.get('successRate')
if(successRate == 'addXP > 50') {
createDiv('error', "Can't add more than 50 XP")
}
if(successRate == 'addXP <= 0') {
createDiv('error', "XP Must be Greater than 0");
}
if(parseInt(successRate) > 0 && parseInt(successRate) < 50 || parseInt(successRate) == 50) {
createDiv('message', "Gave " + successRate + "XP to a Student");
}
}
</script>
<!-- List of all site students (not teachers) -->
<h2>Site Members</h2>
<h2>Studen Members</h2>
<div class='members'>
<ul>
<!-- Loops through all members -->
@@ -153,6 +291,12 @@
<div>
<p id='userRank-<%= member.id %>'></p>
<p>XP: <%= member.xp %></p>
<!-- Button trigger modal -->
<button onClick='passName("<%= member.name %>", <%= member.xp %>, "<%= member._id %>")' type="button" class="btn btn-outline-info btn-sm">
Add XP
</button>
<p><%= member.role %></p>
</div>
<br>