Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0d4e4d7

Browse files
committed
Fixes #24 - Should redirect from login -> account if they are already logged in.
1 parent 0e3e4c9 commit 0d4e4d7

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

app/ch14_testing/final/pypi_org/views/account_views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def register_post():
5858
@response(template_file='account/login.html')
5959
def login_get():
6060
vm = LoginViewModel()
61+
62+
# Added after recording, see https://github.com/talkpython/data-driven-web-apps-with-flask/issues/24
63+
if vm.user_id:
64+
return flask.redirect('/account')
65+
6166
return vm.to_dict()
6267

6368

app/ch14_testing/starter/pypi_org/views/account_views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def register_post():
5858
@response(template_file='account/login.html')
5959
def login_get():
6060
vm = LoginViewModel()
61+
62+
# Added after recording, see https://github.com/talkpython/data-driven-web-apps-with-flask/issues/24
63+
if vm.user_id:
64+
return flask.redirect('/account')
65+
6166
return vm.to_dict()
6267

6368

app/ch15_deploy/final/pypi_org/views/account_views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import flask
22

3+
import pypi_org.infrastructure.cookie_auth as cookie_auth
34
from pypi_org.infrastructure.view_modifiers import response
45
from pypi_org.services import user_service
5-
import pypi_org.infrastructure.cookie_auth as cookie_auth
66
from pypi_org.viewmodels.account.index_viewmodel import IndexViewModel
77
from pypi_org.viewmodels.account.login_viewmodel import LoginViewModel
88
from pypi_org.viewmodels.account.register_viewmodel import RegisterViewModel
@@ -58,6 +58,11 @@ def register_post():
5858
@response(template_file='account/login.html')
5959
def login_get():
6060
vm = LoginViewModel()
61+
62+
# Added after recording, see https://github.com/talkpython/data-driven-web-apps-with-flask/issues/24
63+
if vm.user_id:
64+
return flask.redirect('/account')
65+
6166
return vm.to_dict()
6267

6368

app/ch15_deploy/starter/pypi_org/views/account_views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def register_post():
5858
@response(template_file='account/login.html')
5959
def login_get():
6060
vm = LoginViewModel()
61+
62+
# Added after recording, see https://github.com/talkpython/data-driven-web-apps-with-flask/issues/24
63+
if vm.user_id:
64+
return flask.redirect('/account')
65+
6166
return vm.to_dict()
6267

6368

app/ch16_mongodb/final/pypi_org/views/account_views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def register_post():
5858
@response(template_file='account/login.html')
5959
def login_get():
6060
vm = LoginViewModel()
61+
62+
# Added after recording, see https://github.com/talkpython/data-driven-web-apps-with-flask/issues/24
63+
if vm.user_id:
64+
return flask.redirect('/account')
65+
6166
return vm.to_dict()
6267

6368

app/ch16_mongodb/starter/pypi_org/views/account_views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def register_post():
5858
@response(template_file='account/login.html')
5959
def login_get():
6060
vm = LoginViewModel()
61+
62+
# Added after recording, see https://github.com/talkpython/data-driven-web-apps-with-flask/issues/24
63+
if vm.user_id:
64+
return flask.redirect('/account')
65+
6166
return vm.to_dict()
6267

6368

0 commit comments

Comments
 (0)