Commit fe3e1a37 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

astakos: Set initial signup values if available

prefill third party signup form with initial values (first name, last name,
email) if available in the third party provider response.
parent 0a23f7d3
......@@ -755,9 +755,13 @@ class TestAuthProviderViews(TestCase):
# new academic user
self.assertFalse(academic_users.filter(email='newuser@synnefo.org'))
cl_newuser.set_tokens(eppn="newusereppn")
cl_newuser.set_tokens(eppn="newusereppn", mail="newuser@synnefo.org",
surname="Lastname")
r = cl_newuser.get(ui_url('login/shibboleth?'), follow=True)
initial = r.context['signup_form'].initial
pending = Pending.objects.get()
self.assertEqual(initial.get('last_name'), 'Lastname')
self.assertEqual(initial.get('email'), 'newuser@synnefo.org')
identifier = pending.third_party_identifier
signup_data = {'third_party_identifier': identifier,
'first_name': 'Academic',
......
......@@ -413,6 +413,7 @@ def signup(request, template_name='im/signup.html', on_success='index',
# user registered using third party provider
third_party_token = request.REQUEST.get('third_party_token', None)
unverified = None
pending = None
if third_party_token:
# retreive third party entry. This was created right after the initial
# third party provider handshake.
......@@ -446,9 +447,17 @@ def signup(request, template_name='im/signup.html', on_success='index',
if third_party_token:
form_kwargs['third_party_token'] = third_party_token
if pending:
form_kwargs['initial'] = {
'first_name': pending.first_name,
'last_name': pending.last_name,
'email': pending.email
}
form = activation_backend.get_signup_form(
provider, None, **form_kwargs)
if request.method == 'POST':
form = activation_backend.get_signup_form(
provider,
......
......@@ -90,10 +90,10 @@ def login(request,
try:
eppn = tokens.get(Tokens.SHIB_EPPN)
fullname, first_name, last_name, email = None, None, None, None
if global_settings.DEBUG and not eppn:
eppn = getattr(global_settings, 'SHIBBOLETH_TEST_EPPN', None)
realname = getattr(global_settings, 'SHIBBOLETH_TEST_REALNAME',
fullname = getattr(global_settings, 'SHIBBOLETH_TEST_FULLNAME',
None)
if not eppn:
......@@ -102,17 +102,23 @@ def login(request,
'contact_email': settings.CONTACT_EMAIL
})
if Tokens.SHIB_DISPLAYNAME in tokens:
realname = tokens[Tokens.SHIB_DISPLAYNAME]
fullname = tokens[Tokens.SHIB_DISPLAYNAME]
elif Tokens.SHIB_CN in tokens:
realname = tokens[Tokens.SHIB_CN]
elif Tokens.SHIB_NAME in tokens and Tokens.SHIB_SURNAME in tokens:
realname = tokens[Tokens.SHIB_NAME] + ' ' + \
tokens[Tokens.SHIB_SURNAME]
else:
if settings.SHIBBOLETH_REQUIRE_NAME_INFO:
raise KeyError(_(astakos_messages.SHIBBOLETH_MISSING_NAME))
else:
realname = ''
fullname = tokens[Tokens.SHIB_CN]
if Tokens.SHIB_NAME in tokens:
first_name = tokens[Tokens.SHIB_NAME]
if Tokens.SHIB_SURNAME in tokens:
last_name = tokens[Tokens.SHIB_SURNAME]
if fullname:
splitted = fullname.split(' ', 1)
if len(splitted) == 2:
first_name, last_name = splitted
fullname = '%s %s' % (first_name, last_name)
if not any([first_name, last_name]) and \
settings.SHIBBOLETH_REQUIRE_NAME_INFO:
raise KeyError(_(astakos_messages.SHIBBOLETH_MISSING_NAME))
except KeyError, e:
# invalid shibboleth headers, redirect to login, display message
......@@ -122,7 +128,7 @@ def login(request,
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, 'Shibboleth')
email = tokens.get(Tokens.SHIB_MAIL, '')
eppn_info = tokens.get(Tokens.SHIB_EPPN)
provider_info = {'eppn': eppn_info, 'email': email, 'name': realname,
provider_info = {'eppn': eppn_info, 'email': email, 'name': fullname,
'headers': shibboleth_headers}
userid = eppn
......@@ -132,7 +138,10 @@ def login(request,
affiliation, third_party_key)
except AstakosUser.DoesNotExist, e:
third_party_key = get_pending_key(request)
user_info = {'affiliation': affiliation, 'realname': realname}
user_info = {'affiliation': affiliation,
'first_name': first_name,
'last_name': last_name,
'email': email}
return handle_third_party_signup(request, userid, 'shibboleth',
third_party_key,
provider_info,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment