web2py
Controller index Code that Needs a CAS Ticket to Work
def index(): """ example action using the internationalization operator T and flash rendered by views/default/index.html or views/generic.html """ import urllib import xml.dom.minidom as dom import xml.parsers.expat as expat check_url = 'https://www.purdue.edu/apps/account/cas/serviceValidate' my_url = 'https://pc.cs.purdue.edu:8443/testcas/default/login' if request.vars.ticket: url = "%s?service=%s&ticket=%s" % (check_url, my_url, ticket) else: url = 'bogus' data = urllib.urlopen(url).read() attrs = dict() try: dxml = dom.parseString(data) envelop = dxml.getElementsByTagName("cas:attributes") if len(envelop) > 0: for x in envelop[0].childNodes: if x.nodeName.startswith('cas:') and len(x.childNodes): key = x.nodeName[4:].encode('utf8') value = x.childNodes[0].nodeValue.encode('utf8') attrs[key] = value else: attrs['attr'] = 'no attributes' except expat.ExpatError: attrs['attrs'] = 'expat error' return dict(message=T('Hello World'), token=session.token, attrs=attrs, data=data)
web2py.txt · Last modified: 2011/08/13 13:54 by jtkorb