Add Authenticator.auto_login

Simplifies login URL, handler login

- all login redirects go to `settings['login_url']`
- `login_url` is unconditionally `/hub/login`
- `/hub/login` renders form page or 'login with...' button
- enabling auto_login redirects from /hub/login to Authenticator.login_url()
This commit is contained in:
Min RK
2017-04-07 14:49:18 +02:00
parent 5f498ffaf3
commit 6b22f80ead
6 changed files with 47 additions and 10 deletions

View File

@@ -7,8 +7,8 @@ from urllib.parse import urlparse
from tornado.escape import url_escape
from tornado import gen
from tornado.httputil import url_concat
from ..utils import url_path_join
from .base import BaseHandler
@@ -23,8 +23,10 @@ class LogoutHandler(BaseHandler):
self.clear_login_cookie(name)
user.other_user_cookies = set([])
self.statsd.incr('logout')
self.redirect(url_path_join(self.hub.server.base_url, 'login'), permanent=False)
if self.authenticator.auto_login:
self.render('logout.html')
else:
self.redirect(self.settings['login_url'], permanent=False)
class LoginHandler(BaseHandler):
@@ -37,6 +39,7 @@ class LoginHandler(BaseHandler):
login_error=login_error,
custom_html=self.authenticator.custom_html,
login_url=self.settings['login_url'],
authenticator_login_url=self.authenticator.login_url(self.hub.server.base_url),
)
def get(self):
@@ -60,6 +63,16 @@ class LoginHandler(BaseHandler):
self.set_login_cookie(self.get_current_user())
self.redirect(next_url, permanent=False)
else:
if self.authenticator.auto_login:
auto_login_url = self.authenticator.login_url(self.hub.server.base_url)
if auto_login_url == self.settings['login_url']:
self.authenticator.auto_login = False
self.log.warning("Authenticator.auto_login cannot be used without a custom login_url")
else:
if next_url:
auto_login_url = url_concat(auto_login_url, {'next': next_url})
self.redirect(auto_login_url)
return
username = self.get_argument('username', default='')
self.finish(self._render(username=username))