diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 08461f8..e0f3b60 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -2,4 +2,5 @@ Flask mysql-python Flask-SQLAlchemy SQLAlchemy -gunicorn \ No newline at end of file +gunicorn +requests \ No newline at end of file diff --git a/server/api/user.py b/server/api/user.py index f80a0db..be8bf1f 100644 --- a/server/api/user.py +++ b/server/api/user.py @@ -4,6 +4,7 @@ from flask import current_app as app from models import db, Users from utils import api_wrapper +import requests import utils blueprint = Blueprint("user", __name__) @@ -11,13 +12,16 @@ blueprint = Blueprint("user", __name__) @blueprint.route("/register", methods=["POST"]) @api_wrapper def user_register(): + if not validate_captcha(request.form): + return { "success": 0, "message": "Please do the captcha." } + name = request.form["name"] username = request.form["username"] password = request.form["password"] password_confirm = request.form["password_confirm"] email = request.form["email"] - username_exists = Users.query.add_columns("name", "uid").filter_by(username=username).first() + username_exists = Users.query.add_columns("name", "uid").filter_by(username_lower=username.lower()).first() email_exists = Users.query.add_columns("name", "uid").filter_by(email=email).first() if password != password_confirm: @@ -59,3 +63,13 @@ def add_user(name, username, email, password): user = Users(name, username, email, password) db.session.add(user) db.session.commit() + +def validate_captcha(form): + if "captcha_response" not in form: + return False + captcha_response = form["captcha_response"] + data = {"secret": "6Lc4xhMTAAAAACFaG2NyuKoMdZQtSa_1LI76BCEu", "response": captcha_response} + response = requests.post("https://www.google.com/recaptcha/api/siteverify", data=data) + if response.json()["success"]: + return True + return False diff --git a/web/about.html b/web/about.html index 58c0fbe..7ebbe01 100644 --- a/web/about.html +++ b/web/about.html @@ -13,6 +13,7 @@ Register