--- a/pvl/login/server.py Mon Jan 13 01:49:34 2014 +0200
+++ b/pvl/login/server.py Mon Jan 13 02:28:19 2014 +0200
@@ -56,6 +56,55 @@
except pubtkt.Error as ex :
self.cookie_error = ex
+ def render_valid (self, valid) :
+ seconds = valid.seconds + valid.days * (24 * 60 * 60)
+
+ minutes, seconds = divmod(seconds, 60)
+ hours, minutes = divmod(minutes, 60)
+
+ return "%2d:%02d:%02d" % (hours, minutes, seconds)
+
+ def render_pubtkt_fields (self, pubtkt) :
+ """
+ Yield (glyphicon, text) to render as fields for ticket.
+ """
+
+ yield 'user', "User account", pubtkt.uid
+
+ valid = self.render_valid(pubtkt.valid())
+
+ if pubtkt.graceperiod :
+ valid = "{valid} ({grace})".format(valid=valid, grace=self.render_valid(pubtkt.grace()))
+
+ yield 'time', "Remaining validity", valid
+
+ if pubtkt.cip :
+ yield 'cloud', "Network address", pubtkt.cip
+
+ if pubtkt.udata :
+ yield 'comment', "Associated data", pubtkt.udata
+
+ for token in pubtkt.tokens :
+ yield 'flag', "Access token", token
+
+ if pubtkt.bauth :
+ yield 'keys', "Authentication token", pubtkt.bauth
+
+ def render_pubtkt (self, pubtkt) :
+
+ return html.div(class_='panel panel-info')(
+ html.div(class_='panel-heading')("Login: {pubtkt.uid}".format(pubtkt=self.pubtkt)),
+ html.div(class_='panel-body')(
+ "This is a valid login ticket.",
+ ),
+ html.ul(class_='list-group')(
+ html.li(class_='list-group-item', title=title)(
+ html.span(class_='glyphicon glyphicon-{glyphicon}'.format(glyphicon=icon)) if icon else None,
+ info,
+ ) for icon, title, info in self.render_pubtkt_fields(pubtkt)
+ ),
+ )
+
def render_info (self) :
if self.cookie_error :
return (
@@ -63,9 +112,8 @@
html.p(self.cookie_error),
)
elif self.pubtkt :
- return (
- html.h2("Login: {pubtkt.uid}".format(pubtkt=self.pubtkt)),
- )
+ return self.render_pubtkt(self.pubtkt)
+
else :
return (
html.a(href=self.url(Login), title="Login")(html.h2("No login")),
@@ -125,14 +173,19 @@
return response
def render (self) :
+ domain = self.app.login_domain
+
return html.div(class_='container')(
html.form(action=self.request.path, method='POST', id='login')(
html.fieldset(
html.legend("Log in"),
html.div(class_='form-group')(
- html.label(for_='username', class_='sr-only')("Username"),
- html.input(name='username', type='text', class_='form-control', placeholder="username", required=True, autofocus=True),
+ html.div(class_='input-group')(
+ html.label(for_='username', class_='sr-only')("Username"),
+ html.input(name='username', type='text', class_='form-control', placeholder="username", required=True, autofocus=True),
+ html.span(class_='input-group-addon')("@{domain}".format(domain=domain)),
+ ),
html.label(for_='password', class_='sr-only')("Password"),
html.input(name='password', type='password', class_='form-control', placeholder="Password", required=True),
@@ -151,7 +204,8 @@
PUBLIC_KEY = 'etc/login/public.pem'
PRIVATE_KEY = 'etc/login/private.pem'
-
+
+ login_domain = 'test.paivola.fi'
login_server = 'https://login.test.paivola.fi/'
login_expire = datetime.timedelta(hours=1)