예제 #1
0
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)
예제 #2
0
class Item(db.Model):
    __tablename__ = "items"

    id = db.Column(db.Integer, nullable=False)
    site = db.Column(db.String(length=16), nullable=False)
    price = db.Column(db.Float)
    start_time = db.Column(db.DateTime)
    name = db.Column(db.String(length=128))
    description = db.Column(db.String(length=64))
    nickname = db.Column(db.String(length=50))

    __table_args__ = (db.PrimaryKeyConstraint('site', 'id'), {})

    @classmethod
    def create_item(cls, site, id, db_session=None):
        item = Item(site=site, id=id)

        if db_session:
            db_session.add(item)
        else:
            db.session.add(item)

        if db_session:
            db_session.commit()
        else:
            db.session.commit()

        return item

    @classmethod
    def get_or_create_item(cls, site, id, db_session=None):
        item = cls.get_item(site, id)
        if not item:
            item = cls.create_item(site, id, db_session)

        return item

    @classmethod
    def get_item(cls, site, id):
        item = cls.query.filter(cls.site == site).filter(cls.id == id)
        return item.first()

    def __str__(self):
        return "{"\
               f"'id':'{self.id}'"\
               f", 'site':'{self.site}'"\
               f", 'price':'{self.price}'"\
               f", 'name':'{self.name}'"\
               f", 'description':'{self.description}'"\
               f", 'nickname':'{self.nickname}'"\
               "}"
예제 #3
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)
예제 #4
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)
예제 #5
0
class Photo(Base,CRUDMixin):
    __tablename__='photo'
    uuid = db.Column(db.String(128), nullable=False)
    filepath = db.Column(db.String(500), nullable=False)
    analysed = db.Column(db.Boolean,default=False)
    info = db.Column(db.String(1000),nullable=False)


    def __init__(self,uuid,filepath,analysed=False,info=""):
	self.uuid = uuid
	self.filepath = filepath
        self.analysed=analysed
        self.info=info

    def get_id(self):
        return self.id

    def serialize(self):
	return {'uuid':self.uuid}
    def serialize_all(self):
        return {'uuid':self.uuid, 'filepath': self.filepath, 'analysed': self.analysed, 'info': self.info}
    def __repr__(self):
	return '<photo uuid=%r filepath=%r>' % (self.uuid,self.filepath)
예제 #6
0
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,
        )
예제 #7
0
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