コード例 #1
0
ファイル: forms.py プロジェクト: tzoght/solace
 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
コード例 #2
0
ファイル: forms.py プロジェクト: tzoght/solace
 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.'))
コード例 #3
0
ファイル: forms.py プロジェクト: tzoght/solace
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.'))
コード例 #4
0
ファイル: forms.py プロジェクト: tzoght/solace
 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
コード例 #5
0
ファイル: forms.py プロジェクト: tzoght/solace
 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
コード例 #6
0
ファイル: forms.py プロジェクト: tzoght/solace
 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)
コード例 #7
0
ファイル: forms.py プロジェクト: tzoght/solace
 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.'))
コード例 #8
0
ファイル: forms.py プロジェクト: tzoght/solace
 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.'))
コード例 #9
0
ファイル: forms.py プロジェクト: tzoght/solace
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.'))
コード例 #10
0
ファイル: forms.py プロジェクト: tzoght/solace
 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.')
コード例 #11
0
ファイル: forms.py プロジェクト: tzoght/solace
 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
コード例 #12
0
ファイル: forms.py プロジェクト: tzoght/solace
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'))
コード例 #13
0
ファイル: forms.py プロジェクト: tzoght/solace
 def _check_active(self, user):
     if not user.is_active:
         raise forms.ValidationError(_(u'The user was not yet activated.'))