예제 #1
0
class Group(db.Model):
    __tablename__ = 'group'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(512), nullable=False, unique=True)

    def __str__(self):
        return self.name

    def __repr__(self):
        return '<Group %r>' % self.name
예제 #2
0
class User(db.Model, UserMixin, MailMixin, ModelMixin):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(512), unique=True)
    email = db.Column(db.String(512), unique=True)
    password = db.Column(db.String(512), nullable=False)
    is_superuser = db.Column(db.Boolean, default=False)
    is_confirmed = db.Column(db.Boolean, default=False)
    register_time = db.Column(db.DateTime, default=datetime.now())
    last_login = db.Column(db.DateTime, default=datetime.now())
    groups = db.relationship(Group,
                             secondary=user_group,
                             lazy='dynamic',
                             backref=db.backref('users', lazy='dynamic'))

    def __str__(self):
        return self.username

    def __repr__(self):
        return '<User %r>' % self.username

    def set_password(self, raw_password):
        self.password = generate_password_hash(raw_password)

    def check_password(self, raw_password):
        return check_password_hash(self.password, raw_password)
예제 #3
0
# Email: [email protected]
# Created: 2016-12-07 13:12:42 (CST)
# Last Update:星期三 2017-5-10 14:56:32 (CST)
#          By:
# Description:
# **************************************************************************
from datetime import datetime

from flask_login import UserMixin
from werkzeug.security import check_password_hash, generate_password_hash

from flask_maple.mail import MailMixin
from flask_maple.models import ModelMixin, db

user_group = db.Table(
    'user_group', db.Column('group_id', db.Integer, db.ForeignKey('group.id')),
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')))


class Group(db.Model):
    __tablename__ = 'group'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(512), nullable=False, unique=True)

    def __str__(self):
        return self.name

    def __repr__(self):
        return '<Group %r>' % self.name

예제 #4
0
 def last_login(cls):
     return db.Column(db.DateTime, default=datetime.now)
예제 #5
0
 def register_time(cls):
     return db.Column(db.DateTime, default=datetime.now)
예제 #6
0
 def is_confirmed(cls):
     return db.Column(db.Boolean, default=False)
예제 #7
0
 def is_superuser(cls):
     return db.Column(db.Boolean, default=False)
예제 #8
0
 def password(cls):
     return db.Column(db.String(512), nullable=False)
예제 #9
0
 def code(cls):
     return db.Column(db.String(81), default='0000')
예제 #10
0
 def username(cls):
     return db.Column(db.String(512), nullable=False, unique=True)
예제 #11
0
 def id(cls):
     return db.Column(db.Integer, primary_key=True)
예제 #12
0
 def parent_id(cls):
     return db.Column(db.Integer, db.ForeignKey('group.id'))
예제 #13
0
 def description(cls):
     return db.Column(db.String(2048))
예제 #14
0
 def resource_type(cls):
     return db.Column(db.String(81), nullable=False)
예제 #15
0
 def resource(cls):
     return db.Column(db.String(1024), nullable=False)
예제 #16
0
 def email(cls):
     return db.Column(db.String(512), nullable=False, unique=True)
예제 #17
0
# **************************************************************************
# Copyright © 2017 jianglin
# File Name: models.py
# Author: jianglin
# Email: [email protected]
# Created: 2017-08-29 16:47:32 (CST)
# Last Update: 星期五 2018-02-23 22:59:49 (CST)
#          By:
# Description:
# **************************************************************************
from sqlalchemy.ext.declarative import declared_attr
from flask_maple.models import ModelMixin, db

user_permission = db.Table(
    'user_permission',
    db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('permission_id', db.Integer, db.ForeignKey('permission.id')))

group_permission = db.Table(
    'group_permission',
    db.Column('group_id', db.Integer, db.ForeignKey('group.id')),
    db.Column('permission_id', db.Integer, db.ForeignKey('permission.id')))


class UserMixin(object):
    def perm_cache(self,
                   action,
                   resource,
                   resource_type='endpoint',
                   and_=False):
        return