User Tools

Site Tools


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 = ''
    my_url = ''
    if request.vars.ticket:
        url = "%s?service=%s&ticket=%s" % (check_url, my_url, ticket)
        url = 'bogus'
    data = urllib.urlopen(url).read()
    attrs = dict()
        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
            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