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):
...
@@ -10,15 +10,15 @@ class OwnerLoginForm(FlaskForm):
def
validate
(
self
):
def
validate
(
self
):
if
not
FlaskForm
.
validate
(
self
):
if
not
FlaskForm
.
validate
(
self
):
return
False
,
None
return
False
owner
=
Owner
.
query
.
filter_by
(
username
=
self
.
username
.
data
)
.
first
()
owner
=
Owner
.
query
.
filter_by
(
username
=
self
.
username
.
data
)
.
first
()
if
owner
is
None
:
if
owner
is
None
:
flash
(
'User does not exist!'
)
flash
(
'User does not exist!'
)
return
False
,
None
return
False
if
not
owner
.
check_password
(
self
.
password
.
data
):
if
not
owner
.
check_password
(
self
.
password
.
data
):
flash
(
'Wrong password!'
)
flash
(
'Wrong password!'
)
return
False
,
None
return
False
return
True
,
owner
return
True
,
owner
...
...
canteeneo/views.py
View file @
74cd8246
...
@@ -8,6 +8,7 @@ from forms import OwnerLoginForm, OwnerRegisterForm
...
@@ -8,6 +8,7 @@ from forms import OwnerLoginForm, OwnerRegisterForm
from
models
import
Owner
,
Stall
,
Dish
from
models
import
Owner
,
Stall
,
Dish
class
FormView
(
View
):
class
FormView
(
View
):
methods
=
[
'GET'
,
'POST'
]
def
dispatch_request
(
self
,
**
kwargs
):
def
dispatch_request
(
self
,
**
kwargs
):
form
=
self
.
get_form
()
form
=
self
.
get_form
()
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
...
@@ -30,43 +31,45 @@ def index():
...
@@ -30,43 +31,45 @@ def index():
else
:
else
:
return
render_template
(
'landing.html'
)
return
render_template
(
'landing.html'
)
@
app
.
route
(
'/login'
,
methods
=
[
'GET'
,
'POST'
])
def
not_logged_in
(
f
):
def
login
():
@
wraps
(
f
)
def
wrapper
(
*
args
,
**
kwargs
):
if
current_user
.
is_authenticated
:
if
current_user
.
is_authenticated
:
return
redirect
(
url_for
(
'stalls'
))
return
redirect
(
url_for
(
'stalls'
))
return
f
(
*
args
,
**
kwargs
)
return
wrapper
form
=
OwnerLoginForm
()
class
LoginView
(
FormView
):
if
request
.
method
==
'POST'
:
decorators
=
[
not_logged_in
]
is_valid
,
owner
=
form
.
validate
()
def
render_post
(
self
):
if
is_valid
:
login_user
(
Owner
.
query
.
filter_by
(
username
=
self
.
get_form
()
.
username
.
data
)
.
first
())
login_user
(
owner
)
return
redirect
(
url_for
(
'stalls'
))
return
redirect
(
url_for
(
'stalls'
))
else
:
def
render_get
(
self
)
:
flash_form_errors
(
form
)
return
render_template
(
'login.html'
,
form
=
self
.
get_form
()
)
def
get_form
(
self
):
return
render_template
(
'login.html'
,
form
=
form
)
return
OwnerLoginForm
(
)
@
app
.
route
(
'/logout'
)
app
.
add_url_rule
(
'/login'
,
view_func
=
LoginView
.
as_view
(
'login'
))
def
logout
():
logout_user
()
return
redirect
(
'/'
)
@
app
.
route
(
'/register'
,
methods
=
[
'GET'
,
'POST'
])
class
RegisterView
(
FormView
):
def
register
():
decorators
=
[
not_logged_in
]
if
current_user
.
is_authenticated
:
def
render_post
(
self
):
return
redirect
(
url_for
(
'stalls'
))
form
=
self
.
get_form
()
form
=
OwnerRegisterForm
()
if
request
.
method
==
'POST'
:
if
form
.
validate
():
owner
=
Owner
(
form
.
name
.
data
,
form
.
username
.
data
,
form
.
email
.
data
,
form
.
password
.
data
)
owner
=
Owner
(
form
.
name
.
data
,
form
.
username
.
data
,
form
.
email
.
data
,
form
.
password
.
data
)
db
.
session
.
add
(
owner
)
db
.
session
.
add
(
owner
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
redirect
(
url_for
(
'login'
))
return
redirect
(
url_for
(
'login'
))
else
:
def
render_get
(
self
):
flash_form_errors
(
form
)
return
render_template
(
'register.html'
,
form
=
form
)
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
):
def
stall_validate
(
f
):
@
wraps
(
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