easyctf-2017/server/api/models.py

74 lines
2.3 KiB
Python
Raw Normal View History

2015-12-23 06:26:27 +00:00
from flask.ext.sqlalchemy import SQLAlchemy
2015-12-23 23:23:18 +00:00
import utils
2015-12-23 06:26:27 +00:00
2015-12-23 19:49:31 +00:00
db = SQLAlchemy()
2015-12-23 23:06:44 +00:00
class Users(db.Model):
2015-12-24 00:40:59 +00:00
uid = db.Column(db.Integer, primary_key=True)
tid = db.Column(db.Integer)
name = db.Column(db.String(64))
username = db.Column(db.String(64), unique=True)
username_lower = db.Column(db.String(64), unique=True)
email = db.Column(db.String(64), unique=True)
password = db.Column(db.String(128))
2016-01-02 22:55:30 +00:00
admin = db.Column(db.Boolean, default=False)
2015-12-24 00:40:59 +00:00
2015-12-24 02:06:49 +00:00
def __init__(self, name, username, email, password):
2015-12-24 00:40:59 +00:00
self.name = name
self.username = username
self.username_lower = username.lower()
self.email = email.lower()
self.password = utils.hash_password(password)
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)
2015-12-24 02:06:49 +00:00
school = db.Column(db.Text)
2015-12-24 00:40:59 +00:00
size = db.Column(db.Integer)
score = db.Column(db.Integer)
observer = db.Column(db.Boolean)
owner = db.Column(db.Integer)
def __init__(self, name, school):
self.name = name
self.school = school
class Problems(db.Model):
pid = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))
2016-01-02 04:18:40 +00:00
category = db.Column(db.String(128))
2015-12-24 00:40:59 +00:00
description = db.Column(db.Text)
hint = db.Column(db.Text)
flag = db.Column(db.Text)
2016-01-02 22:55:30 +00:00
disabled = db.Column(db.Boolean, default=False)
2015-12-24 00:40:59 +00:00
value = db.Column(db.Integer)
2016-01-02 22:55:30 +00:00
solves = db.Column(db.Integer, default=0)
2015-12-24 00:40:59 +00:00
2016-01-02 04:18:40 +00:00
def __init__(self, name, category, description, hint, flag, value):
2015-12-24 00:40:59 +00:00
self.name = name
2016-01-02 04:18:40 +00:00
self.category = category
2015-12-24 00:40:59 +00:00
self.description = description
self.hint = hint
self.flag = flag
self.value = value
2016-01-02 20:45:05 +00:00
class Files(db.Model):
fid = db.Column(db.Integer, primary_key=True)
pid = db.Column(db.Integer)
location = db.Column(db.Text)
def __init__(self, pid, location):
self.pid = pid
self.location = location
2015-12-24 00:40:59 +00:00
class Solves(db.Model):
sid = db.Column(db.Integer, primary_key=True)
pid = db.Column(db.Integer)
tid = db.Column(db.Integer)
date = db.Column(db.Integer, default=utils.get_time_since_epoch())
def __init__(self, pid, tid):
self.pid = pid
self.tid = tid