Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profanity check #577

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apis/users_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pymysql.cursors import DictCursor

from wikispeedruns.auth import passwords
from wikispeedruns.profanity_check import profanity_check_func

user_api = Blueprint("users", __name__, url_prefix="/api/users")

Expand Down Expand Up @@ -144,6 +145,9 @@ def create_user():
# Validate username
if (not _valid_username(username)):
return "Invalid username", 400
# profanity check
if profanity_check_func(username):
return ("Please use clean language in username", 406)

# Use SHA256 to allow for arbitrary length passwords
hash = passwords.hash_password(password)
Expand Down Expand Up @@ -306,6 +310,9 @@ def change_username():

id = session["user_id"]
new_username = request.json["new_username"]
# profanity check
if profanity_check_func(new_username):
return ("Please use clean language in username", 406)

db = get_db()
with db.cursor(cursor=DictCursor) as cursor:
Expand Down
3 changes: 3 additions & 0 deletions frontend/static/js/pages/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ var app = new Vue({
if (response.status === 200) {
window.location.reload();
}
else if (response.status === 406) {
alert(await response.text());
}
this.feedbackMsg = await response.text()
} catch (e) {
console.log(e);
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bcrypt>=3.2.0
Flask-Dance==7.0.1
itsdangerous==2.1.2
pytest==6.2.5
alt-profanity-check==1.3.2

celery[redis]

Expand Down
12 changes: 12 additions & 0 deletions wikispeedruns/profanity_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from profanity_check import predict


def profanity_check_func(word):
'''
Profanity check for a word
'''
profanity = predict([word])
if profanity[0]:
return 1
else:
return 0
Loading