Esempio n. 1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(40), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)
    isAdmin = db.Column(db.Boolean, default=False)
    score = db.relationship('Score', backref='user', lazy=True, uselist=False)
    if LOGGING:
        logs = db.relationship('Logs',
                               backref='user',
                               lazy=True,
                               uselist=False)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except Exception:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}'))"
Esempio n. 2
0
class Notification(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(30), nullable=False)
    body = db.Column(db.TEXT(), nullable=False)
    timestamp = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return f"Notif('{self.title}', '{self.body}')"
Esempio n. 3
0
class Score(db.Model):
    userid = db.Column(db.Integer, primary_key=True)
    userHash = db.Column(db.Boolean, default=False)
    rootHash = db.Column(db.Boolean, default=False)
    score = db.Column(db.Integer)
    timestamp = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return f"Score('{self.userid}', '{self.score}')"
Esempio n. 4
0
class Score(db.Model):
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False,
                        primary_key=True)
    userHash = db.Column(db.Boolean, default=False)
    rootHash = db.Column(db.Boolean, default=False)
    points = db.Column(db.Integer)
    timestamp = db.Column(db.DateTime(), default=datetime.utcnow)

    def __repr__(self):
        return f"Score('{self.user_id}', '{self.points}')"
Esempio n. 5
0
class Machine(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    user_hash = db.Column(db.String(32), nullable=False)
    root_hash = db.Column(db.String(32), nullable=False)
    user_points = db.Column(db.Integer, default=0)
    root_points = db.Column(db.Integer, default=0)
    os = db.Column(db.String(16), nullable=False)
    ip = db.Column(db.String(45), nullable=False)
    hardness = db.Column(db.String(16), nullable=False, default="Easy")

    score = db.relationship('Score', backref='machine', lazy=True)
Esempio n. 6
0
    class Logs(db.Model):
        user_id = db.Column(db.Integer,
                            db.ForeignKey('user.id'),
                            nullable=False,
                            primary_key=True)
        accountCreationTime = db.Column(db.DateTime, nullable=False)
        visitedMachine = db.Column(db.Boolean, default=False)
        machineVisitTime = db.Column(db.DateTime, nullable=True)
        userSubmissionTime = db.Column(db.DateTime, nullable=True)
        rootSubmissionTime = db.Column(db.DateTime, nullable=True)
        userOwnTime = db.Column(db.String, nullable=True)
        rootOwnTime = db.Column(db.String, nullable=True)
        userSubmissionIP = db.Column(db.String, nullable=True)
        rootSubmissionIP = db.Column(db.String, nullable=True)

        def __repr__(self):
            return f"Logs('{self.user_id}','{self.visitedMachine}'"
Esempio n. 7
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(40), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}')"