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.

- add option to go on subscribe directly by /login?subscribe
  • Loading branch information
mathben committed Mar 26, 2018
1 parent 0ac4cdc commit 2a5e079
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 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
5 changes: 2 additions & 3 deletions src/web/resources/js/tl_module/login_ctrl/login_ctrl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Formulaire de Traitre-Lame
characterApp.controller("login_ctrl", ['$scope', '$routeParams', function ($scope, $routeParams) {
$scope.show_login = true;
characterApp.controller("login_ctrl", ["$scope", "$routeParams", "$window", function ($scope, $routeParams, $window) {
$scope.show_login = !($window.location.search.indexOf("?subscribe") >= 0);
$scope.invalid_login = false;

$scope.log_facebook = function (e) {
Expand Down Expand Up @@ -60,7 +60,6 @@ characterApp.directive('fieldMatch', function () {
function validate(value) {
var isValid = scope.$eval(attr.fieldMatch) == value;
ngModel.$setValidity('fieldMatch', isValid);
console.log(isValid);
return isValid ? value : undefined;
}
}
Expand Down

0 comments on commit 2a5e079

Please sign in to comment.