Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flask-backend
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
retno sonjaya
flask-backend
Commits
1ee74bf2
Commit
1ee74bf2
authored
Aug 12, 2024
by
Beno Sons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
privelege
parent
2a706cfe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
11 deletions
+23
-11
app/config.py
app/config.py
+1
-0
app/models/user.py
app/models/user.py
+22
-11
No files found.
app/config.py
View file @
1ee74bf2
...
...
@@ -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
))
...
...
app/models/user.py
View file @
1ee74bf2
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment