Skip to content

Commit

Permalink
[AdminTL#83] Server login: when connect to user, redirect to profile …
Browse files Browse the repository at this point in the history
…page.
  • Loading branch information
mathben committed Mar 26, 2018
1 parent 0ac4cdc commit 7d91560
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/web/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def give_cookie(self, user_id, twitter_access_token=None, facebook_access_token=
}
serialize_data = json.dumps(data)
self.set_secure_cookie("user", serialize_data)
self.redirect("/")
self.redirect("/profile")
else:
print("User doesn't have an id.", file=sys.stderr)
# Bad Request
self.set_status(400)
self.send_error(400)
raise tornado.web.Finish()
15 changes: 10 additions & 5 deletions src/web/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ class LoginHandler(base_handler.BaseHandler):
@tornado.web.asynchronous
def get(self):
if self.get_current_user():
self.redirect("/")
self.redirect("/profile")
return

self.render('login.html', **self._global_arg)

@tornado.web.asynchronous
def post(self):
if self._global_arg["disable_login"]:
self.redirect("/login?invalid=disable_login")
self.redirect("/")
return

if self.get_current_user():
print("Need to logout before login or sign up from %s" % self.request.remote_ip, file=sys.stderr)
Expand Down Expand Up @@ -119,6 +120,7 @@ def post(self):
# If user is found, give him a secure cookie based on his user id
if user:
self.give_cookie(user.get("user_id"))
return
else:
print("Invalid email/password combination from %s" % self.request.remote_ip, file=sys.stderr)
self.redirect("/login?invalid=login")
Expand Down Expand Up @@ -168,7 +170,7 @@ def get(self):
# If user is found, give him a secure cookie based on his user_id and Google access_token
if user:
self.give_cookie(user.get("user_id"), google_access_token=access_token)

return
# Sign up
else:
name = google_user["name"]
Expand All @@ -186,6 +188,7 @@ def get(self):

if user:
self.give_cookie(user.get("user_id"), google_access_token=access_token)
return
else:
self.redirect("/login?invalid=google")
return
Expand Down Expand Up @@ -230,7 +233,7 @@ def get(self):
# If user is found, give him a secure cookie based on his user_id and Facebook access_token
if user:
self.give_cookie(user.get("user_id"), facebook_access_token=access_token)

return
# Sign up
else:
name = facebook_user["name"]
Expand All @@ -247,6 +250,7 @@ def get(self):

if user:
self.give_cookie(user.get("user_id"), facebook_access_token=access_token)
return
else:
self.redirect("/login?invalid=facebook")
return
Expand Down Expand Up @@ -287,7 +291,7 @@ def get(self):
# If user is found, give him a secure cookie based on his user_id and Twitter access_token
if user:
self.give_cookie(user.get("user_id"), twitter_access_token=access_token)

return
# Sign up
else:
# nickname = twitter_user["screen_name"]
Expand All @@ -306,6 +310,7 @@ def get(self):

if user:
self.give_cookie(user.get("user_id"), twitter_access_token=access_token)
return
else:
self.redirect("/login?invalid=twitter")
return
Expand Down

0 comments on commit 7d91560

Please sign in to comment.