我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用wtforms.ValidationError()。
def protect(self): if request.method not in current_app.config['WTF_CSRF_METHODS']: return try: validate_csrf(self._get_csrf_token()) except ValidationError as e: logger.info(e.args[0]) self._error_response(e.args[0]) if request.is_secure and current_app.config['WTF_CSRF_SSL_STRICT']: if not request.referrer: self._error_response('The referrer header is missing.') good_referrer = 'https://{0}/'.format(request.host) if not same_origin(request.referrer, good_referrer): self._error_response('The referrer does not match the host.') g.csrf_valid = True # mark this request as CSRF valid
def __call__(self, form, field): if current_app.testing: return True if request.json: response = request.json.get('g-recaptcha-response', '') else: response = request.form.get('g-recaptcha-response', '') remote_ip = request.remote_addr if not response: raise ValidationError(field.gettext(self.message)) if not self._validate_recaptcha(response, remote_ip): field.recaptcha_error = 'incorrect-captcha-sol' raise ValidationError(field.gettext(self.message))
def __call__(self, form, field): if current_app.testing: return True if request.json: challenge = request.json.get('recaptcha_challenge_field', '') response = request.json.get('recaptcha_response_field', '') else: challenge = request.form.get('recaptcha_challenge_field', '') response = request.form.get('recaptcha_response_field', '') remote_ip = request.remote_addr if not challenge or not response: raise ValidationError(field.gettext(self.message)) if not self._validate_recaptcha(challenge, response, remote_ip): field.recaptcha_error = 'incorrect-captcha-sol' raise ValidationError(field.gettext(self.message))
def __call__(self, form, field): if current_app.testing or not flaskbb_config["RECAPTCHA_ENABLED"]: return True if request.json: response = request.json.get('g-recaptcha-response', '') else: response = request.form.get('g-recaptcha-response', '') remote_ip = request.remote_addr if not response: raise ValidationError(field.gettext(self.message)) if not self._validate_recaptcha(response, remote_ip): field.recaptcha_error = 'incorrect-captcha-sol' raise ValidationError(field.gettext(self.message))
def validate_email(self, filed): if User.query.filter(db.func.lower(User.email) == db.func.lower(filed.data)).first(): raise ValidationError(u'? Email ??????')
def validate_old_password(self, filed): from flask.ext.login import current_user if not current_user.verify_password(filed.data): raise ValidationError(u'?????')
def validate_isbn(self, filed): if Book.query.filter_by(isbn=filed.data).count(): raise ValidationError(u'???????ISBN,????,?????????????.')
def validate_email(self, field): user = User.where('email', field.data).first() if user: raise form.ValidationError(message='User with this email already exist')
def validate_password(self, field): if self.password_confirm.data != field.data: raise form.ValidationError(message='Password does not match the confirm password')
def validate_email(self, field): if User.query.filter_by(email=field.data).first(): raise ValidationError('Email already registered.')
def validate_username(self, field): if User.query.filter_by(username=field.data).first(): raise ValidationError('Username already in use.')
def validate_email(self, field): if User.query.filter_by(email=field.data).first() is None: raise ValidationError('Unknown email address.')
def validate_email(self, field): if field.data != self.user.email and \ User.query.filter_by(email=field.data).first(): raise ValidationError('Email already registered.')
def validate_username(self, field): if User.query.filter_by(username=field.data).first(): raise ValidationError('Username already registered.')
def validate_csrf_token(self, form, field): if g.get('csrf_valid', False): # already validated by CSRFProtect return try: validate_csrf( field.data, self.meta.csrf_secret, self.meta.csrf_time_limit, self.meta.csrf_field_name ) except ValidationError as e: logger.info(e.args[0]) raise
def _validate_recaptcha(self, response, remote_addr): """Performs the actual validation.""" try: private_key = current_app.config['RECAPTCHA_PRIVATE_KEY'] except KeyError: raise RuntimeError("No RECAPTCHA_PRIVATE_KEY config set") data = url_encode({ 'secret': private_key, 'remoteip': remote_addr, 'response': response }) http_response = http.urlopen(RECAPTCHA_VERIFY_SERVER, to_bytes(data)) if http_response.code != 200: return False json_resp = json.loads(to_unicode(http_response.read())) if json_resp["success"]: return True for error in json_resp.get("error-codes", []): if error in RECAPTCHA_ERROR_CODES: raise ValidationError(RECAPTCHA_ERROR_CODES[error]) return False
def validate_username(self, field): if User.query.filter_by(username=field.data).first(): raise ValidationError('username already registered.')
def validate_black_id(form, field): """Check that IDs are different.""" if form.black_id.data == form.white_id.data: raise ValidationError('Players cannot play themselves')
def validate_game_id(form, field): """Check that game exists.""" game_id = form.game_id.data if Game.get_by_id(game_id) is None: raise ValidationError('Game {} does not exist'.format(game_id))
def validate_email(self, field): if User.query.filter_by(email=field.data).first(): raise ValidationError('???????')
def validate_nickname(self, field): if User.query.filter_by(nickname=field.data).first(): raise ValidationError('???????') # ??????