19 #include "validator_p.h"
20 #include <Cutelyst/context.h>
21 #include <Cutelyst/request.h>
22 #include <Cutelyst/application.h>
23 #include <QLoggingCategory>
25 using namespace Cutelyst;
27 Q_LOGGING_CATEGORY(C_VALIDATOR,
"cutelyst.utils.validator", QtWarningMsg)
30 d_ptr(new ValidatorPrivate(translationContext))
34 #ifdef Q_COMPILER_INITIALIZER_LISTS
36 d_ptr(new ValidatorPrivate(validators, translationContext))
49 if (!d->validators.empty()) {
50 qDeleteAll(d->validators.begin(), d->validators.end());
51 d->validators.clear();
83 if (d->validators.empty()) {
84 qCWarning(C_VALIDATOR) <<
"Validation started with empty validator list.";
89 qCWarning(C_VALIDATOR) <<
"Validation started with empty parameters.";
93 const bool noTrimming = flags.testFlag(
NoTrimming);
98 v->setTrimBefore(
false);
111 if (stopOnFirstError) {
124 if (!i.
key().contains(QStringLiteral(
"password"), Qt::CaseInsensitive)) {
138 v->setTranslationContext(d->translationContext);
139 d->validators.push_back(v);
QString field() const
Returns the name of the field to validate.
QMap< Key, T > & unite(const QMap< Key, T > &other)
const_iterator constBegin() const
Validator(QLatin1String translationContext=QLatin1String())
Constructs a new Validator.
void setStash(const QString &key, const QVariant &value)
void loadTranslations(const QString &filename, const QString &directory=QString(), const QString &prefix=QString(), const QString &suffix=QString())
ParamsMultiMap bodyParameters() const
ParamsMultiMap queryParameters() const
QStringList errorStrings() const
Returns a list of all error messages.
const_iterator constEnd() const
Base class for all validator rules.
Validation processor for input data.
void addError(const QString &field, const QString &message)
Adds new error information to the internal QHash.
QVariant fromValue(const T &value)
void addValue(const QString &field, const QVariant &value)
Adds a new value extracted from the specified input field.
QHash< QString, QStringList > errors() const
Returns a dictionary containing fields with errors.
virtual ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const =0
Starts the validation and returns the result.
void clear()
Clears all internal data.
void addValidator(ValidatorRule *v)
Adds a new validator to the list of validators.
static void loadTranslations(Application *app)
Loads the translations for the plugin.
The Cutelyst Application.
Contains the result of a single input parameter validation.
Provides information about performed validations.
void addExtra(const QString &field, const QVariant &extra)
Adds new extra data that came up when validating the input field.
ValidatorResult validate(Context *c, ValidatorFlags flags=NoSpecialBehavior) const
Starts the validation process on Context c and returns a ValidatorResult.
~Validator()
Desconstructs the Validator and all added ValidatorRule objects.