def validate_username(self, value): user = User.query.filter_by(username=value).first() if user is None: raise forms.ValidationError(_(u'No such user.')) if self.request is not None and \ self.request.user == user: raise forms.ValidationError(_(u'You cannot ban yourself.')) self.user = user
def context_validate(self, data): has_username = bool(data['username']) has_email = bool(data['email']) if not has_username and not has_email: raise forms.ValidationError( _(u'Either username or e-mail address ' u' is required.')) if has_username and has_email: raise forms.ValidationError( _(u'You have to provide either a username ' u'or an e-mail address, not both.'))
def is_valid_username(form, value): """Checks if the value is a valid username.""" if len(value) > 40: raise forms.ValidationError(_(u'The username is too long.')) if '/' in value: raise forms.ValidationError( _(u'The username may not contain ' u'slashes.')) if value[:1] == '.' or value[-1:] == '.': raise forms.ValidationError( _(u'The username may not begin or ' u'end with a dot.')) if ' ' in value: raise forms.ValidationError( _(u'The username may not contain ' u'spaces.'))
def validate_email(self, email): if not email: return user = User.query.filter_by(email=email).first() if user is None: raise forms.ValidationError( _(u'No user with that e-mail address found.')) self._check_active(user) self.user = user
def validate_username(self, username): if not username: return user = User.query.filter_by(username=username).first() if user is None: raise forms.ValidationError( _(u'No user named “%s” found.') % username) self._check_active(user) self.user = user
def validate_openid_logins(self, value): ids_to_check = set(value) - set(self.user.openid_logins) in_use = check_used_openids(ids_to_check, self.user) if in_use: count = len(in_use) message = ngettext( u'The following %(count)d URL is already ' u'associated to a different user: %(urls)s', u'The following %(count)d URLs are already ' u'associated to different users: %(urls)s', count) % dict( count=count, urls=u', '.join(sorted(in_use))) raise forms.ValidationError(message)
def context_validate(self, data): password = data.get('password') password_repeat = data.get('password_repeat') if password != password_repeat: raise forms.ValidationError(_(u'The two passwords do not match.'))
def validate_username(self, value): user = User.query.filter_by(username=value).first() if user is not None: raise forms.ValidationError(_('This username is already in use.'))
def is_http_url(form, value): """Checks if the value is a HTTP URL.""" scheme, netloc = urlparse.urlparse(value)[:2] if scheme not in ('http', 'https') or not netloc: raise forms.ValidationError(_(u'A valid HTTP URL is required.'))
def validate_is_admin(self, value): if not value and self.request and self.request.user == self.user: raise forms.ValidationError(u'You cannot remove your own ' u'admin rights.')
def validate_username(self, value): user = User.query.filter_by(username=value).first() if user is None: raise forms.ValidationError(_(u'No such user.')) self.user = user
def is_valid_email(form, value): """Due to stupid rules in emails, we just check if there is an at-sign in the email and that it's not too long. """ if '@' not in value or len(value) > 200: raise forms.ValidationError(_('Invalid email address'))
def _check_active(self, user): if not user.is_active: raise forms.ValidationError(_(u'The user was not yet activated.'))