Revision ca828a10

b/snf-astakos-app/astakos/im/forms.py
195 195
        if get_latest_terms():
196 196
            self.fields.keyOrder.append('has_signed_terms')
197 197
        #set readonly form fields
198
        ro = ["third_party_identifier", "first_name", "last_name"]
198
        ro = ["third_party_identifier"]
199 199
        for f in ro:
200 200
            self.fields[f].widget.attrs['readonly'] = True
201 201
        
......
255 255
        return user
256 256

  
257 257
class ShibbolethUserCreationForm(ThirdPartyUserCreationForm):
258
    additional_email = forms.CharField(widget=forms.HiddenInput(), label='', required = False)
259
    
260
    def __init__(self, *args, **kwargs):
261
        super(ShibbolethUserCreationForm, self).__init__(*args, **kwargs)
262
        self.fields.keyOrder.append('additional_email')
263
        # copy email value to additional_mail in case user will change it
264
        name = 'email'
265
        field = self.fields[name]
266
        self.initial['additional_email'] = self.initial.get(name, field.initial)
267
    
258 268
    def clean_email(self):
259 269
        email = self.cleaned_data['email']
260 270
        for user in AstakosUser.objects.filter(email = email):
b/snf-astakos-app/astakos/im/migrations/0012_auto__add_additionalmail.py
1
# encoding: utf-8
2
import datetime
3
from south.db import db
4
from south.v2 import SchemaMigration
5
from django.db import models
6

  
7
class Migration(SchemaMigration):
8

  
9
    def forwards(self, orm):
10
        
11
        # Adding model 'AdditionalMail'
12
        db.create_table('im_additionalmail', (
13
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
14
            ('owner', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['im.AstakosUser'])),
15
            ('email', self.gf('django.db.models.fields.EmailField')(unique=True, max_length=75)),
16
        ))
17
        db.send_create_signal('im', ['AdditionalMail'])
18

  
19

  
20
    def backwards(self, orm):
21
        
22
        # Deleting model 'AdditionalMail'
23
        db.delete_table('im_additionalmail')
24

  
25

  
26
    models = {
27
        'auth.group': {
28
            'Meta': {'object_name': 'Group'},
29
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
30
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
31
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
32
        },
33
        'auth.permission': {
34
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
35
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
36
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
37
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
38
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
39
        },
40
        'auth.user': {
41
            'Meta': {'object_name': 'User'},
42
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
43
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
44
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
45
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
46
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
47
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
48
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
49
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
50
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
51
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
52
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
53
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
54
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
55
        },
56
        'contenttypes.contenttype': {
57
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
58
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
59
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
60
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
61
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
62
        },
63
        'im.additionalmail': {
64
            'Meta': {'object_name': 'AdditionalMail'},
65
            'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '75'}),
66
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
67
            'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['im.AstakosUser']"})
68
        },
69
        'im.approvalterms': {
70
            'Meta': {'object_name': 'ApprovalTerms'},
71
            'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 6, 1, 10, 5, 42, 665990)', 'db_index': 'True'}),
72
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
73
            'location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
74
        },
75
        'im.astakosuser': {
76
            'Meta': {'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
77
            'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
78
            'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
79
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
80
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
81
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
82
            'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
83
            'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
84
            'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
85
            'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
86
            'invitations': ('django.db.models.fields.IntegerField', [], {'default': '100'}),
87
            'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
88
            'level': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
89
            'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
90
            'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
91
            'updated': ('django.db.models.fields.DateTimeField', [], {}),
92
            'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
93
        },
94
        'im.emailchange': {
95
            'Meta': {'object_name': 'EmailChange'},
96
            'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}),
97
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
98
            'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
99
            'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 6, 1, 10, 5, 42, 667593)'}),
100
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchange_user'", 'unique': 'True', 'to': "orm['im.AstakosUser']"})
101
        },
102
        'im.invitation': {
103
            'Meta': {'object_name': 'Invitation'},
104
            'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
105
            'consumed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
106
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
107
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
108
            'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}),
109
            'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
110
            'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
111
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
112
        },
113
        'im.service': {
114
            'Meta': {'object_name': 'Service'},
115
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
116
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
117
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
118
            'icon': ('django.db.models.fields.FilePathField', [], {'max_length': '100', 'blank': 'True'}),
119
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
120
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
121
            'url': ('django.db.models.fields.FilePathField', [], {'max_length': '100'})
122
        }
123
    }
124

  
125
    complete_apps = ['im']
b/snf-astakos-app/astakos/im/models.py
364 364
        self.auth_token_expires = self.auth_token_created + \
365 365
                                  timedelta(hours=AUTH_TOKEN_DURATION)
366 366

  
367
class AdditionalMail(models.Model):
368
    """
369
    Model for registring invitations
370
    """
371
    owner = models.ForeignKey(AstakosUser)
372
    email = models.EmailField(unique=True)
373

  
367 374
def create_astakos_user(u):
368 375
    try:
369 376
        AstakosUser.objects.get(user_ptr=u.pk)
b/snf-astakos-app/astakos/im/target/shibboleth.py
35 35
from django.utils.translation import ugettext as _
36 36
from django.contrib import messages
37 37
from django.template import RequestContext
38
from django.forms.models import inlineformset_factory
38 39

  
39 40
from astakos.im.util import prepare_response, get_context, get_invitation
40 41
from astakos.im.views import requires_anonymous, render_response
41 42
from astakos.im.settings import DEFAULT_USER_LEVEL
42
from astakos.im.models import AstakosUser, Invitation
43
from astakos.im.models import AstakosUser, Invitation, AdditionalMail
43 44
from astakos.im.forms import LoginForm
44 45
from astakos.im.activation_backends import get_backend, SimpleBackend
45 46

  
......
52 53
    SHIB_DISPLAYNAME = "HTTP_SHIB_INETORGPERSON_DISPLAYNAME"
53 54
    SHIB_EP_AFFILIATION = "HTTP_SHIB_EP_AFFILIATION"
54 55
    SHIB_SESSION_ID = "HTTP_SHIB_SESSION_ID"
56
    SHIB_MAIL = "HTTP_SHIB_MAIL"
55 57

  
56 58
@requires_anonymous
57 59
def login(request,  backend=None, on_login_template='im/login.html', on_creation_template='im/third_party_registration.html', extra_context={}):
......
72 74
        return HttpResponseBadRequest("Missing user name in request")
73 75
    
74 76
    affiliation = tokens.get(Tokens.SHIB_EP_AFFILIATION, '')
77
    email = tokens.get(Tokens.SHIB_MAIL, None)
75 78
    
76 79
    try:
77 80
        user = AstakosUser.objects.get(provider='shibboleth', third_party_identifier=eppn)
......
88 91
                                   context_instance=RequestContext(request))
89 92
    except AstakosUser.DoesNotExist, e:
90 93
        user = AstakosUser(third_party_identifier=eppn, realname=realname,
91
                           affiliation=affiliation, provider='shibboleth')
94
                           affiliation=affiliation, provider='shibboleth',
95
                           email=email)
92 96
        try:
93 97
            if not backend:
94 98
                backend = get_backend(request)
......
96 100
        except Exception, e:
97 101
            form = SimpleBackend(request).get_signup_form(provider='shibboleth', instance=user)
98 102
            messages.add_message(request, messages.ERROR, e)
99
        form.data.update({'third_party_identifier':eppn, 'realname':realname,
100
                          'affiliation':affiliation})
101 103
        return render_response(on_creation_template,
102 104
                               signup_form = form,
103 105
                               provider = 'shibboleth',
b/snf-astakos-app/astakos/im/views.py
326 326
                status = messages.SUCCESS
327 327
                message = result.message
328 328
                user.save()
329
                if 'additional_email' in form.cleaned_data:
330
                    additional_email = form.cleaned_data['additional_email']
331
                    if additional_email != user.email:
332
                        user.additionalmail_set.create(email=additional_email)
329 333
                if user and user.is_active:
330 334
                    next = request.POST.get('next', '')
331 335
                    return prepare_response(request, user, next=next)

Also available in: Unified diff