From 8d3a7b704c676063a41546a719dde2377a569d77 Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Wed, 23 Dec 2020 13:03:27 +0900 Subject: [PATCH 1/5] Render custom html --- jupyterhub/handlers/login.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/jupyterhub/handlers/login.py b/jupyterhub/handlers/login.py index 605cd580..16f26f1a 100644 --- a/jupyterhub/handlers/login.py +++ b/jupyterhub/handlers/login.py @@ -3,6 +3,7 @@ # Distributed under the terms of the Modified BSD License. import asyncio +from jinja2 import Template from tornado import web from tornado.escape import url_escape from tornado.httputil import url_concat @@ -90,17 +91,21 @@ class LoginHandler(BaseHandler): """Render the login page.""" def _render(self, login_error=None, username=None): + context = { + "next": url_escape(self.get_argument('next', default='')), + "username": username, + "login_error": login_error, + "login_url": self.settings['login_url'], + "authenticator_login_url": url_concat( + self.authenticator.login_url(self.hub.base_url), + {'next': self.get_argument('next', '')}, + ), + } + custom_html = Template(self.authenticator.custom_html).render(**context) return self.render_template( 'login.html', - next=url_escape(self.get_argument('next', default='')), - username=username, - login_error=login_error, - custom_html=self.authenticator.custom_html, - login_url=self.settings['login_url'], - authenticator_login_url=url_concat( - self.authenticator.login_url(self.hub.base_url), - {'next': self.get_argument('next', '')}, - ), + **context, + custom_html=custom_html, ) async def get(self): From c833fae9011bb88f16cf0aff5737c58149a9beb5 Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Wed, 23 Dec 2020 13:39:59 +0900 Subject: [PATCH 2/5] Allow to use base URL in custom HTML --- jupyterhub/auth.py | 3 +++ jupyterhub/handlers/login.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/jupyterhub/auth.py b/jupyterhub/auth.py index 33a00bef..98308610 100644 --- a/jupyterhub/auth.py +++ b/jupyterhub/auth.py @@ -1101,6 +1101,9 @@ class PAMAuthenticator(LocalAuthenticator): else: return super().normalize_username(username) + def get_custom_html(self, base_url): + return self.custom_html + for _old_name, _new_name, _version in [ ("check_group_whitelist", "check_group_allowed", "1.2"), diff --git a/jupyterhub/handlers/login.py b/jupyterhub/handlers/login.py index 16f26f1a..599c8540 100644 --- a/jupyterhub/handlers/login.py +++ b/jupyterhub/handlers/login.py @@ -101,7 +101,7 @@ class LoginHandler(BaseHandler): {'next': self.get_argument('next', '')}, ), } - custom_html = Template(self.authenticator.custom_html).render(**context) + custom_html = Template(self.authenticator.get_custom_html(self.hub.base_url)).render(**context) return self.render_template( 'login.html', **context, From ca3ceac4f34a7a55504ac5b63d024fdb4f2341d9 Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Wed, 23 Dec 2020 13:42:51 +0900 Subject: [PATCH 3/5] Add comment --- jupyterhub/auth.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jupyterhub/auth.py b/jupyterhub/auth.py index 98308610..79aed549 100644 --- a/jupyterhub/auth.py +++ b/jupyterhub/auth.py @@ -1102,6 +1102,7 @@ class PAMAuthenticator(LocalAuthenticator): return super().normalize_username(username) def get_custom_html(self, base_url): + """Get custom HTML for the authenticator.""" return self.custom_html From 0b085a91b6bc8128c8289a2584ab49ec8dc3be07 Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Wed, 23 Dec 2020 13:50:27 +0900 Subject: [PATCH 4/5] Fix format issues --- jupyterhub/handlers/login.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/jupyterhub/handlers/login.py b/jupyterhub/handlers/login.py index 599c8540..29f2ff02 100644 --- a/jupyterhub/handlers/login.py +++ b/jupyterhub/handlers/login.py @@ -92,16 +92,18 @@ class LoginHandler(BaseHandler): def _render(self, login_error=None, username=None): context = { - "next": url_escape(self.get_argument('next', default='')), - "username": username, - "login_error": login_error, - "login_url": self.settings['login_url'], - "authenticator_login_url": url_concat( - self.authenticator.login_url(self.hub.base_url), - {'next': self.get_argument('next', '')}, - ), + "next": url_escape(self.get_argument('next', default='')), + "username": username, + "login_error": login_error, + "login_url": self.settings['login_url'], + "authenticator_login_url": url_concat( + self.authenticator.login_url(self.hub.base_url), + {'next': self.get_argument('next', '')}, + ), } - custom_html = Template(self.authenticator.get_custom_html(self.hub.base_url)).render(**context) + custom_html = Template( + self.authenticator.get_custom_html(self.hub.base_url) + ).render(**context) return self.render_template( 'login.html', **context, From 47265786e3f97141ae963e06dd67fb73ab4f4bc9 Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Wed, 27 Jan 2021 20:49:47 +0900 Subject: [PATCH 5/5] Add versionadded --- jupyterhub/auth.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jupyterhub/auth.py b/jupyterhub/auth.py index 79aed549..09d09a02 100644 --- a/jupyterhub/auth.py +++ b/jupyterhub/auth.py @@ -1102,7 +1102,10 @@ class PAMAuthenticator(LocalAuthenticator): return super().normalize_username(username) def get_custom_html(self, base_url): - """Get custom HTML for the authenticator.""" + """Get custom HTML for the authenticator. + + .. versionadded: 1.4 + """ return self.custom_html