User Tools

Site Tools


web2py
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


web2py [2011/08/13 13:54] (current) – created jtkorb
Line 1: Line 1:
 +====== Controller index Code that Needs a CAS Ticket to Work ======
  
 +<code python>
 +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)
 +</code>
web2py.txt · Last modified: 2011/08/13 13:54 by jtkorb