class NewEmailAddressForm(forms.Form): email = forms.EmailField( __("Email address"), validators=[forms.validators.DataRequired(), forms.ValidEmail()], widget_attrs={ 'autocorrect': 'none', 'autocapitalize': 'none' }) type = forms.RadioField(__("Type"), coerce=nullunicode, validators=[forms.validators.Optional()], choices=[(__(u"Home"), __(u"Home")), (__(u"Work"), __(u"Work")), (__(u"Other"), __(u"Other"))]) # TODO: Move to function and place before ValidEmail() def validate_email(self, field): field.data = field.data.lower() # Convert to lowercase existing = UserEmail.get(email=field.data) if existing is not None: if existing.user == current_auth.user: raise forms.ValidationError( _("You have already registered this email address")) else: raise forms.ValidationError( _("This email address has already been claimed")) existing = UserEmailClaim.get(email=field.data, user=current_auth.user) if existing is not None: raise forms.ValidationError( _("This email address is pending verification"))
class ProfileForm(forms.Form): fullname = forms.StringField(__("Full name"), validators=[forms.validators.DataRequired(), forms.validators.Length(max=80)]) email = forms.EmailField(__("Email address"), validators=[forms.validators.DataRequired(), forms.ValidEmail()], widget_attrs={'autocorrect': 'none', 'autocapitalize': 'none'}) username = forms.AnnotatedTextField(__("Username"), validators=[forms.validators.DataRequired()], filters=[forms.filters.none_if_empty()], prefix=u"https://hasgeek.com/…", widget_attrs={'autocorrect': 'none', 'autocapitalize': 'none'}) timezone = forms.SelectField(__("Timezone"), validators=[forms.validators.DataRequired()], choices=timezones) def validate_username(self, field): # # Usernames are now mandatory. This should be commented out: # if not field.data: # field.data = None # return field.data = field.data.lower() # Usernames can only be lowercase if not valid_username(field.data): raise forms.ValidationError(_("Usernames can only have alphabets, numbers and dashes (except at the ends)")) if field.data in current_app.config.get('RESERVED_USERNAMES', []): raise forms.ValidationError(_("This name is reserved")) if not self.edit_user.is_valid_username(field.data): raise forms.ValidationError(_("This username is taken")) # TODO: Move to function and place before ValidEmail() def validate_email(self, field): field.data = field.data.lower() # Convert to lowercase existing = UserEmail.get(email=field.data) if existing is not None and existing.user != self.edit_obj: raise forms.ValidationError(_("This email address has been claimed by another user"))
class ProfileForm(forms.Form): fullname = forms.StringField( __("Full name"), validators=[ forms.validators.DataRequired(), forms.validators.Length(max=User.__title_length__) ]) email = forms.EmailField( __("Email address"), validators=[forms.validators.DataRequired(), forms.ValidEmail()], widget_attrs={ 'autocorrect': 'none', 'autocapitalize': 'none' }) username = forms.AnnotatedTextField( __("Username"), validators=[ forms.validators.DataRequired(), forms.validators.Length(max=Name.__name_length__) ], filters=[forms.filters.none_if_empty()], prefix=u"https://hasgeek.com/", widget_attrs={ 'autocorrect': 'none', 'autocapitalize': 'none' }) timezone = forms.SelectField(__("Timezone"), validators=[forms.validators.DataRequired()], choices=timezones) def validate_username(self, field): if field.data.lower() in current_app.config['RESERVED_USERNAMES']: raise forms.ValidationError( _("This name is reserved" )) # To be deprecated in favour of one below reason = self.edit_obj.validate_name_candidate(field.data) if not reason: return # Username is available if reason == 'invalid': raise forms.ValidationError( _("Usernames can only have alphabets, numbers and dashes (except at the ends)" )) elif reason == 'reserved': raise forms.ValidationError(_("This username is reserved")) elif reason in ('user', 'org'): raise forms.ValidationError(_("This username has been taken")) else: raise forms.ValidationError(_("This username is not available")) # TODO: Move to function and place before ValidEmail() def validate_email(self, field): existing = UserEmail.get(email=field.data) if existing is not None and existing.user != self.edit_obj: raise forms.ValidationError( _("This email address has been claimed by another user"))
class EmailPrimaryForm(forms.Form): email = forms.EmailField( __("Email address"), validators=[forms.validators.DataRequired(), forms.ValidEmail()], widget_attrs={ 'autocorrect': 'none', 'autocapitalize': 'none' })