--- a/pvl/login/server.py Mon Jan 13 18:05:20 2014 +0200
+++ b/pvl/login/server.py Mon Jan 13 18:05:29 2014 +0200
@@ -9,7 +9,8 @@
import pvl.web.response
from pvl.login import pubtkt
-from pvl.web import urls, html
+from pvl.web import urls
+from pvl.web import html5 as html
import logging; log = logging.getLogger('pvl.login.server')
@@ -46,10 +47,10 @@
def init (self) :
self.alerts = []
- def alert (self, type, alert) :
+ def alert (self, type, alert, icon=None) :
log.info(u"%s: %s", type, alert)
- self.alerts.append((type, unicode(alert)))
+ self.alerts.append((type, icon, unicode(alert)))
def process_cookie (self) :
"""
@@ -76,15 +77,15 @@
self.pubtkt = self.app.load(cookie)
except pubtkt.ParseError as ex :
- self.alert('danger', ex)
+ self.alert('danger', ex, icon='compare')
except pubtkt.ExpiredError as ex :
self.pubtkt = ex.pubtkt
- self.alert('warning', ex)
+ self.alert('warning', ex, icon='clock')
except pubtkt.VerifyError as ex :
self.pubtkt = ex.pubtkt
- self.alert('danger', ex)
+ self.alert('danger', ex, icon='warning-sign')
def process_back (self) :
self.server = None
@@ -102,12 +103,21 @@
scheme = url.scheme
else :
- self.alert('info', "Using SSL for application URL")
+ self.alert('info', "Using SSL for application URL", icon='lock')
scheme = self.app.login_scheme
self.server = self.app.check_server(url.hostname)
self.back = urlparse.urlunparse((scheme, self.server, url.path, url.params, url.query, url.fragment))
+ def render_alerts (self) :
+ for type, icon, alert in self.alerts :
+ yield html.div(class_='alert alert-{type}'.format(type=type))(
+ html.span(class_='glyphicon glyphicon-{glyphicon}'.format(glyphicon=icon)) if icon else None,
+ alert
+ )
+
+
+
class Index (Handler) :
TITLE = u"Päivölä Network Login"
@@ -196,32 +206,31 @@
#html.div(class_='btn-toolbar', role='toolbar')(
(
html.form(action=self.url(Login), method='post', class_='form-inline')(
- html.button(type='submit', class_='btn btn-success')("Renew"),
+ html.button(type='submit', class_='btn btn-success')(
+ html.span(class_='glyphicon glyphicon-time'), "Renew"
+ )
)
) if pubtkt.valid() else (
html.form(action=self.url(Login), method='get', class_='form-inline')(
- html.button(type='submit', class_='btn btn-info')("Login"),
+ html.button(type='submit', class_='btn btn-info')(
+ html.span(class_='glyphicon glyphicon-log-in'), "Login"
+ )
),
),
html.form(action=self.url(Logout), method='post', class_='form-inline pull-right')(
- html.button(type='submit', class_='btn btn-warning')("Logout"),
+ html.button(type='submit', class_='btn btn-warning')(
+ html.span(class_='glyphicon glyphicon-log-out'), "Logout"
+ )
),
#),
),
)
- def render_info (self) :
- for type, alert in self.alerts :
- yield html.div(class_='alert alert-{type}'.format(type=type))(alert)
-
- if self.pubtkt :
- yield self.render_pubtkt(self.pubtkt)
-
def render (self) :
-
return html.div(class_='container')(
- self.render_info(),
+ self.render_alerts(),
+ self.render_pubtkt(self.pubtkt) if self.pubtkt else None,
)
class Login (Handler) :
@@ -297,23 +306,20 @@
domain = self.app.login_domain
if 'logout' in self.request.args :
- self.alert('info', "You have been logged out.")
+ self.alert('info', "You have been logged out.", icon='log-out')
if self.pubtkt and self.pubtkt.valid() :
renew = True
# within validity period...
- self.alert('info', "Login or renew ticket.")
+ self.alert('info', "Login or renew ticket.", icon='log-in')
else :
renew = False
return html.div(class_='container')(
html.form(action=self.url(back=self.back), method='POST', id='login')(
- (
- html.div(class_='alert alert-{alert}'.format(alert=type))(alert)
- for type, alert in self.alerts
- ),
+ self.render_alerts(),
html.fieldset(
html.legend(
@@ -336,9 +342,13 @@
html.input(name='password', type='password', class_='form-control', placeholder="Password", required=(not renew)),
),
- html.button(type='submit', class_='btn btn-primary')("Login"),
+ html.button(type='submit', class_='btn btn-primary')(
+ html.span(class_='glyphicon glyphicon-log-in'), "Login"
+ ),
- html.button(type='submit', class_='btn btn-success')("Rewnew") if renew else None,
+ html.button(type='submit', class_='btn btn-success')(
+ html.span(class_='glyphicon glyphicon-time'), "Renew"
+ ) if renew else None,
)
)
)
@@ -370,7 +380,9 @@
html.fieldset(
html.legend("Logout {pubtkt.uid}".format(pubtkt=self.pubtkt)),
- html.button(type='submit', class_='btn btn-warning')("Logout"),
+ html.button(type='submit', class_='btn btn-warning')(
+ html.span(class_='glyphicon glyphicon-log-out'), "Logout"
+ ),
)
)
)