Skip to content

Commit

Permalink
[AdminTL#83] Login: fix when unauthorized permission when connect to …
Browse files Browse the repository at this point in the history
…third-party

- change menu color item to red for admin button
- move all item menu to left, remove right option
  • Loading branch information
mathben committed Apr 1, 2018
1 parent 4b661e7 commit b341237
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 57 deletions.
47 changes: 39 additions & 8 deletions src/web/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,31 @@ def get(self):
google_user = yield self.get_authenticated_user(
redirect_uri=self._global_arg["url"] + '/cmd/auth/google',
code=self.get_argument('code'))
access_token = google_user["access_token"]

# Cancel by the user or other reason
if not google_user:
self.redirect("/login?invalid=google")
return

access_token = google_user.get("access_token")
google_user = yield self.oauth2_request("https://www.googleapis.com/oauth2/v1/userinfo",
access_token=access_token)

# Cancel by the user or other reason
if not google_user:
self.redirect("/login?invalid=google")
return

# Save the user with e.g. set_secure_cookie
google_id = google_user["id"]
google_id = google_user.get("id")
user = self._db.get_user(id_type="google", user_id=google_id)

# Login
# 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:
username = google_user.get("name")
Expand Down Expand Up @@ -238,23 +250,30 @@ def get(self):
client_secret=self.settings["facebook_secret"],
code=self.get_argument("code"),
extra_fields=["email"])
access_token = facebook_user["access_token"]

facebook_id = facebook_user["id"]
# Cancel by the user or other reason
if not facebook_user:
self.redirect("/login?invalid=facebook")
return

access_token = facebook_user.get("access_token")

facebook_id = facebook_user.get("id")
user = self._db.get_user(id_type="facebook", user_id=facebook_id)

# Login
# 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:
username = facebook_user.get("name")
email = facebook_user.get("email")
name = facebook_user.get("name")
given_name = facebook_user.get("first_name")
last_name = facebook_user.get("last_name")
family_name = facebook_user.get("last_name")
locale = facebook_user.get("locale")

# check if email exist or name. If yes, associate it with this account
Expand All @@ -265,7 +284,7 @@ def get(self):
user["facebook_id"] = facebook_id
self._db.update_user(user)
else:
user = self._db.create_user(username, name=name, given_name=given_name, last_name=last_name,
user = self._db.create_user(username, name=name, given_name=given_name, family_name=family_name,
locale=locale, email=email, facebook_id=facebook_id)

if user:
Expand Down Expand Up @@ -300,21 +319,33 @@ def get(self):
try:
if self.get_argument("oauth_token", False):
twitter_user = yield self.get_authenticated_user()

# Cancel by the user or other reason
if not twitter_user:
self.redirect("/login?invalid=twitter")
return

access_token = twitter_user.get("access_token")
twitter_user = yield self.twitter_request("/account/verify_credentials",
access_token=access_token, include_email="true")

twitter_id = twitter_user["id_str"]
# Cancel by the user or other reason
if not twitter_user:
self.redirect("/login?invalid=twitter")
return

twitter_id = twitter_user.get("id_str")
user = self._db.get_user(id_type="twitter", user_id=twitter_id)

# Login
# 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:
username = twitter_user["screen_name"]
username = twitter_user.get("screen_name")
name = twitter_user.get("name")
email = twitter_user.get("email")
verified_email = twitter_user.get("verified")
Expand Down
29 changes: 4 additions & 25 deletions src/web/partials/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,7 @@
<li ng-class="{ active: isActive('/character') }"><a href="/character"><span class="glyphicon glyphicon-knight"></span> Personnage</a></li>
<li ng-class="{ active: isActive('/manual') }"><a href="/manual"><span class="glyphicon glyphicon-book"></span> Livre de règle</a></li>
<li ng-class="{ active: isActive('/lore') }"><a href="/lore"><span class="glyphicon glyphicon-globe"></span> Univers</a></li>
{% if not disable_login and not disable_admin and current_user and current_user.get("permission") == "Admin" %}
<li ng-class="{ active: isActive('/admin') }"><a href="admin"><span class="glyphicon glyphicon-king"></span> Admin</a></li>
{% end %}
</ul>

<!--<ul class="nav navbar-nav" ng-show="nav_ariane_menu.length > 0">-->
<!--{% if not disable_custom_css %}-->
<!--<li class="dropdown">-->
<!--<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" ng-cloak>Affichage <span class="caret"></span></a>-->
<!--<ul class="dropdown-menu">-->
<!--<li ng-repeat="style_name in style" ng-class="{ active: isStyle(style_name)}"><a ng-click="updateStyle(style_name)" href="#">{{! style_name }}</a></li>-->
<!--</ul>-->
<!--</li>-->
<!--{% end %}-->

<!--{% if not disable_login %}-->
<!--{% if current_user %}-->
<!--<li><a href="/profile/">{{current_user.get("username")}}</a></li>-->
<!--<li><a href="/logout">Déconnexion</a></li>-->
<!--{% else %}-->
<!--<li ng-class="{ active: isActive('/login') }"><a href="/login">Connexion</a></li>-->
<!--{% end %}-->
<!--{% end %}-->
<!--</ul>-->

<ul class="nav navbar-nav navbar-right">
{% if not disable_custom_css %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" ng-cloak>Affichage <span class="caret"></span></a>
Expand All @@ -102,6 +77,10 @@
</li>
{% end %}

{% if not disable_login and not disable_admin and current_user and current_user.get("permission") == "Admin" %}
<li ng-class="{ active: isActive('/admin') }"><a href="admin" style="color:red;"><span class="glyphicon glyphicon-king"></span> Admin</a></li>
{% end %}

{% if not disable_login %}
{% if current_user %}
<li><a href="/profile/"><span class="glyphicon glyphicon-user"></span> {{current_user.get("username")}}</a></li>
Expand Down
27 changes: 3 additions & 24 deletions src/web/partials/admin/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Traître-Lame, grandeur nature</a>
<a class="navbar-brand" href="#" style="color:red;">ADMIN Traître-Lame</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
Expand All @@ -67,30 +67,7 @@
{% if not disable_character %}
<li ng-class="{ active: isActive('/admin/character') }"><a href="/admin/character"><span class="glyphicon glyphicon-knight"></span> Personnage</a></li>
{% end %}
<li ng-class="{ active: isActive('/') }"><a href="/"><span class="glyphicon glyphicon-remove-circle"></span> Quitter</a></li>
</ul>

<!--<ul class="nav navbar-nav" ng-show="nav_ariane_menu.length > 0">-->
<!--{% if not disable_custom_css %}-->
<!--<li class="dropdown">-->
<!--<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" ng-cloak>Affichage <span class="caret"></span></a>-->
<!--<ul class="dropdown-menu">-->
<!--<li ng-repeat="style_name in style" ng-class="{ active: isStyle(style_name)}"><a ng-click="updateStyle(style_name)" href="#">{{! style_name }}</a></li>-->
<!--</ul>-->
<!--</li>-->
<!--{% end %}-->

<!--{% if not disable_login %}-->
<!--{% if current_user %}-->
<!--<li><a href="/profile/">{{current_user.get("username")}}</a></li>-->
<!--<li><a href="/logout">Déconnexion</a></li>-->
<!--{% else %}-->
<!--<li ng-class="{ active: isActive('/login') }"><a href="/login">Connexion</a></li>-->
<!--{% end %}-->
<!--{% end %}-->
<!--</ul>-->

<ul class="nav navbar-nav navbar-right">
{% if not disable_custom_css %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" ng-cloak>Affichage <span class="caret"></span></a>
Expand All @@ -100,6 +77,8 @@
</li>
{% end %}

<li ng-class="{ active: isActive('/') }"><a href="/" style="color:red;"><span class="glyphicon glyphicon-remove-circle"></span> Quitter</a></li>

{% if not disable_login %}
{% if current_user %}
<li><a href="/profile/"><span class="glyphicon glyphicon-user"></span> {{current_user.get("username")}}</a></li>
Expand Down

0 comments on commit b341237

Please sign in to comment.