Revision d1757ca7

b/snf-astakos-app/astakos/im/views.py
52 52
from django.db.utils import IntegrityError
53 53
from django.contrib.auth.views import password_change
54 54
from django.core.exceptions import ValidationError
55
from django.db.models import Q
55 56

  
56 57
from astakos.im.models import AstakosUser, Invitation, ApprovalTerms
57 58
from astakos.im.activation_backends import get_backend, SimpleBackend
......
442 443
    except AstakosUser.DoesNotExist:
443 444
        return HttpResponseBadRequest(_('No such user'))
444 445
    
446
    if user.is_active:
447
        message = 'Account already active.'
448
        messages.add_message(request, messages.ERROR, message)
449
        return render_response(on_failure)
450
    
445 451
    try:
446
        local_user = AstakosUser.objects.get(email=user.email, is_active=True)
452
        local_user = AstakosUser.objects.get(~Q(id = user.id), email=user.email, is_active=True)
447 453
    except AstakosUser.DoesNotExist:
448 454
        user.is_active = True
449 455
        user.email_verified = True
......
453 459
            return HttpResponseBadRequest(e)
454 460
    else:
455 461
        # switch the existing account to shibboleth one
456
        local_user.provider = 'shibboleth'
457
        local_user.set_unusable_password()
458
        local_user.third_party_identifier = user.third_party_identifier
459
        try:
460
            local_user.save()
461
        except ValidationError, e:
462
            return HttpResponseBadRequest(e)
463
        user.delete()
464
        user = local_user
465
    
462
        if user.provider == 'shibboleth':
463
            local_user.provider = 'shibboleth'
464
            local_user.set_unusable_password()
465
            local_user.third_party_identifier = user.third_party_identifier
466
            try:
467
                local_user.save()
468
            except ValidationError, e:
469
                return HttpResponseBadRequest(e)
470
            user.delete()
471
            user = local_user
472
        
466 473
    try:
467 474
        send_greeting(user, email_template_name)
468 475
        response = prepare_response(request, user, next, renew=True)

Also available in: Unified diff