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
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
4858f36d
Commit
4858f36d
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Codestyle for auth package.
parent
5749c94b
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/auth/forms.py
+21
-25
21 additions, 25 deletions
app/auth/forms.py
app/auth/views.py
+28
-16
28 additions, 16 deletions
app/auth/views.py
with
49 additions
and
41 deletions
app/auth/forms.py
+
21
−
25
View file @
4858f36d
from
flask_wtf
import
FlaskForm
from
flask_wtf
import
FlaskForm
from
wtforms
import
(
String
Field
,
PasswordField
,
Boolean
Field
,
SubmitField
,
from
wtforms
import
(
Boolean
Field
,
PasswordField
,
String
Field
,
SubmitField
,
ValidationError
)
ValidationError
)
from
wtforms.validators
import
DataRequired
,
Length
,
Email
,
Regexp
,
EqualTo
from
wtforms.validators
import
DataRequired
,
Email
,
EqualTo
,
Length
,
Regexp
from
..models
import
User
from
..models
import
User
...
@@ -12,6 +12,25 @@ class LoginForm(FlaskForm):
...
@@ -12,6 +12,25 @@ class LoginForm(FlaskForm):
submit
=
SubmitField
(
'
Log In
'
)
submit
=
SubmitField
(
'
Log In
'
)
class
PasswordResetForm
(
FlaskForm
):
password
=
PasswordField
(
'
New Password
'
,
validators
=
[
DataRequired
(),
EqualTo
(
'
password2
'
,
message
=
'
Passwords must match
'
)]
)
password2
=
PasswordField
(
'
Confirm password
'
,
validators
=
[
DataRequired
(),
EqualTo
(
'
password
'
,
message
=
'
Passwords must match.
'
)]
)
submit
=
SubmitField
(
'
Reset Password
'
)
class
PasswordResetRequestForm
(
FlaskForm
):
email
=
StringField
(
'
Email
'
,
validators
=
[
DataRequired
(),
Email
()])
submit
=
SubmitField
(
'
Reset Password
'
)
class
RegistrationForm
(
FlaskForm
):
class
RegistrationForm
(
FlaskForm
):
email
=
StringField
(
'
Email
'
,
validators
=
[
DataRequired
(),
Email
()])
email
=
StringField
(
'
Email
'
,
validators
=
[
DataRequired
(),
Email
()])
username
=
StringField
(
username
=
StringField
(
...
@@ -38,26 +57,3 @@ class RegistrationForm(FlaskForm):
...
@@ -38,26 +57,3 @@ class RegistrationForm(FlaskForm):
def
validate_username
(
self
,
field
):
def
validate_username
(
self
,
field
):
if
User
.
query
.
filter_by
(
username
=
field
.
data
).
first
():
if
User
.
query
.
filter_by
(
username
=
field
.
data
).
first
():
raise
ValidationError
(
'
Username already in use.
'
)
raise
ValidationError
(
'
Username already in use.
'
)
class
PasswordResetForm
(
FlaskForm
):
password
=
PasswordField
(
'
New Password
'
,
validators
=
[
DataRequired
(),
EqualTo
(
'
password2
'
,
message
=
'
Passwords must match
'
)
]
)
password2
=
PasswordField
(
'
Confirm password
'
,
validators
=
[
DataRequired
(),
EqualTo
(
'
password
'
,
message
=
'
Passwords must match.
'
)
]
)
submit
=
SubmitField
(
'
Reset Password
'
)
class
PasswordResetRequestForm
(
FlaskForm
):
email
=
StringField
(
'
Email
'
,
validators
=
[
DataRequired
(),
Email
()])
submit
=
SubmitField
(
'
Reset Password
'
)
This diff is collapsed.
Click to expand it.
app/auth/views.py
+
28
−
16
View file @
4858f36d
from
flask
import
flash
,
redirect
,
render_template
,
request
,
url_for
from
flask
import
flash
,
redirect
,
render_template
,
request
,
url_for
from
flask_login
import
current_user
,
login_required
,
login_user
,
logout_user
from
flask_login
import
current_user
,
login_required
,
login_user
,
logout_user
from
.
import
auth
from
.
import
auth
from
..
import
db
from
.forms
import
(
LoginForm
,
PasswordResetForm
,
PasswordResetRequestForm
,
from
.forms
import
(
LoginForm
,
PasswordResetForm
,
PasswordResetRequestForm
,
RegistrationForm
)
RegistrationForm
)
from
..
import
db
from
..email
import
send_email
from
..email
import
send_email
from
..models
import
User
from
..models
import
User
...
@@ -42,16 +42,21 @@ def register():
...
@@ -42,16 +42,21 @@ def register():
form
=
RegistrationForm
()
form
=
RegistrationForm
()
if
form
.
validate_on_submit
():
if
form
.
validate_on_submit
():
user
=
User
(
email
=
form
.
email
.
data
.
lower
(),
user
=
User
(
email
=
form
.
email
.
data
.
lower
(),
username
=
form
.
username
.
data
,
password
=
form
.
password
.
data
,
password
=
form
.
password
.
data
)
username
=
form
.
username
.
data
)
db
.
session
.
add
(
user
)
db
.
session
.
add
(
user
)
db
.
session
.
commit
()
db
.
session
.
commit
()
token
=
user
.
generate_confirmation_token
()
token
=
user
.
generate_confirmation_token
()
send_email
(
user
.
email
,
'
Confirm Your Account
'
,
send_email
(
user
.
email
,
'
auth/email/confirm
'
,
user
=
user
,
token
=
token
)
'
Confirm Your Account
'
,
'
auth/email/confirm
'
,
token
=
token
,
user
=
user
)
flash
(
'
A confirmation email has been sent to you by email.
'
)
flash
(
'
A confirmation email has been sent to you by email.
'
)
return
redirect
(
url_for
(
'
auth.login
'
))
return
redirect
(
url_for
(
'
auth.login
'
))
return
render_template
(
'
auth/register.html.j2
'
,
form
=
form
,
title
=
'
Register
'
)
return
render_template
(
'
auth/register.html.j2
'
,
form
=
form
,
title
=
'
Register
'
)
@auth.route
(
'
/confirm/<token>
'
)
@auth.route
(
'
/confirm/<token>
'
)
...
@@ -73,10 +78,10 @@ def before_request():
...
@@ -73,10 +78,10 @@ def before_request():
Checks if a user is unconfirmed when visiting specific sites. Redirects to
Checks if a user is unconfirmed when visiting specific sites. Redirects to
unconfirmed view if user is unconfirmed.
unconfirmed view if user is unconfirmed.
"""
"""
if
current_user
.
is_authenticated
\
if
(
current_user
.
is_authenticated
and
not
current_user
.
confirmed
\
and
not
current_user
.
confirmed
and
request
.
blueprint
!=
'
auth
'
\
and
request
.
blueprint
!=
'
auth
'
and
request
.
endpoint
!=
'
static
'
:
and
request
.
endpoint
!=
'
static
'
)
:
return
redirect
(
url_for
(
'
auth.unconfirmed
'
))
return
redirect
(
url_for
(
'
auth.unconfirmed
'
))
...
@@ -91,8 +96,11 @@ def unconfirmed():
...
@@ -91,8 +96,11 @@ def unconfirmed():
@login_required
@login_required
def
resend_confirmation
():
def
resend_confirmation
():
token
=
current_user
.
generate_confirmation_token
()
token
=
current_user
.
generate_confirmation_token
()
send_email
(
current_user
.
email
,
'
Confirm Your Account
'
,
'
auth/email/confirm
'
,
send_email
(
current_user
.
email
,
user
=
current_user
,
token
=
token
)
'
Confirm Your Account
'
,
'
auth/email/confirm
'
,
token
=
token
,
user
=
current_user
)
flash
(
'
A new confirmation email has benn sent to you by email.
'
)
flash
(
'
A new confirmation email has benn sent to you by email.
'
)
return
redirect
(
url_for
(
'
main.dashboard
'
))
return
redirect
(
url_for
(
'
main.dashboard
'
))
...
@@ -106,13 +114,16 @@ def password_reset_request():
...
@@ -106,13 +114,16 @@ def password_reset_request():
user
=
User
.
query
.
filter_by
(
email
=
form
.
email
.
data
.
lower
()).
first
()
user
=
User
.
query
.
filter_by
(
email
=
form
.
email
.
data
.
lower
()).
first
()
if
user
:
if
user
:
token
=
user
.
generate_reset_token
()
token
=
user
.
generate_reset_token
()
send_email
(
user
.
email
,
'
Reset Your Password
'
,
send_email
(
user
.
email
,
'
Reset Your Password
'
,
'
auth/email/reset_password
'
,
'
auth/email/reset_password
'
,
user
=
user
,
token
=
token
)
token
=
token
,
user
=
user
)
flash
(
'
An email with instructions to reset your password has been
'
flash
(
'
An email with instructions to reset your password has been
'
'
sent to you.
'
)
'
sent to you.
'
)
return
redirect
(
url_for
(
'
auth.login
'
))
return
redirect
(
url_for
(
'
auth.login
'
))
return
render_template
(
'
auth/reset_password_request.html.j2
'
,
form
=
form
,
return
render_template
(
'
auth/reset_password_request.html.j2
'
,
form
=
form
,
title
=
'
Password Reset
'
)
title
=
'
Password Reset
'
)
...
@@ -128,5 +139,6 @@ def password_reset(token):
...
@@ -128,5 +139,6 @@ def password_reset(token):
return
redirect
(
url_for
(
'
auth.login
'
))
return
redirect
(
url_for
(
'
auth.login
'
))
else
:
else
:
return
redirect
(
url_for
(
'
main.index
'
))
return
redirect
(
url_for
(
'
main.index
'
))
return
render_template
(
'
auth/reset_password.html.j2
'
,
form
=
form
,
return
render_template
(
'
auth/reset_password.html.j2
'
,
form
=
form
,
title
=
'
Password Reset
'
)
title
=
'
Password Reset
'
)
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