Revision 4e30244e snf-astakos-app/astakos/im/target/shibboleth.py
b/snf-astakos-app/astakos/im/target/shibboleth.py | ||
---|---|---|
39 | 39 |
from astakos.im.util import get_or_create_user, prepare_response, get_context, get_invitation |
40 | 40 |
from astakos.im.views import requires_anonymous, render_response |
41 | 41 |
from astakos.im.settings import DEFAULT_USER_LEVEL |
42 |
from astakos.im.models import AstakosUser |
|
43 |
from astakos.im.forms import ShibbolethUserCreationForm, LoginForm |
|
42 |
from astakos.im.models import AstakosUser, Invitation |
|
43 |
from astakos.im.forms import LoginForm |
|
44 |
from astakos.im.activation_backends import get_backend, SimpleBackend |
|
44 | 45 |
|
45 | 46 |
class Tokens: |
46 | 47 |
# these are mapped by the Shibboleth SP software |
... | ... | |
54 | 55 |
|
55 | 56 |
@requires_anonymous |
56 | 57 |
def login(request, backend=None, on_login_template='im/login.html', on_creation_template='im/signup.html', extra_context={}): |
57 |
#tokens = request.META
|
|
58 |
# |
|
59 |
#try:
|
|
60 |
# eppn = tokens[Tokens.SHIB_EPPN]
|
|
61 |
#except KeyError:
|
|
62 |
# return HttpResponseBadRequest("Missing unique token in request")
|
|
63 |
# |
|
64 |
#if Tokens.SHIB_DISPLAYNAME in tokens:
|
|
65 |
# realname = tokens[Tokens.SHIB_DISPLAYNAME]
|
|
66 |
#elif Tokens.SHIB_CN in tokens:
|
|
67 |
# realname = tokens[Tokens.SHIB_CN]
|
|
68 |
#elif Tokens.SHIB_NAME in tokens and Tokens.SHIB_SURNAME in tokens:
|
|
69 |
# realname = tokens[Tokens.SHIB_NAME] + ' ' + tokens[Tokens.SHIB_SURNAME]
|
|
70 |
#else:
|
|
71 |
# return HttpResponseBadRequest("Missing user name in request")
|
|
72 |
# |
|
73 |
#affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
|
|
58 |
tokens = request.META |
|
59 |
|
|
60 |
try: |
|
61 |
eppn = tokens[Tokens.SHIB_EPPN] |
|
62 |
except KeyError: |
|
63 |
return HttpResponseBadRequest("Missing unique token in request") |
|
64 |
|
|
65 |
if Tokens.SHIB_DISPLAYNAME in tokens: |
|
66 |
realname = tokens[Tokens.SHIB_DISPLAYNAME] |
|
67 |
elif Tokens.SHIB_CN in tokens: |
|
68 |
realname = tokens[Tokens.SHIB_CN] |
|
69 |
elif Tokens.SHIB_NAME in tokens and Tokens.SHIB_SURNAME in tokens: |
|
70 |
realname = tokens[Tokens.SHIB_NAME] + ' ' + tokens[Tokens.SHIB_SURNAME] |
|
71 |
else: |
|
72 |
return HttpResponseBadRequest("Missing user name in request") |
|
73 |
|
|
74 |
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '') |
|
74 | 75 |
|
75 |
eppn, realname, affiliation = 'spapagian', 'Sofia Papagiannaki', 'grnet' |
|
76 | 76 |
try: |
77 | 77 |
user = AstakosUser.objects.get(provider='shibboleth', third_party_identifier=eppn) |
78 | 78 |
if user.is_active: |
... | ... | |
88 | 88 |
context_instance=RequestContext(request)) |
89 | 89 |
except AstakosUser.DoesNotExist, e: |
90 | 90 |
user = AstakosUser(third_party_identifier=eppn, realname=realname, |
91 |
affiliation=affiliation, |
|
92 |
provider='shibboleth') |
|
91 |
affiliation=affiliation, provider='shibboleth') |
|
92 |
try: |
|
93 |
if not backend: |
|
94 |
backend = get_backend(request) |
|
95 |
form = backend.get_signup_form(provider='shibboleth', instance=user) |
|
96 |
except (Invitation.DoesNotExist, ValueError), e: |
|
97 |
form = SimpleBackend(request).get_signup_form(provider='shibboleth', instance=user) |
|
98 |
messages.add_message(request, messages.ERROR, e) |
|
99 |
form.data.update({'third_party_identifier':eppn, 'realname':realname, |
|
100 |
'affiliation':affiliation}) |
|
93 | 101 |
return render_response(on_creation_template, |
94 |
signup_form = ShibbolethUserCreationForm(instance=user), |
|
95 |
provider = 'shibboleth', |
|
102 |
signup_form = form, |
|
96 | 103 |
context_instance=get_context(request, extra_context)) |
Also available in: Unified diff