Skip to content

Commit

Permalink
fix(auth): logout
Browse files Browse the repository at this point in the history
Closes #87
  • Loading branch information
nritsche committed Nov 27, 2020
1 parent 79899e9 commit 0d451f0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions bondia/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def get_user(request_handler):

# If this is done by defining login_url directly, tornado is inconsistent with the root url.
def get_login_url(request):
root_url = os.getenv("BONDIA_ROOT_URL", "")
return root_url + "/login"


Expand Down Expand Up @@ -56,10 +55,11 @@ def get_user(self):
return user


logout_url = os.getenv("BONDIA_LOGOUT_URL", "/logout")
def get_logout_url(request):
return root_url + "/logout"


class LogoutHandler(tornado.web.RequestHandler):
class CustomLogoutHandler(tornado.web.RequestHandler):
def get(self):
self.clear_cookie("user")
self.redirect(os.getenv("BONDIA_NEXT_URL", "/"))
Expand Down
6 changes: 5 additions & 1 deletion bondia/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@


class BondiaGui(param.Parameterized):
def __init__(self, template, width_drawer_widgets, data_loader, config_plots):
def __init__(
self, template, width_drawer_widgets, data_loader, config_plots, root_url
):
self._width_drawer_widgets = width_drawer_widgets
self._template = template
self._plot = {}
self._toggle_plot = {}
self._opinion_buttons = {}
self._data = data_loader
self._config_plots = config_plots
self._root_url = root_url
self._opinion_header = pn.pane.Markdown(
"####Opinion", width=width_drawer_widgets
)
Expand Down Expand Up @@ -323,5 +326,6 @@ def render(self):
template.add_variable("app_title", "BON DIA")
template.add_variable("username", self.current_user)
template.add_variable("num_unvalidated", 19)
template.add_variable("root_url", self._root_url)

return self.populate_template(template)
1 change: 1 addition & 0 deletions bondia/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def gui_instance(self):
self._width_drawer_widgets,
self.data,
self._config_plots,
self.root_url,
).render()
return instance

Expand Down
2 changes: 1 addition & 1 deletion bondia/templates/mdl.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="mdl-layout-spacer"></div>
<!-- Navigation. We hide it in small screens. -->
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="/bondia/logout">Logout <i>{{ username }}</i></a>
<a class="mdl-navigation__link" href="{{ root_url }}/logout">Logout <i>{{ username }}</i></a>
{{ embed(roots.busy_indicator) }}
</nav>
</div>
Expand Down
5 changes: 4 additions & 1 deletion scripts/bondia-server
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def start(

# We have to redirect to the login handler manually, because tornado doesn't know about
# the root URL.
kwargs["extra_patterns"] = [(r"/login", auth.CustomLoginHandler)]
kwargs["extra_patterns"] = [
(r"/login", auth.CustomLoginHandler),
(r"/logout", auth.CustomLogoutHandler),
]
kwargs["auth_provider"] = AuthModule(auth.__file__)

panel.serve(
Expand Down

0 comments on commit 0d451f0

Please sign in to comment.