Merge branch 'master' of https://www.github.com/failedxyz/easyctf
This commit is contained in:
commit
71c893fd68
4 changed files with 56 additions and 20 deletions
|
@ -13,9 +13,8 @@ class Users(db.Model):
|
|||
password = db.Column(db.String(128))
|
||||
admin = db.Column(db.Boolean)
|
||||
|
||||
def __init__(self, name, tid, username, email, password):
|
||||
def __init__(self, name, username, email, password):
|
||||
self.name = name
|
||||
self.tid = tid
|
||||
self.username = username
|
||||
self.username_lower = username.lower()
|
||||
self.email = email.lower()
|
||||
|
@ -25,7 +24,7 @@ class Teams(db.Model):
|
|||
tid = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(64), unique=True)
|
||||
join_code = db.Column(db.String(128), unique=True)
|
||||
school = db.Column(db.String)
|
||||
school = db.Column(db.Text)
|
||||
size = db.Column(db.Integer)
|
||||
score = db.Column(db.Integer)
|
||||
observer = db.Column(db.Boolean)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
from flask import Blueprint, session
|
||||
from flask import Blueprint, session, request
|
||||
from flask import current_app as app
|
||||
|
||||
from models import db, Users
|
||||
from utils import api_wrapper
|
||||
|
||||
blueprint = Blueprint("user", __name__)
|
||||
|
@ -6,7 +9,31 @@ blueprint = Blueprint("user", __name__)
|
|||
@blueprint.route("/register", methods=["POST"])
|
||||
@api_wrapper
|
||||
def user_register():
|
||||
return { "success": 0, "message": "Registration is not open yet." }
|
||||
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()
|
||||
email_exists = Users.query.add_columns("name", "uid").filter_by(email=email).first()
|
||||
|
||||
if password != password_confirm:
|
||||
return { "success": 0, "message": "Passwords do not match." }
|
||||
if len(password) > 128:
|
||||
return { "success": 0, "message": "Password is too long." }
|
||||
if len(password) == 0:
|
||||
return { "success": 0, "message": "Password is too short." }
|
||||
if len(username) > 64:
|
||||
return { "success": 0, "message": "Username is too long." }
|
||||
if username_exists:
|
||||
return { "success": 0, "message": "Username is already taken." }
|
||||
if email_exists:
|
||||
return { "success": 0, "message": "Email has already been used." }
|
||||
|
||||
add_user(name, username, email, password)
|
||||
|
||||
return { "success": 1, "message": "Success!" }
|
||||
|
||||
@blueprint.route("/logout", methods=["POST"])
|
||||
@api_wrapper
|
||||
|
@ -18,3 +45,8 @@ def user_logout():
|
|||
@api_wrapper
|
||||
def user_login():
|
||||
pass
|
||||
|
||||
def add_user(name, username, email, password):
|
||||
user = Users(name, username, email, password)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
|
|
@ -9,7 +9,15 @@ from api.api import api as api_blueprint
|
|||
from api.user import blueprint as user_blueprint
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
with app.app_context():
|
||||
from api.models import db
|
||||
db.init_app(app)
|
||||
db.create_all()
|
||||
|
||||
app.secret_key = config.SECRET
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLALCHEMY_DATABASE_URI
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS
|
||||
app.register_blueprint(api_blueprint)
|
||||
app.register_blueprint(user_blueprint, url_prefix="/api/user")
|
||||
|
||||
|
@ -26,11 +34,4 @@ if __name__ == "__main__":
|
|||
|
||||
app.debug = keyword_args["debug"]
|
||||
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:i_hate_passwords@localhost/easyctf"
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
|
||||
from api.models import db
|
||||
db.init_app(app)
|
||||
db.create_all()
|
||||
|
||||
app.run(host="0.0.0.0", port=8000)
|
||||
|
|
|
@ -10,5 +10,9 @@ with open(".secret_key", "a+") as secret:
|
|||
key = secret.read()
|
||||
|
||||
SECRET = key
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = "mysql://root:i_hate_passwords@localhost/easyctf"
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
|
||||
CTF_BEGIN = 0 # To be used later
|
||||
CTF_END = 0 # To be used later
|
||||
|
|
Loading…
Reference in a new issue