Revision ef20ea07 snf-astakos-app/astakos/im/forms.py

b/snf-astakos-app/astakos/im/forms.py
48 48
from django.utils.encoding import smart_str
49 49

  
50 50
from astakos.im.models import AstakosUser, Invitation, get_latest_terms, EmailChange
51
from astakos.im.settings import INVITATIONS_PER_LEVEL, DEFAULT_FROM_EMAIL, \
52
    BASEURL, SITENAME, RECAPTCHA_PRIVATE_KEY, DEFAULT_CONTACT_EMAIL, \
53
    RECAPTCHA_ENABLED, LOGGING_LEVEL, PASSWORD_RESET_EMAIL_SUBJECT, \
54
    NEWPASSWD_INVALIDATE_TOKEN
51
from astakos.im.settings import (INVITATIONS_PER_LEVEL, DEFAULT_FROM_EMAIL,
52
    BASEURL, SITENAME, RECAPTCHA_PRIVATE_KEY, DEFAULT_CONTACT_EMAIL,
53
    RECAPTCHA_ENABLED, LOGGING_LEVEL, PASSWORD_RESET_EMAIL_SUBJECT,
54
    NEWPASSWD_INVALIDATE_TOKEN, THIRDPARTY_ACC_ADDITIONAL_FIELDS
55
)
55 56
from astakos.im.widgets import DummyWidget, RecaptchaWidget
56 57
from astakos.im.functions import send_change_email
57 58

  
......
182 183
        return user
183 184

  
184 185
class ThirdPartyUserCreationForm(forms.ModelForm):
186
    third_party_identifier = forms.CharField(
187
        widget=forms.HiddenInput(),
188
        label=''
189
    )
185 190
    class Meta:
186 191
        model = AstakosUser
187 192
        fields = ("email", "first_name", "last_name", "third_party_identifier", "has_signed_terms")
......
193 198
        self.request = kwargs.get('request', None)
194 199
        if self.request:
195 200
            kwargs.pop('request')
201
                
202
        latest_terms = get_latest_terms()
203
        if latest_terms:
204
            self._meta.fields.append('has_signed_terms')
205
                
196 206
        super(ThirdPartyUserCreationForm, self).__init__(*args, **kwargs)
197
        self.fields.keyOrder = ['email', 'first_name', 'last_name', 'third_party_identifier']
198
        if get_latest_terms():
207
        
208
        if latest_terms:
199 209
            self.fields.keyOrder.append('has_signed_terms')
200
        #set readonly form fields
201
        ro = ["third_party_identifier"]
202
        for f in ro:
203
            self.fields[f].widget.attrs['readonly'] = True
204

  
210
        
205 211
        if 'has_signed_terms' in self.fields:
206 212
            # Overriding field label since we need to apply a link
207 213
            # to the terms within the label
......
262 268

  
263 269
    def __init__(self, *args, **kwargs):
264 270
        super(ShibbolethUserCreationForm, self).__init__(*args, **kwargs)
265
        self.fields.keyOrder.append('additional_email')
266 271
        # copy email value to additional_mail in case user will change it
267 272
        name = 'email'
268 273
        field = self.fields[name]
269 274
        self.initial['additional_email'] = self.initial.get(name, field.initial)
270

  
275
        self.initial['email'] = None
276
    
271 277
    def clean_email(self):
272 278
        email = self.cleaned_data['email']
273 279
        for user in AstakosUser.objects.filter(email = email):
274 280
            if user.provider == 'shibboleth':
275
                raise forms.ValidationError(_("This email is already associated with another shibboleth account."))
276
            elif not user.is_active:
277
                raise forms.ValidationError(_("This email is already associated with an inactive account. \
278
                                              You need to wait to be activated before being able to switch to a shibboleth account."))
281
                raise forms.ValidationError(_(
282
                        "This email is already associated with another shibboleth \
283
                        account."
284
                    )
285
                )
286
            else:
287
                raise forms.ValidationError(_("This email is already used"))
279 288
        super(ShibbolethUserCreationForm, self).clean_email()
280 289
        return email
281 290

  
......
321 330
        check = captcha.submit(rcf, rrf, RECAPTCHA_PRIVATE_KEY, self.ip)
322 331
        if not check.is_valid:
323 332
            raise forms.ValidationError(_('You have not entered the correct words'))
324

  
333
    
325 334
    def clean(self):
326 335
        super(LoginForm, self).clean()
327 336
        if self.user_cache and self.user_cache.provider not in ('local', ''):

Also available in: Unified diff