Ejemplo n.º 1
0
class UserLogin(db.Model):
    __tablename__ = 'User_Login'
    __table_args__ = {"schema": "sys"}

    userID = db.Column(db.Integer, primary_key=True)
    accName = db.Column(db.String(120), unique=True)
    displayName = db.Column(db.String(30))
    pwHash = db.Column(db.String(120))

    def __init__(self, accName, displayName, pwHash):
        self.accName = accName
        self.displayName = displayName
        self.pwHash = pwHash

    # save user to db
    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    # find user by name
    @classmethod
    def find_by_accName(cls, accName):
        return cls.query.filter_by(accName=accName).first()

    # generate hash from pw
    @staticmethod
    def generate_hash(pwHash):
        return sha256.hash(pwHash)

    # verify hash from pw
    @staticmethod
    def verify_hash(pwHash, hash_):
        return sha256.verify(pwHash, hash_)
Ejemplo n.º 2
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    public_id = db.Column(db.String(50), unique=True, nullable=False)
    username = db.Column(db.String(50), unique=True, nullable=False)
    email = db.Column(db.String(60), unique=True, nullable=False)
    password = db.Column(db.String(20), nullable=False)

    def __init__(self, public_id, username, email, password):
        self.public_id = public_id
        self.username = username
        self.email = email
        self.password = password
Ejemplo n.º 3
0
class SiteInfoEng(db.Model):
    __tablename__ = 'Site_InfoEng'
    __table_args__ = {"schema": "sys"}

    siteInfoENID = db.Column(db.String(4), primary_key=True)
    siteNameEN = db.Column(db.Text)
    siteAreaEN = db.Column(db.Text)
    addrEN = db.Column(db.Text)
    siteID = db.Column(db.String(4), db.ForeignKey('sys.Site_Status.siteID'))

    def __init__(self, siteInfoENID, siteNameEN, siteAreaEN, addrEN, siteID):
        self.siteInfoENID = siteInfoENID
        self.siteNameEN = siteNameEN
        self.siteAreaEN = siteAreaEN
        self.addrEN = addrEN
        self.siteID = siteID
Ejemplo n.º 4
0
class SiteInfo(db.Model):
    __tablename__ = 'Site_Info'
    __table_args__ = {"schema": "sys"}

    siteInfoID = db.Column(db.String(4), primary_key=True)
    siteName = db.Column(db.NVARCHAR(60))
    siteArea = db.Column(db.NVARCHAR(60))
    addr = db.Column(db.NVARCHAR(120))
    siteID = db.Column(db.String(4), db.ForeignKey('sys.Site_Status.siteID'))

    def __init__(self, siteInfoID, siteName, siteArea, addr, siteID):
        self.siteInfoID = siteInfoID
        self.siteName = siteName
        self.siteArea = siteArea
        self.addr = addr
        self.siteID = siteID
Ejemplo n.º 5
0
class SiteData(db.Model):
    __tablename__ = 'Site_Data'
    __table_args__ = {"schema": "sys"}

    siteDataID = db.Column(db.String(4), primary_key=True)
    totalSlot = db.Column(db.Integer)
    Lat = db.Column(db.Float)
    Lng = db.Column(db.Float)
    siteID = db.Column(db.String(4), db.ForeignKey('sys.Site_Status.siteID'))

    def __init__(self, siteDataID, totalSlot, Lat, Lng, siteID):
        self.siteDataID = siteDataID
        self.totalSlot = totalSlot
        self.Lat = Lat
        self.Lng = Lng
        self.siteID = siteID
Ejemplo n.º 6
0
class SiteStatus(db.Model):
    __tablename__ = 'Site_Status'
    __table_args__ = {"schema": "sys"}

    siteID = db.Column(db.String(4), primary_key=True)
    avalBike = db.Column(db.Integer)
    modTime = db.Column(db.String(14))
    act = db.Column(db.Boolean)
    remainSpace = db.Column(db.Integer)
    data = db.relationship("SiteData", backref="Site_Status")
    info = db.relationship("SiteInfo", backref="Site_Status")
    infoEng = db.relationship("SiteInfoEng", backref="Site_Status")

    def __init__(self, siteID, avalBike, modTime, act, remainSpace):
        self.siteID = siteID
        self.avalBike = avalBike
        self.modTime = modTime
        self.act = act
        self.remainSpace = remainSpace
Ejemplo n.º 7
0
class Comments(db.Model):
    __tablename__ = 'Comments'
    __table_args__ = {"schema": "sys"}

    commID = db.Column(db.Integer, primary_key=True)
    commDet = db.Column(db.Text)
    userID = db.Column(db.Integer, db.ForeignKey('sys.User_Login.userID'))
    siteID = db.Column(db.String(4), db.ForeignKey('sys.Site_Status.siteID'))

    def __init__(self, commDet, userID, siteID):
        self.commDet = commDet
        self.userID = userID
        self.siteID = siteID
Ejemplo n.º 8
0
class RevokedTokenModel(db.Model):
    __tablename__ = 'revoked_tokens'
    id = db.Column(db.Integer, primary_key=True)
    # jti stans for JWT ID
    jti = db.Column(db.String(120))

    # Save token to db
    def add(self):
        db.session.add(self)
        db.session.commit()

    # check if token is black listed
    @classmethod
    def is_jti_blacklisted(cls, jti):
        result = RevokedTokenModel.query.filter_by(jti=jti).first()

        schema = RevokedSchema()
        out = schema.dump(result)

        if len(out) < 1:
            return False
        else:
            return True