Commit f46077e3 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Enable inactive shibboleth users to change email

Refs: #3041
parent 320f57a6
......@@ -187,13 +187,18 @@ class InvitedLocalUserCreationForm(LocalUserCreationForm):
return user
class ThirdPartyUserCreationForm(forms.ModelForm):
id = forms.CharField(
widget=forms.HiddenInput(),
label='',
required=False
)
third_party_identifier = forms.CharField(
widget=forms.HiddenInput(),
label=''
)
class Meta:
model = AstakosUser
fields = ['email', 'third_party_identifier', 'first_name', 'last_name']
fields = ['id', 'email', 'third_party_identifier', 'first_name', 'last_name']
def __init__(self, *args, **kwargs):
"""
......@@ -280,11 +285,14 @@ class ShibbolethUserCreationForm(ThirdPartyUserCreationForm):
def clean_email(self):
email = self.cleaned_data['email']
for user in AstakosUser.objects.filter(email = email):
if self.instance:
if self.instance.email == email:
raise forms.ValidationError(_("This is your current email."))
for user in AstakosUser.objects.filter(email=email):
if user.provider == 'shibboleth':
raise forms.ValidationError(_(
"This email is already associated with another shibboleth \
account."
"This email is already associated with another \
shibboleth account."
)
)
else:
......
......@@ -86,7 +86,7 @@ def login(request, on_failure='im/login.html'):
else:
url = reverse('send_activation', kwargs={'user_id':user.id})
message = _('You have not followed the activation link. \
<a href="%s">Provide new email?</a>' % url)
<a href="%s">Resend activation email?</a>' % url)
elif user.provider not in ('local', ''):
message = _(
'Local login is not the current authentication method for this account.'
......
......@@ -78,30 +78,28 @@ def login(
tokens = request.META
# try:
# eppn = tokens.get(Tokens.SHIB_EPPN)
# if not eppn:
# raise KeyError(_('Missing unique token in request'))
# if Tokens.SHIB_DISPLAYNAME in tokens:
# realname = 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:
# raise KeyError(_('Missing user name in request'))
# except KeyError, e:
# extra_context['login_form'] = LoginForm(request=request)
# messages.error(request, e)
# return render_response(
# login_template,
# context_instance=get_context(request, extra_context)
# )
#
# affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
# email = tokens.get(Tokens.SHIB_MAIL, '')
try:
eppn = tokens.get(Tokens.SHIB_EPPN)
if not eppn:
raise KeyError(_('Missing unique token in request'))
if Tokens.SHIB_DISPLAYNAME in tokens:
realname = 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:
raise KeyError(_('Missing user name in request'))
except KeyError, e:
extra_context['login_form'] = LoginForm(request=request)
messages.error(request, e)
return render_response(
login_template,
context_instance=get_context(request, extra_context)
)
eppn, realname, affiliation, email = 'shibboleth1', 'shib Boleth', '', ''
affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
email = tokens.get(Tokens.SHIB_MAIL, '')
try:
user = AstakosUser.objects.get(
......@@ -180,13 +178,14 @@ def signup(
extra_context=None
):
extra_context = extra_context or {}
if not username:
return HttpResponseBadRequest(_('Missing key parameter.'))
try:
pending = PendingThirdPartyUser.objects.get(username=username)
except BaseException, e:
except PendingThirdPartyUser.DoesNotExist:
try:
user = AstakosUser.objects.get(username=username)
except BaseException, e:
logger.exception(e)
except AstakosUser.DoesNotExist:
return HttpResponseBadRequest(_('Invalid key.'))
else:
d = pending.__dict__
......
......@@ -334,10 +334,16 @@ def signup(request, template_name='im/signup.html', on_success='im/signup_comple
return HttpResponseRedirect(reverse('astakos.im.views.edit_profile'))
provider = get_query(request).get('provider', 'local')
id = get_query(request).get('id')
try:
instance = AstakosUser.objects.get(id=id) if id else None
except AstakosUser.DoesNotExist:
instance = None
try:
if not backend:
backend = get_backend(request)
form = backend.get_signup_form(provider)
form = backend.get_signup_form(provider, instance)
except Exception, e:
form = SimpleBackend(request).get_signup_form(provider)
messages.add_message(request, messages.ERROR, e)
......@@ -353,14 +359,22 @@ def signup(request, template_name='im/signup.html', on_success='im/signup_comple
additional_email = form.cleaned_data['additional_email']
if additional_email != user.email:
user.additionalmail_set.create(email=additional_email)
msg = 'Additional email: %s saved for user %s.' % (additional_email, user.email)
msg = 'Additional email: %s saved for user %s.' % (
additional_email,
user.email
)
logger._log(LOGGING_LEVEL, msg, [])
if user and user.is_active:
next = request.POST.get('next', '')
return prepare_response(request, user, next=next)
messages.add_message(request, status, message)
return render_response(on_success,
context_instance=get_context(request, extra_context))
return render_response(
on_success,
context_instance=get_context(
request,
extra_context
)
)
except SendMailError, e:
logger.exception(e)
status = messages.ERROR
......
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