Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
47ab22c5
Commit
47ab22c5
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Codestyle
parent
3a6fdaa2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models.py
+12
-9
12 additions, 9 deletions
app/models.py
config.py
+2
-1
2 additions, 1 deletion
config.py
with
14 additions
and
10 deletions
app/models.py
+
12
−
9
View file @
47ab22c5
from
flask
import
current_app
from
flask
import
current_app
from
flask_login
import
UserMixin
,
AnonymousUserMixin
from
flask_login
import
UserMixin
,
AnonymousUserMixin
from
itsdangerous
import
TimedJSONWebSignatureSerializer
as
Serializer
from
itsdangerous
import
BadSignature
,
TimedJSONWebSignatureSerializer
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
.
import
db
from
.
import
db
from
.
import
login_manager
from
.
import
login_manager
...
@@ -22,8 +22,8 @@ class Permission:
...
@@ -22,8 +22,8 @@ class Permission:
class
Role
(
db
.
Model
):
class
Role
(
db
.
Model
):
"""
"""
Model for the different roles Users can have. Is a one-to-many
relationship.
Model for the different roles Users can have. Is a one-to-many
A Role can be associated with many User rows.
relationship.
A Role can be associated with many User rows.
"""
"""
__tablename__
=
'
roles
'
__tablename__
=
'
roles
'
# Primary key
# Primary key
...
@@ -136,24 +136,26 @@ class User(UserMixin, db.Model):
...
@@ -136,24 +136,26 @@ class User(UserMixin, db.Model):
"""
"""
Generates a confirmation token for user confirmation via email.
Generates a confirmation token for user confirmation via email.
"""
"""
s
=
Serializer
(
current_app
.
config
[
'
SECRET_KEY
'
],
expiration
)
s
=
TimedJSONWebSignatureSerializer
(
current_app
.
config
[
'
SECRET_KEY
'
],
expiration
)
return
s
.
dumps
({
'
confirm
'
:
self
.
id
}).
decode
(
'
utf-8
'
)
return
s
.
dumps
({
'
confirm
'
:
self
.
id
}).
decode
(
'
utf-8
'
)
def
generate_reset_token
(
self
,
expiration
=
3600
):
def
generate_reset_token
(
self
,
expiration
=
3600
):
"""
"""
Generates a reset token for password reset via email.
Generates a reset token for password reset via email.
"""
"""
s
=
Serializer
(
current_app
.
config
[
'
SECRET_KEY
'
],
expiration
)
s
=
TimedJSONWebSignatureSerializer
(
current_app
.
config
[
'
SECRET_KEY
'
],
expiration
)
return
s
.
dumps
({
'
reset
'
:
self
.
id
}).
decode
(
'
utf-8
'
)
return
s
.
dumps
({
'
reset
'
:
self
.
id
}).
decode
(
'
utf-8
'
)
def
confirm
(
self
,
token
):
def
confirm
(
self
,
token
):
"""
"""
Confirms User if the given token is valid and not expired.
Confirms User if the given token is valid and not expired.
"""
"""
s
=
Serializer
(
current_app
.
config
[
'
SECRET_KEY
'
])
s
=
TimedJSONWebSignature
Serializer
(
current_app
.
config
[
'
SECRET_KEY
'
])
try
:
try
:
data
=
s
.
loads
(
token
.
encode
(
'
utf-8
'
))
data
=
s
.
loads
(
token
.
encode
(
'
utf-8
'
))
except
:
except
BadSignature
:
return
False
return
False
if
data
.
get
(
'
confirm
'
)
!=
self
.
id
:
if
data
.
get
(
'
confirm
'
)
!=
self
.
id
:
return
False
return
False
...
@@ -166,10 +168,10 @@ class User(UserMixin, db.Model):
...
@@ -166,10 +168,10 @@ class User(UserMixin, db.Model):
"""
"""
Resets password for User if the given token is valid and not expired.
Resets password for User if the given token is valid and not expired.
"""
"""
s
=
Serializer
(
current_app
.
config
[
'
SECRET_KEY
'
])
s
=
TimedJSONWebSignature
Serializer
(
current_app
.
config
[
'
SECRET_KEY
'
])
try
:
try
:
data
=
s
.
loads
(
token
.
encode
(
'
utf-8
'
))
data
=
s
.
loads
(
token
.
encode
(
'
utf-8
'
))
except
:
except
BadSignature
:
return
False
return
False
user
=
User
.
query
.
get
(
data
.
get
(
'
reset
'
))
user
=
User
.
query
.
get
(
data
.
get
(
'
reset
'
))
if
user
is
None
:
if
user
is
None
:
...
@@ -291,6 +293,7 @@ class Corpus(db.Model):
...
@@ -291,6 +293,7 @@ class Corpus(db.Model):
'
title
'
:
self
.
title
,
'
title
'
:
self
.
title
,
'
user_id
'
:
self
.
user_id
}
'
user_id
'
:
self
.
user_id
}
'''
'''
'
Flask-Login is told to use the application’s custom anonymous user by setting
'
Flask-Login is told to use the application’s custom anonymous user by setting
'
its class in the login_manager.anonymous_user attribute.
'
its class in the login_manager.anonymous_user attribute.
...
...
This diff is collapsed.
Click to expand it.
config.py
+
2
−
1
View file @
47ab22c5
...
@@ -33,7 +33,8 @@ class Config:
...
@@ -33,7 +33,8 @@ class Config:
class
DevelopmentConfig
(
Config
):
class
DevelopmentConfig
(
Config
):
DEBUG
=
True
DEBUG
=
True
SQLALCHEMY_DATABASE_URI
=
'
sqlite:///
'
+
os
.
path
.
join
(
basedir
,
'
data_dev.sqlite
'
)
SQLALCHEMY_DATABASE_URI
=
'
sqlite:///
'
+
os
.
path
.
join
(
basedir
,
'
data_dev.sqlite
'
)
class
TestingConfig
(
Config
):
class
TestingConfig
(
Config
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment