コード例 #1
0
ファイル: user.py プロジェクト: yekki/flask-restful
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(20), nullable=False)

    def __repr__(self):
        return f'<User ID: {self.id}>'
コード例 #2
0
ファイル: blog_role.py プロジェクト: Onekki/OnekkiSite
class BlogRole(db.Model):
    __tablename__ = 'blog_role'
    __table_args__ = {'schema': 'onekki_site'}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True)
    description = db.Column(db.String(255))
コード例 #3
0
class BlogReminder(db.Model):
    __tablename__ = 'blog_reminder'
    __table_args__ = {'schema': 'onekki_site'}

    id = db.Column(db.Integer, primary_key=True)
    time = db.Column(db.DateTime)
    email = db.Column(db.String(255))
    content = db.Column(db.Text)
コード例 #4
0
class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), unique=True, nullable=False)
    designer_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    designer = db.relationship('User', backref='products')

    def __repr__(self):
        return f'<Product ID: {self.id}>'
コード例 #5
0
class BlogComment(db.Model):
    __tablename__ = 'blog_comment'
    __table_args__ = {'schema': 'onekki_site'}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    content = db.Column(db.Text)
    time = db.Column(db.DateTime)
    article_id = db.Column(db.ForeignKey('onekki_site.blog_article.id'),
                           index=True)

    article = db.relationship(
        'BlogArticle',
        primaryjoin='BlogComment.article_id == BlogArticle.id',
        backref='blog_comments')
コード例 #6
0
class BlogArticle(db.Model):
    __tablename__ = 'blog_article'
    __table_args__ = {'schema': 'onekki_site'}

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(45))
    content = db.Column(db.Text)
    publish_time = db.Column(db.DateTime)
    user_id = db.Column(db.ForeignKey('onekki_site.blog_user.id'), index=True)

    user = db.relationship('BlogUser',
                           primaryjoin='BlogArticle.user_id == BlogUser.id',
                           backref='blog_articles')

    comments = db.relationship('BlogComment',
                               backref='blog_article',
                               lazy='dynamic')
    tags = db.relationship('BlogTag',
                           secondary='onekki_site.blog_article_tag',
                           backref='blog_articles')
コード例 #7
0
ファイル: blog_user.py プロジェクト: Onekki/OnekkiSite
class BlogUser(db.Model):
    __tablename__ = 'blog_user'
    __table_args__ = {'schema': 'onekki_site'}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))

    articles = db.relationship('BlogArticle',
                               backref='blog_user',
                               lazy='dynamic')
    roles = db.relationship('BlogRole',
                            secondary='onekki_site.blog_user_role',
                            backref=db.backref('blog_users', lazy='dynamic'))

    # 自定义
    def __init__(self, name, password):
        self.name = name
        self.password = self.set_password(password)

        defalut = BlogRole.query.filter_by(name="default").first()
        self.roles.append(defalut)

    def __repr__(self):
        return "<BlogUser:`{}`>".format(self.name)

    def set_password(self, password):
        return bcrypt.generate_password_hash(password)

    def check_password(self, password):
        return bcrypt.check_password_hash(self.password, password)

    def is_authenticated(self):
        if isinstance(self, AnonymousUserMixin):
            return False
        else:
            return True

    def is_active(self):
        return True

    def is_anonymous(self):
        if isinstance(self, AnonymousUserMixin):
            return True
        else:
            return False

    def get_id(self):
        return self.id

    @staticmethod
    def verify_auth_token(token):
        serializer = Serializer(current_app.config['SECRET_KEY'])
        try:
            data = serializer.loads(token)
        except SignatureExpired:
            return None
        except BadSignature:
            return None

        user = BlogUser.query.filter_by(id=data['id']).first()
        return user
コード例 #8
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True, nullable=False)
    password = db.Column(db.Binary)
コード例 #9
0
class BlogTag(db.Model):
    __tablename__ = 'blog_tag'
    __table_args__ = {'schema': 'onekki_site'}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
コード例 #10
0
from app.plugins import db

t_blog_article_tag = db.Table(
    'blog_article_tag',
    db.Column('article_id',
              db.ForeignKey('onekki_site.blog_article.id'),
              primary_key=True,
              nullable=False),
    db.Column('tag_id',
              db.ForeignKey('onekki_site.blog_tag.id'),
              primary_key=True,
              nullable=False,
              index=True),
    schema='onekki_site')

t_blog_user_role = db.Table(
    'blog_user_role',
    db.Column('user_id',
              db.ForeignKey('onekki_site.blog_user.id'),
              primary_key=True,
              nullable=False),
    db.Column('role_id',
              db.ForeignKey('onekki_site.blog_role.id'),
              primary_key=True,
              nullable=False,
              index=True),
    schema='onekki_site')