root / aai / views.py @ 71:00236c4d72ba
History | View | Annotate | Download (2.7 kB)
1 |
import time |
---|---|
2 |
|
3 |
from os import environ |
4 |
|
5 |
from aai.models import * |
6 |
from aai.util import * |
7 |
from grnet_aai.idpmap import * |
8 |
from django.shortcuts import render_to_response |
9 |
from django.conf import settings |
10 |
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound |
11 |
from django.utils.http import urlencode |
12 |
from django.template.loader import render_to_string |
13 |
|
14 |
|
15 |
def index(request): |
16 |
return render_to_response("index.html") |
17 |
|
18 |
def idp_list(request): |
19 |
metadata = ShibbolethMetadata(settings.SHIB_METADATA) |
20 |
idps = metadata.getIdps() |
21 |
idplist = idps.getIdpsByCategory(exclude=('wayf', 'test')) |
22 |
|
23 |
return render_to_response("idp_list.html", { 'idplist' : idplist } ) |
24 |
|
25 |
def static(request, path): |
26 |
# A catch-all view, trying to render all our static pages or give a 404
|
27 |
try:
|
28 |
return render_to_response(path + ".html") |
29 |
except:
|
30 |
return HttpResponseNotFound(render_to_string("404.html")) |
31 |
|
32 |
def support(request, mode="support"): |
33 |
# This gets triggered when a user's attributes fail to be accepted
|
34 |
# by a service provider. The aim is to produce a help page, indicating
|
35 |
# the user's home institution contact details.
|
36 |
|
37 |
opts = {} |
38 |
userIdp = None
|
39 |
|
40 |
# Check to see whether _redirect_user_idp is set. This cookie will include
|
41 |
# The user's selected IdP
|
42 |
if settings.IDP_COOKIE in request.COOKIES.keys(): |
43 |
userIdp = urldecode(request.COOKIES[settings.IDP_COOKIE]) |
44 |
elif settings.LAST_IDP_COOKIE in request.COOKIES.keys(): |
45 |
userIdp = urldecode(request.COOKIES[settings.LAST_IDP_COOKIE]) |
46 |
|
47 |
if userIdp:
|
48 |
# Check to see if this is one of the old WAYF entries and map it to a
|
49 |
# new entityID instead.
|
50 |
if userIdp in idpmap.keys(): |
51 |
userIdp = idpmap[userIdp] |
52 |
|
53 |
# Get the corresponding IdentityProvider instance
|
54 |
idp = ShibbolethMetadata(settings.SHIB_METADATA).getIdps()[userIdp] |
55 |
|
56 |
if idp:
|
57 |
opts['idp'] = idp
|
58 |
opts['idpname'] = idp.getName()
|
59 |
|
60 |
if mode == "help": |
61 |
response = render_to_response("help.html", opts)
|
62 |
else:
|
63 |
response = render_to_response("support.html", opts)
|
64 |
|
65 |
response['P3P'] = 'CP="NOI CUR DEVa OUR IND COM NAV PRE"' |
66 |
return response
|
67 |
|
68 |
def setlanguage(request, lang): |
69 |
response = HttpResponseRedirect(request.META['HTTP_REFERER'])
|
70 |
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang, domain='.grnet.gr', max_age = 100 * 86400, expires = time.strftime("%a, %d-%m-%y %H:%M:%S GMT", time.gmtime(time.time() + 100 * 86400))) |
71 |
response['P3P'] = 'CP="NOI CUR DEVa OUR IND COM NAV PRE"' |
72 |
return response
|
73 |
|
74 |
def debug(request): |
75 |
return HttpResponse("<br />\n".join(map(lambda x: "%s: %s" % (x[0], x[1]), environ.items()))) |
76 |
|