Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS123-Canteeneo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Willard Torres
CS123-Canteeneo
Commits
74cd8246
Commit
74cd8246
authored
Nov 11, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement login and registration as FormView
parent
0e07d5c1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
32 deletions
+35
-32
forms.py
canteeneo/forms.py
+3
-3
views.py
canteeneo/views.py
+32
-29
No files found.
canteeneo/forms.py
View file @
74cd8246
...
...
@@ -10,15 +10,15 @@ class OwnerLoginForm(FlaskForm):
def
validate
(
self
):
if
not
FlaskForm
.
validate
(
self
):
return
False
,
None
return
False
owner
=
Owner
.
query
.
filter_by
(
username
=
self
.
username
.
data
)
.
first
()
if
owner
is
None
:
flash
(
'User does not exist!'
)
return
False
,
None
return
False
if
not
owner
.
check_password
(
self
.
password
.
data
):
flash
(
'Wrong password!'
)
return
False
,
None
return
False
return
True
,
owner
...
...
canteeneo/views.py
View file @
74cd8246
...
...
@@ -8,6 +8,7 @@ from forms import OwnerLoginForm, OwnerRegisterForm
from
models
import
Owner
,
Stall
,
Dish
class
FormView
(
View
):
methods
=
[
'GET'
,
'POST'
]
def
dispatch_request
(
self
,
**
kwargs
):
form
=
self
.
get_form
()
if
request
.
method
==
'POST'
:
...
...
@@ -30,43 +31,45 @@ def index():
else
:
return
render_template
(
'landing.html'
)
@
app
.
route
(
'/login'
,
methods
=
[
'GET'
,
'POST'
])
def
login
():
def
not_logged_in
(
f
):
@
wraps
(
f
)
def
wrapper
(
*
args
,
**
kwargs
):
if
current_user
.
is_authenticated
:
return
redirect
(
url_for
(
'stalls'
))
return
f
(
*
args
,
**
kwargs
)
return
wrapper
form
=
OwnerLoginForm
()
if
request
.
method
==
'POST'
:
is_valid
,
owner
=
form
.
validate
()
if
is_valid
:
login_user
(
owner
)
class
LoginView
(
FormView
):
decorators
=
[
not_logged_in
]
def
render_post
(
self
):
login_user
(
Owner
.
query
.
filter_by
(
username
=
self
.
get_form
()
.
username
.
data
)
.
first
())
return
redirect
(
url_for
(
'stalls'
))
else
:
flash_form_errors
(
form
)
return
render_template
(
'login.html'
,
form
=
form
)
def
render_get
(
self
)
:
return
render_template
(
'login.html'
,
form
=
self
.
get_form
()
)
def
get_form
(
self
):
return
OwnerLoginForm
(
)
@
app
.
route
(
'/logout'
)
def
logout
():
logout_user
()
return
redirect
(
'/'
)
app
.
add_url_rule
(
'/login'
,
view_func
=
LoginView
.
as_view
(
'login'
))
@
app
.
route
(
'/register'
,
methods
=
[
'GET'
,
'POST'
])
def
register
():
if
current_user
.
is_authenticated
:
return
redirect
(
url_for
(
'stalls'
))
form
=
OwnerRegisterForm
()
if
request
.
method
==
'POST'
:
if
form
.
validate
():
class
RegisterView
(
FormView
):
decorators
=
[
not_logged_in
]
def
render_post
(
self
):
form
=
self
.
get_form
()
owner
=
Owner
(
form
.
name
.
data
,
form
.
username
.
data
,
form
.
email
.
data
,
form
.
password
.
data
)
db
.
session
.
add
(
owner
)
db
.
session
.
commit
()
return
redirect
(
url_for
(
'login'
))
else
:
flash_form_errors
(
form
)
def
render_get
(
self
):
return
render_template
(
'register.html'
,
form
=
form
)
def
get_form
(
self
):
return
OwnerRegisterForm
()
app
.
add_url_rule
(
'/register'
,
view_func
=
RegisterView
.
as_view
(
'register'
))
@
app
.
route
(
'/logout'
)
def
logout
():
logout_user
()
return
redirect
(
'/'
)
def
stall_validate
(
f
):
@
wraps
(
f
)
...
...
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