Revision 672d445a snf-astakos-app/astakos/im/forms.py
b/snf-astakos-app/astakos/im/forms.py | ||
---|---|---|
76 | 76 |
""" |
77 | 77 |
Changes the order of fields, and removes the username field. |
78 | 78 |
""" |
79 |
if 'ip' in kwargs: |
|
80 |
self.ip = kwargs['ip'] |
|
81 |
kwargs.pop('ip') |
|
79 |
request = kwargs.get('request', None) |
|
80 |
if request: |
|
81 |
kwargs.pop('request') |
|
82 |
self.ip = request.META.get('REMOTE_ADDR', |
|
83 |
request.META.get('HTTP_X_REAL_IP', None)) |
|
84 |
|
|
82 | 85 |
super(LocalUserCreationForm, self).__init__(*args, **kwargs) |
83 | 86 |
self.fields.keyOrder = ['email', 'first_name', 'last_name', |
84 | 87 |
'password1', 'password2'] |
... | ... | |
186 | 189 |
""" |
187 | 190 |
Changes the order of fields, and removes the username field. |
188 | 191 |
""" |
189 |
if 'ip' in kwargs: |
|
190 |
kwargs.pop('ip') |
|
191 | 192 |
super(ThirdPartyUserCreationForm, self).__init__(*args, **kwargs) |
192 | 193 |
self.fields.keyOrder = ['email', 'first_name', 'last_name', |
193 | 194 |
'provider', 'third_party_identifier'] |
... | ... | |
284 | 285 |
|
285 | 286 |
class LoginForm(AuthenticationForm): |
286 | 287 |
username = forms.EmailField(label=_("Email")) |
288 |
recaptcha_challenge_field = forms.CharField(widget=DummyWidget) |
|
289 |
recaptcha_response_field = forms.CharField(widget=RecaptchaWidget, label='') |
|
290 |
|
|
291 |
def __init__(self, *args, **kwargs): |
|
292 |
was_limited = kwargs.get('was_limited', False) |
|
293 |
request = kwargs.get('request', None) |
|
294 |
if request: |
|
295 |
self.ip = request.META.get('REMOTE_ADDR', |
|
296 |
request.META.get('HTTP_X_REAL_IP', None)) |
|
297 |
|
|
298 |
t = ('request', 'was_limited') |
|
299 |
for elem in t: |
|
300 |
if elem in kwargs.keys(): |
|
301 |
kwargs.pop(elem) |
|
302 |
super(LoginForm, self).__init__(*args, **kwargs) |
|
303 |
|
|
304 |
self.fields.keyOrder = ['username', 'password'] |
|
305 |
if was_limited and RECAPTCHA_ENABLED: |
|
306 |
self.fields.keyOrder.extend(['recaptcha_challenge_field', |
|
307 |
'recaptcha_response_field',]) |
|
308 |
|
|
309 |
def clean_recaptcha_response_field(self): |
|
310 |
if 'recaptcha_challenge_field' in self.cleaned_data: |
|
311 |
self.validate_captcha() |
|
312 |
return self.cleaned_data['recaptcha_response_field'] |
|
313 |
|
|
314 |
def clean_recaptcha_challenge_field(self): |
|
315 |
if 'recaptcha_response_field' in self.cleaned_data: |
|
316 |
self.validate_captcha() |
|
317 |
return self.cleaned_data['recaptcha_challenge_field'] |
|
318 |
|
|
319 |
def validate_captcha(self): |
|
320 |
rcf = self.cleaned_data['recaptcha_challenge_field'] |
|
321 |
rrf = self.cleaned_data['recaptcha_response_field'] |
|
322 |
check = captcha.submit(rcf, rrf, RECAPTCHA_PRIVATE_KEY, self.ip) |
|
323 |
if not check.is_valid: |
|
324 |
raise forms.ValidationError(_('You have not entered the correct words')) |
|
287 | 325 |
|
288 | 326 |
class ProfileForm(forms.ModelForm): |
289 | 327 |
""" |
Also available in: Unified diff