class Class(db.Model):
    __tablename__ = "class"

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50))
    desc = db.Column(db.String(200))
    users = db.relationship("Access", backref="class", lazy="dynamic")
    students = db.relationship("Class_Student",
                               backref="class",
                               lazy="dynamic")

    def __repr__(self):
        return "<Class: {}>".format(self.title)
class Roll(db.Model):
    __tablename__ = "roll"

    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.DateTime, default=datetime.now())
    class_id = db.Column(db.Integer)
    roll = db.relationship("Roll_Student", backref="roll", lazy="dynamic")
    linked_rfid = db.relationship("Station", back_populates="linked_roll_rel")

    def __repr__(self):
        return "<Roll object Student: {} is in Class: {}>".format(
            self.student_id,
            self.class_id,
        )
Exemple #3
0
class Experiment(CRUDMixin, db.Model):

    id = db.Column(db.Integer, primary_key=True)
    hardware = db.Column(db.Text)
    t_stamp = db.Column(db.DateTime)
    label = db.Column(db.Text)
    sensors = db.relationship('Sensor', backref='experiment', lazy='dynamic')

    def __repr__(self):
        return '<Experiment %r>, <id %r>' % (self.hardware, self.id)
Exemple #4
0
class Site(CRUDMixin, db.Model):
    __tablename__ = 'tracking_site'

    base_url = db.Column(db.String)
    visits = db.relationship('Visit', backref='site', lazy='select')
    user_id = db.Column(db.Integer, db.ForeignKey('users_user.id'))

    def __repr__(self):
        return '<Site {:d} {}>'.format(self.id, self.base_url)

    def __str__(self):
        return self.base_url
class Student(db.Model):
    __tablename__ = "student"

    id = db.Column(db.Integer, primary_key=True)
    student_id = db.Column(db.Integer)
    student_name = db.Column(db.String(50))
    rfid = db.Column(db.Integer)
    roll = db.relationship("Roll_Student", backref="student", lazy="dynamic")

    def __repr__(self):
        return "<Student, id: {}, name: {}, dbId: {}>".format(
            self.student_id,
            self.student_name,
            self.id,
        )
Exemple #6
0
class User(UserMixin, CRUDMixin, db.Model):
    __tablename__ = 'users_user'

    name = db.Column(db.String(50))
    email = db.Column(db.String(120), unique=True)
    _password = db.Column(db.LargeBinary(120))
    _salt = db.Column(db.String(120))
    sites = db.relationship('Site', backref='owner', lazy='dynamic')

    @hybrid_property
    def password(self):
        return self._password

    # In order to ensure that passwords are always stored
    # hashed and salted in our database we use a descriptor
    # here which will automatically hash our password
    # when we provide it (i. e. user.password = "******")
    @password.setter
    def password(self, value):
        # When a user is first created, give them a salt
        if self._salt is None:
            self._salt = bytes(SystemRandom().getrandbits(128))
        self._password = self._hash_password(value)

    def is_valid_password(self, password):
        """Ensure that the provided password is valid.
        We are using this instead of a ``sqlalchemy.types.TypeDecorator``
        (which would let us write ``User.password == password`` and have the incoming
        ``password`` be automatically hashed in a SQLAlchemy query)
        because ``compare_digest`` properly compares **all***
        the characters of the hash even when they do not match in order to
        avoid timing oracle side-channel attacks."""
        new_hash = self._hash_password(password)
        return compare_digest(new_hash, self._password)

    def _hash_password(self, password):
        pwd = password.encode("utf-8")
        salt = bytes(self._salt)
        rounds = current_app.config.get("HASH_ROUNDS", 100000)
        buff = pbkdf2_hmac("sha512", pwd, salt, iterations=rounds)
        return bytes(buff)

    def __repr__(self):
        return "<User #{:d}>".format(self.id)
Exemple #7
0
class User(db.Model, UserMixin):
    __tablename__ = "user"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), nullable=True)
    password_hash = db.Column(db.String(128))
    logins = db.Column(db.Integer, default=0)
    classes = db.relationship("Access", backref="user", lazy="dynamic")

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def set_password(self, password):
        """Runs the passwords through a hash and appends."""
        self.password_hash = generate_password_hash(str(password))

    def check_password(self, password):
        """Checks a password against the hash."""
        return check_password_hash(self.password_hash, password)
class Station(db.Model):
    __tablename__ = "station"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))
    password_hash = db.Column(db.String(128))
    linked_roll = db.Column(db.Integer, db.ForeignKey('roll.id'))
    linked_roll_rel = db.relationship("Roll", back_populates="linked_rfid")
    scan = db.Column(db.Integer)
    active = db.Column(db.Boolean, default=False)

    def __repr__(self):
        return '<Station {}>'.format(self.name)

    def set_password(self, password):
        """Runs the passwords through a hash and appends."""
        self.password_hash = generate_password_hash(str(password))

    def check_password(self, password):
        """Checks a password against the hash."""
        return check_password_hash(self.password_hash, password)

    def get_scan(self):
        return self.scan if not self.active else None