From ece3eecf7f554ab23f70ab27415184edb1c98d7f 2014-12-07 22:10:54 From: Min RK Date: 2014-12-07 22:10:54 Subject: [PATCH] allow LoginHandler to override get_current_user --- diff --git a/IPython/html/auth/login.py b/IPython/html/auth/login.py index 2fd94ad..9de7fcf 100644 --- a/IPython/html/auth/login.py +++ b/IPython/html/auth/login.py @@ -44,6 +44,24 @@ class LoginHandler(IPythonHandler): self.redirect(self.get_argument('next', default=self.base_url)) + @staticmethod + def get_user(handler): + """Called by handlers for identifying the current user.""" + # Can't call this get_current_user because it will collide when + # called on LoginHandler itself. + + user_id = handler.get_secure_cookie(handler.cookie_name) + # For now the user_id should not return empty, but it could eventually + if user_id == '': + user_id = 'anonymous' + if user_id is None: + # prevent extra Invalid cookie sig warnings: + handler.clear_login_cookie() + if not handler.login_available: + user_id = 'anonymous' + return user_id + + @classmethod def validate_notebook_app_security(cls, notebook_app, ssl_options=None): if not notebook_app.ip: diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index 882c0a4..a45d4f7 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -68,16 +68,9 @@ class AuthenticatedHandler(web.RequestHandler): self.clear_cookie(self.cookie_name) def get_current_user(self): - user_id = self.get_secure_cookie(self.cookie_name) - # For now the user_id should not return empty, but it could eventually - if user_id == '': - user_id = 'anonymous' - if user_id is None: - # prevent extra Invalid cookie sig warnings: - self.clear_login_cookie() - if not self.login_available: - user_id = 'anonymous' - return user_id + if self.login_handler is None: + return 'anonymous' + return self.login_handler.get_user(self) @property def cookie_name(self):