source: TI12-security/trunk/NDGSecurity/python/Tests/openid-provider/op/op/lib/rendering.py @ 7080

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/openid-provider/op/op/lib/rendering.py@7080
Revision 7080, 4.0 KB checked in by pjkersha, 10 years ago (diff)
  • Property svn:keywords set to Id
Line 
1import pylons
2from pylons.templating import Buffet
3from pylons import config
4import ndg.security.server.sso.sso.lib.helpers as h
5import logging
6log = logging.getLogger(__name__)
7
8class MyBuffet(Buffet):
9    def _update_names(self, ns):
10        return ns
11
12def_eng = config['buffet.template_engines'][0]
13buffet = MyBuffet(
14    def_eng['engine'],
15    template_root=def_eng['template_root'],
16    **def_eng['template_options']
17)
18
19for e in config['buffet.template_engines'][1:]:
20    buffet.prepare(
21        e['engine'],
22        template_root=e['template_root'],
23        alias=e['alias'],
24        **e['template_options']
25    )
26
27class State:
28    def __init__(self, urls={}, session={}):
29        self.title = ''
30        self.xml = ''
31        self.headExtras = ''
32        self.session = session
33        self.loginStatus = True
34        self.urls = urls
35
36def _render(templateName, **kw):
37    ''''''
38    rendering = buffet.render(template_name=templateName, namespace=kw)
39    return rendering
40
41config['pylons.g'].server = "http://localhost:8700"
42config['pylons.g'].LeftLogo = config['pylons.g'].server+'/layout/NERC_Logo.gif'
43config['pylons.g'].LeftAlt = 'Natural Environment Research Council'
44config['pylons.g'].ndgLink = 'http://ndg.nerc.ac.uk/'
45config['pylons.g'].ndgImage = config['pylons.g'].server+'/layout/ndg_logo_circle.gif'
46config['pylons.g'].disclaimer = ''
47config['pylons.g'].stfcLink = 'http://ceda.stfc.ac.uk/'
48config['pylons.g'].stfcImage = config['pylons.g'].server+'/layout/stfc-circle-sm.gif'
49config['pylons.g'].helpIcon = config['pylons.g'].server+'/layout/icons/help.png'
50
51from ndg.security.server.wsgi.openid.provider import RenderingInterface
52
53class OpenIDProviderKidRendering(RenderingInterface):
54    """Provide Kid Templating for OpenID Provider Middleware"""
55   
56    def login(self, environ, success_to=None, fail_to=None):
57        """Set-up Kid template for OpenID Provider Login"""
58        c = State(urls=self.urls, session=self.session)
59        c.title = "OpenID Login"
60        c.success_to = success_to or self.urls['url_mainpage']
61        c.fail_to = fail_to or self.urls['url_mainpage'] 
62   
63        return _render('ndg.security.login', c=c, g=config['pylons.g'], h=h)
64       
65       
66    def mainPage(self, environ):
67        """Set-up Kid template for OpenID Provider Login"""
68        c = State(urls=self.urls, session=self.session)
69        c.title = "OpenID Provider"
70        c.headExtras = '<meta http-equiv="x-xrds-location" content="%s"/>' % \
71                        self.urls['url_serveryadis']
72   
73        return _render('ndg.security.mainPage', c=c, g=config['pylons.g'], h=h)
74
75
76    def identityPage(self, environ):
77        """Identity page"""
78        path = environ['PATH_INFO']
79        username = path[4:]
80        if not username:
81            h.redirect_to(self.urls['url_mainpage'])
82           
83        c = State(urls=self.urls, session=self.session)
84        c.title = "OpenID Identity Page"
85                       
86        link_tag = '<link rel="openid.server" href="%s"/>' % \
87              self.urls['url_openidserver']
88             
89        yadis_loc_tag = '<meta http-equiv="x-xrds-location" content="%s"/>' % \
90            (self.urls['url_yadis']+'/'+username)
91           
92        c.headExtras = link_tag + yadis_loc_tag
93        identityURL = self.base_url + path
94        c.xml = "<b><pre>%s</pre></b>" % identityURL
95       
96        return _render('ndg.security.identityPage',
97                       c=c, g=config['pylons.g'], h=h)   
98   
99    def decidePage(self, environ, oidRequest):
100        """Handle user interaction required before final submit back to Relying
101        Party"""
102        c = State(urls=self.urls, session=self.session)
103        c.title = 'Approve OpenID Request?'
104        c.trust_root = oidRequest.trust_root
105        c.oidRequest = oidRequest
106       
107        return _render('ndg.security.decidePage', c=c,g=config['pylons.g'],h=h)
108
109       
110    def errorPage(self, environ, msg):
111        c = State(urls=self.urls, session=self.session)
112        c.title = 'Error with OpenID Provider'
113        c.xml = msg
114        return _render('ndg.security.error', c=c, g=config['pylons.g'], h=h)
Note: See TracBrowser for help on using the repository browser.