Commit 1ee74bf2 authored by Beno Sons's avatar Beno Sons

privelege

parent 2a706cfe
......@@ -7,6 +7,7 @@ load_dotenv()
class Config:
SECRET_KEY = os.getenv('SECRET_KEY', 'mysecretkey')
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', 'postgresql://user:password@localhost/dbname')
SCHEMA_NAME = os.getenv('DATABASE_SCHEMA')
SQLALCHEMY_TRACK_MODIFICATIONS = False
DEBUG = os.getenv('FLASK_ENV') == 'development'
PORT = int(os.getenv('PORT', 8000))
......
from app import db
from werkzeug.security import generate_password_hash, check_password_hash
from app.config import Config
class User(db.Model):
__tablename__ = 'user'
__table_args__ = {'schema': Config.SCHEMA_NAME }
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(150), unique=True, nullable=False)
password_hash = db.Column(db.String(255), nullable=False)
email = db.Column(db.String(150), unique=True, nullable=True, default='no-reply@example.com')
current_refresh_token = db.Column(db.String(500), nullable=True)
roles = db.relationship('Role', secondary='user_roles', backref=db.backref('users', lazy='dynamic'))
# roles = db.relationship('Role', secondary='user_roles', backref=db.backref('users', lazy='dynamic'))
def set_password(self, password):
self.password_hash = generate_password_hash(password)
......@@ -17,22 +21,29 @@ class User(db.Model):
# Role model
class Role(db.Model):
__tablename__ = 'role'
__table_args__ = {'schema': Config.SCHEMA_NAME }
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), unique=True)
privileges = db.relationship('Privilege', secondary='role_privileges', backref=db.backref('roles', lazy='dynamic'))
# privileges = db.relationship('Privilege', secondary='role_privileges', backref=db.backref('roles', lazy='dynamic'))
# Privilege model
class Privilege(db.Model):
__tablename__ = 'privilege'
__table_args__ = {'schema': Config.SCHEMA_NAME }
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50), unique=True)
# Association tables
user_roles = db.Table('user_roles',
db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
db.Column('role_id', db.Integer, db.ForeignKey('role.id'))
)
# # Association tables
# user_roles = db.Table('user_roles',
# db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
# db.Column('role_id', db.Integer, db.ForeignKey('role.id'))
# )
role_privileges = db.Table('role_privileges',
db.Column('role_id', db.Integer, db.ForeignKey('role.id')),
db.Column('privilege_id', db.Integer, db.ForeignKey('privilege.id'))
)
\ No newline at end of file
# role_privileges = db.Table('role_privileges',
# db.Column('role_id', db.Integer, db.ForeignKey('role.id')),
# db.Column('privilege_id', db.Integer, db.ForeignKey('privilege.id'))
# )
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment