class Token(db.Model): id = db.Column(db.Integer, primary_key=True) client_id = db.Column( db.Text, db.ForeignKey('client.client_id'), nullable=False, ) client = db.relationship('Client') user_id = db.Column( db.Integer, db.ForeignKey('user.id') ) user = db.relationship('User') # currently only bearer is supported token_type = db.Column(db.String(40)) access_token = db.Column(db.String(255), unique=True) refresh_token = db.Column(db.String(255), unique=True) expires = db.Column(db.DateTime) _scopes = db.Column(db.Text) def delete(self): db.session.delete(self) db.session.commit() return self @property def scopes(self): if self._scopes: return self._scopes.split() return []
class Grant(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column( db.Integer, db.ForeignKey('user.id', ondelete='CASCADE') ) user = db.relationship('User') client_id = db.Column( db.Text, db.ForeignKey('client.client_id'), nullable=False, ) client = db.relationship('Client') code = db.Column(db.String(255), index=True, nullable=False) redirect_uri = db.Column(db.String(255)) expires = db.Column(db.DateTime) _scopes = db.Column('scopes', db.Text) def delete(self): db.session.delete(self) db.session.commit() return self @property def scopes(self): if self._scopes: return self._scopes.split() return []
class Post(db.Model): """Defines the post database model""" id = db.Column(db.Integer, primary_key=True) message = db.Column(db.String(5000)) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref='posts') created_at = db.Column(db.DateTime, default=db.func.now()) updated_at = db.Column(db.DateTime, nullable=True)
class Client(db.Model): # human readable name, not required name = db.Column(db.String(40)) # human readable description, not required description = db.Column(db.String(400)) # creator of the client, not required user_id = db.Column(db.ForeignKey('user.id')) # required if you need to support client credential user = db.relationship('User') client_id = db.Column(db.Text, primary_key=True, server_default=sqlalchemy.text('gen_random_uuid()')) client_secret = db.Column(db.Text, unique=True, index=True, nullable=False) # public or confidential is_confidential = db.Column(db.Boolean) _redirect_uris = db.Column('redirect_uris', db.Text) _default_scopes = db.Column('default_scopes', db.Text) @property def client_type(self): if self.is_confidential: return 'confidential' return 'public' @property def redirect_uris(self): if self._redirect_uris: return self._redirect_uris.split(',') return [] @redirect_uris.setter def redirect_uris(self, redirect_uris): self._redirect_uris = redirect_uris @property def default_redirect_uri(self): return self.redirect_uris[0] @property def default_scopes(self): if self._default_scopes: return self._default_scopes.split(',') return [] @default_scopes.setter def default_scopes(self, scopes): self._default_scopes = scopes
class Picture(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), unique=True) created_at = db.Column(db.DateTime, default=db.func.now()) updated_at = db.Column(db.DateTime, nullable=True)