From c580aac61be53f0de54667d1daa06b9ebacabd55 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 13 Mar 2013 19:09:26 +0000 Subject: [PATCH] custom login page --- openlp/plugins/remotes/html/login.html | 51 ++++++++++++++++++++++++ openlp/plugins/remotes/html/openlp.css | 8 ++++ openlp/plugins/remotes/lib/httpauth.py | 51 +++++++++++++----------- openlp/plugins/remotes/lib/httpserver.py | 2 + 4 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 openlp/plugins/remotes/html/login.html diff --git a/openlp/plugins/remotes/html/login.html b/openlp/plugins/remotes/html/login.html new file mode 100644 index 000000000..4441958de --- /dev/null +++ b/openlp/plugins/remotes/html/login.html @@ -0,0 +1,51 @@ + + + + + + + + ${title} + + + + + + + + +
+ +

${message}

+

+ User name:
+ Password:
+ +
+ \ No newline at end of file diff --git a/openlp/plugins/remotes/html/openlp.css b/openlp/plugins/remotes/html/openlp.css index 4bc1bf907..60a8fe625 100644 --- a/openlp/plugins/remotes/html/openlp.css +++ b/openlp/plugins/remotes/html/openlp.css @@ -36,3 +36,11 @@ .ui-li .ui-btn-text a.ui-link-inherit{ white-space: normal; } + +.ui-page{ + padding: 100px 100px 100px 100px; + width: 300px; +} +.ui-input-text{ + width: 30px; +} \ No newline at end of file diff --git a/openlp/plugins/remotes/lib/httpauth.py b/openlp/plugins/remotes/lib/httpauth.py index 7e0e2ebe5..d46620855 100644 --- a/openlp/plugins/remotes/lib/httpauth.py +++ b/openlp/plugins/remotes/lib/httpauth.py @@ -35,8 +35,12 @@ http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions import cherrypy import logging +import os + +from mako.template import Template from openlp.core.lib import Settings +from openlp.core.utils import AppLocation, translate SESSION_KEY = '_cp_openlp' @@ -48,6 +52,7 @@ def check_credentials(user_name, password): Verifies credentials for username and password. Returns None on success or a string describing the error on failure """ + print "check" if user_name == Settings().value(u'remotes/user id') and password == Settings().value(u'remotes/password'): return None else: @@ -70,9 +75,12 @@ def check_auth(*args, **kwargs): for condition in conditions: # A condition is just a callable that returns true or false if not condition(): + print "r1" raise cherrypy.HTTPRedirect("/auth/login") else: + print "r2" raise cherrypy.HTTPRedirect("/auth/login") + print "r3" cherrypy.tools.auth = cherrypy.Tool('before_handler', check_auth) @@ -100,36 +108,31 @@ class AuthController(object): """ Called on successful login """ + pass def on_logout(self, username): """ Called on logout """ + pass - def get_loginform(self, username, msg="Enter login information", from_page="/"): + def get_login_form(self, username, message=None, from_page="/"): """ Provides a login form """ - return """ - - - - User Login - - - - - - - - -
- - %(msg)s
- Username:
- Password:
- - """ % locals() + if not message: + message = translate('RemotePlugin.Mobile', 'Enter login information') + variables = { + 'title': translate('RemotePlugin.Mobile', 'OpenLP 2.1 User Login'), + 'from_page': from_page, + 'message': message, + 'username': username + } + directory = os.path.join(AppLocation.get_directory(AppLocation.PluginsDir), u'remotes', u'html') + login_html = os.path.normpath(os.path.join(directory, u'login.html')) + html = Template(filename=login_html, input_encoding=u'utf-8', output_encoding=u'utf-8').render(**variables) + cherrypy.response.headers['Content-Type'] = u'text/html' + return html @cherrypy.expose def login(self, username=None, password=None, from_page="/"): @@ -137,14 +140,14 @@ class AuthController(object): Provides the actual login control """ if username is None or password is None: - return self.get_loginform("", from_page=from_page) - + return self.get_login_form("", from_page=from_page) error_msg = check_credentials(username, password) if error_msg: - return self.get_loginform(username, error_msg, from_page) + return self.get_login_form(username, from_page, error_msg,) else: cherrypy.session[SESSION_KEY] = cherrypy.request.login = username self.on_login(username) + print from_page raise cherrypy.HTTPRedirect(from_page or "/") @cherrypy.expose diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 211608858..db6143eb0 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -174,6 +174,8 @@ class HttpServer(object): cherrypy.config.update({'environment': 'embedded'}) cherrypy.config.update({'engine.autoreload_on': False}) cherrypy.tree.mount(HttpConnection(self), '/', config=self.conf) + # Turn off the flood of access messages cause by poll + cherrypy.log.access_log.propagate = False cherrypy.engine.start() Registry().register_function(u'slidecontroller_live_changed', self.slide_change) Registry().register_function(u'slidecontroller_live_started', self.item_change)