2015-12-23 06:26:27 +00:00
|
|
|
from flask.ext.sqlalchemy import SQLAlchemy
|
2016-01-07 00:23:43 +00:00
|
|
|
import time
|
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):
|
2016-01-06 06:15:57 +00:00
|
|
|
uid = db.Column(db.Integer, unique=True, 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-06 06:35:59 +00:00
|
|
|
admin = db.Column(db.Boolean)
|
2016-01-06 06:15:57 +00:00
|
|
|
utype = db.Column(db.Integer)
|
2016-01-07 00:23:43 +00:00
|
|
|
tid = db.Column(db.Integer)
|
|
|
|
registertime = db.Column(db.Integer)
|
2015-12-24 00:40:59 +00:00
|
|
|
|
2016-01-06 06:15:57 +00:00
|
|
|
def __init__(self, name, username, email, password, utype=1):
|
|
|
|
self.name = name
|
|
|
|
self.username = username
|
|
|
|
self.username_lower = username.lower()
|
|
|
|
self.email = email.lower()
|
|
|
|
self.password = utils.hash_password(password)
|
|
|
|
self.utype = utype
|
2016-01-06 06:35:59 +00:00
|
|
|
self.admin = False
|
2016-01-07 00:23:43 +00:00
|
|
|
self.registertime = int(time.time())
|
2015-12-24 00:40:59 +00:00
|
|
|
|
|
|
|
class Teams(db.Model):
|
2016-01-06 06:15:57 +00:00
|
|
|
tid = db.Column(db.Integer, primary_key=True)
|
2016-01-12 03:54:26 +00:00
|
|
|
teamname = db.Column(db.String(64), unique=True)
|
|
|
|
teamname_lower = db.Column(db.String(64), unique=True)
|
2016-01-06 06:15:57 +00:00
|
|
|
school = db.Column(db.Text)
|
|
|
|
owner = db.Column(db.Integer)
|
2015-12-24 00:40:59 +00:00
|
|
|
|
2016-01-12 03:54:26 +00:00
|
|
|
def __init__(self, teamname, owner):
|
|
|
|
self.teamname = teamname
|
|
|
|
self.teamname_lower = teamname.lower()
|
|
|
|
self.owner = owner
|
|
|
|
|
|
|
|
def get_members(self):
|
|
|
|
members = [ ]
|
|
|
|
for member in Users.query.filter_by(tid=self.tid).all():
|
|
|
|
members.append({
|
|
|
|
"username": member.username
|
|
|
|
})
|
|
|
|
return members
|
2015-12-24 00:40:59 +00:00
|
|
|
|
|
|
|
class Problems(db.Model):
|
2016-01-06 06:15:57 +00:00
|
|
|
pid = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.String(128))
|
|
|
|
category = db.Column(db.String(128))
|
|
|
|
description = db.Column(db.Text)
|
|
|
|
hint = db.Column(db.Text)
|
|
|
|
flag = db.Column(db.Text)
|
|
|
|
disabled = db.Column(db.Boolean, default=False)
|
|
|
|
value = db.Column(db.Integer)
|
|
|
|
solves = db.Column(db.Integer, default=0)
|
2015-12-24 00:40:59 +00:00
|
|
|
|
2016-01-06 06:15:57 +00:00
|
|
|
def __init__(self, name, category, description, hint, flag, value):
|
|
|
|
self.name = name
|
|
|
|
self.category = category
|
|
|
|
self.description = description
|
|
|
|
self.hint = hint
|
|
|
|
self.flag = flag
|
|
|
|
self.value = value
|
2015-12-24 00:40:59 +00:00
|
|
|
|
2016-01-02 20:45:05 +00:00
|
|
|
class Files(db.Model):
|
2016-01-06 06:15:57 +00:00
|
|
|
fid = db.Column(db.Integer, primary_key=True)
|
|
|
|
pid = db.Column(db.Integer)
|
|
|
|
location = db.Column(db.Text)
|
2016-01-02 20:45:05 +00:00
|
|
|
|
2016-01-06 06:15:57 +00:00
|
|
|
def __init__(self, pid, location):
|
|
|
|
self.pid = pid
|
|
|
|
self.location = location
|
2016-01-02 20:45:05 +00:00
|
|
|
|
2015-12-24 00:40:59 +00:00
|
|
|
class Solves(db.Model):
|
2016-01-06 06:15:57 +00:00
|
|
|
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())
|
2015-12-24 00:40:59 +00:00
|
|
|
|
2016-01-06 06:15:57 +00:00
|
|
|
def __init__(self, pid, tid):
|
|
|
|
self.pid = pid
|
|
|
|
self.tid = tid
|
|
|
|
|
|
|
|
##########
|
|
|
|
# TOKENS #
|
|
|
|
##########
|
|
|
|
|
|
|
|
class LoginTokens(db.Model):
|
|
|
|
sid = db.Column(db.String(64), unique=True, primary_key=True)
|
|
|
|
uid = db.Column(db.Integer)
|
|
|
|
username = db.Column(db.String(32))
|
|
|
|
active = db.Column(db.Boolean)
|
|
|
|
issued = db.Column(db.Integer)
|
|
|
|
expiry = db.Column(db.Integer)
|
|
|
|
ua = db.Column(db.String(128))
|
|
|
|
ip = db.Column(db.String(16))
|
|
|
|
|
2016-01-07 00:23:43 +00:00
|
|
|
def __init__(self, uid, username, expiry=int(time.time()), active=True, ua=None, ip=None):
|
2016-01-06 06:15:57 +00:00
|
|
|
self.sid = utils.generate_string()
|
|
|
|
self.uid = uid
|
|
|
|
self.username = username
|
2016-01-07 00:23:43 +00:00
|
|
|
self.issued = int(time.time())
|
2016-01-06 06:15:57 +00:00
|
|
|
self.expiry = expiry
|
|
|
|
self.active = active
|
|
|
|
self.ua = ua
|
|
|
|
self.ip = ip
|