diff options
Diffstat (limited to 'askbot/utils/forms.py')
-rw-r--r-- | askbot/utils/forms.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/askbot/utils/forms.py b/askbot/utils/forms.py index 319e9b9d..e8f9e622 100644 --- a/askbot/utils/forms.py +++ b/askbot/utils/forms.py @@ -59,6 +59,7 @@ class UserNameField(StrippedNonEmptyCharField): must_exist=False, skip_clean=False, label=_('Choose a screen name'), + widget_attrs=None, **kw ): self.must_exist = must_exist @@ -74,12 +75,19 @@ class UserNameField(StrippedNonEmptyCharField): 'multiple-taken': _('sorry, we have a serious error - user name is taken by several users'), 'invalid': _('user name can only consist of letters, empty space and underscore'), 'meaningless': _('please use at least some alphabetic characters in the user name'), + 'noemail': _('symbol "@" is not allowed') } if 'error_messages' in kw: error_messages.update(kw['error_messages']) del kw['error_messages'] + + if widget_attrs: + widget_attrs.update(login_form_widget_attrs) + else: + widget_attrs = login_form_widget_attrs + super(UserNameField,self).__init__(max_length=30, - widget=forms.TextInput(attrs=login_form_widget_attrs), + widget=forms.TextInput(attrs=widget_attrs), label=label, error_messages=error_messages, **kw @@ -104,7 +112,16 @@ class UserNameField(StrippedNonEmptyCharField): except forms.ValidationError: raise forms.ValidationError(self.error_messages['required']) - username_regex = re.compile(const.USERNAME_REGEX_STRING, re.UNICODE) + username_re_string = const.USERNAME_REGEX_STRING + #attention: here we check @ symbol in two places: input and the regex + if askbot_settings.ALLOW_EMAIL_ADDRESS_IN_USERNAME is False: + if '@' in username: + raise forms.ValidationError(self.error_messages['noemail']) + + username_re_string = username_re_string.replace('@', '') + + username_regex = re.compile(username_re_string, re.UNICODE) + if self.required and not username_regex.search(username): raise forms.ValidationError(self.error_messages['invalid']) if username in self.RESERVED_NAMES: |