custom login page

This commit is contained in:
Tim Bentley 2013-03-13 19:09:26 +00:00
parent 5c79832bcc
commit c580aac61b
4 changed files with 88 additions and 24 deletions

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<!--
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />
<title>${title}</title>
<link rel="stylesheet" href="/files/jquery.mobile.css" />
<link rel="stylesheet" href="/files/openlp.css" />
<link rel="shortcut icon" type="image/x-icon" href="/files/images/favicon.ico">
<script type="text/javascript" src="/files/jquery.js"></script>
<script type="text/javascript" src="/files/openlp.js"></script>
<script type="text/javascript" src="/files/jquery.mobile.js"></script>
</head>
<body>
<form method="post" action="/auth/login">
<input type="hidden" name="from_page" value="${from_page}" />
<h2>${message}</h2>
</p>
<strong>User name: </strong><input type="text" name="username" value="${username}" /><br />
<strong>Password: </strong><input type="password" name="password" /><br />
<input type="submit" value="Log in" />
</form>
</body></html>

View File

@ -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;
}

View File

@ -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 """<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />
<title>User Login</title>
<link rel="stylesheet" href="/files/jquery.mobile.css" />
<link rel="stylesheet" href="/files/openlp.css" />
<link rel="shortcut icon" type="image/x-icon" href="/files/images/favicon.ico">
<script type="text/javascript" src="/files/jquery.js"></script>
<script type="text/javascript" src="/files/openlp.js"></script>
<script type="text/javascript" src="/files/jquery.mobile.js"></script>
</head>
<body>
<form method="post" action="/auth/login">
<input type="hidden" name="from_page" value="%(from_page)s" />
%(msg)s<br/>
Username: <input type="text" name="username" value="%(username)s" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" value="Log in" />
</body></html>""" % 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

View File

@ -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)