cutelyst 5.0.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::ValidatorAccepted Class Reference

Checks if a field is available and has a specific value. More...

#include <Cutelyst/Plugins/Utils/validatoraccepted.h>

Inheritance diagram for Cutelyst::ValidatorAccepted:

Public Member Functions

 ValidatorAccepted (const QString &field, const ValidatorMessages &messages={})
 
 ~ValidatorAccepted () override
 
- Public Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr)
 
virtual ~ValidatorRule ()
 Deconstructs the ValidatorRule.
 

Static Public Member Functions

static bool validate (const QString &value)
 Returns true if the value is equal to yes, on, 1, or true.
 

Protected Member Functions

QString genericValidationError (Context *c, const QVariant &errorData=QVariant()) const override
 
ValidatorReturnType validate (Context *c, const ParamsMultiMap &params) const override
 
void validateCb (Context *c, const ParamsMultiMap &params, ValidatorRtFn cb) const override
 
- Protected Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (ValidatorRulePrivate &dd)
 
QString debugString (const Context *c) const
 
void defaultValue (Context *c, ValidatorReturnType *result) const
 
void defaultValue (Context *c, ValidatorRtFn cb) const
 
QString field () const noexcept
 
virtual QString genericParsingError (Context *c, const QVariant &errorData={}) const
 
virtual QString genericValidationDataError (Context *c, const QVariant &errorData={}) const
 
QString label (const Context *c) const
 
QString parsingError (Context *c, const QVariant &errorData={}) const
 
bool trimBefore () const noexcept
 
QString validationDataError (Context *c, const QVariant &errorData={}) const
 
QString validationError (Context *c, const QVariant &errorData={}) const
 
QString value (const ParamsMultiMap &params) const
 

Additional Inherited Members

Detailed Description

The field under validation must be yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance. This check will also fail if the input data for the specified field is empty or if the field is not part of the input data.

Note
Unless validation is started with NoTrimming, whitespaces will be removed from the beginning and the end of the input value before validation.
Return type
On success, ValidatorReturnType::value will be set to true.
See also
Validator for general usage of validators.

Definition at line 32 of file validatoraccepted.h.

Constructor & Destructor Documentation

◆ ValidatorAccepted()

ValidatorAccepted::ValidatorAccepted ( const QString field,
const ValidatorMessages messages = {} 
)
explicit

Constructs a new ValidatorAccepted object for the given field using optional custom error messages.

Definition at line 15 of file validatoraccepted.cpp.

◆ ~ValidatorAccepted()

ValidatorAccepted::~ValidatorAccepted ( )
overridedefault

Destroys the ValidatorAccepted object.

Member Function Documentation

◆ genericValidationError()

QString ValidatorAccepted::genericValidationError ( Cutelyst::Context c,
const QVariant errorData = QVariant() 
) const
overrideprotectedvirtual

Returns a generic error message.

Reimplemented from Cutelyst::ValidatorRule.

Definition at line 54 of file validatoraccepted.cpp.

References QString::arg(), QString::isEmpty(), Cutelyst::ValidatorRule::label(), and Cutelyst::Context::qtTrId().

◆ validate()

ValidatorReturnType ValidatorAccepted::validate ( Cutelyst::Context c,
const ParamsMultiMap params 
) const
overrideprotectedvirtual

Performs the validation on the input params and returns the result.

If validation succeeds, ValidatorReturnType::value will contain true, otherwise false.

Implements Cutelyst::ValidatorRule.

Definition at line 23 of file validatoraccepted.cpp.

References Cutelyst::ValidatorRule::debugString(), Cutelyst::ValidatorReturnType::errorMessage, QVariant::setValue(), validate(), Cutelyst::ValidatorRule::validationError(), Cutelyst::ValidatorReturnType::value, and Cutelyst::ValidatorRule::value().

◆ validateCb()

void ValidatorAccepted::validateCb ( Context c,
const ParamsMultiMap params,
ValidatorRtFn  cb 
) const
overrideprotectedvirtual

Performs the validation on the input params and calls the cb with the ValidatorReturnType as argument.

If validation succeeds, ValidatorReturnType::value will contain true, otherwise false.

Since
Cutelyst 5.0.0

Reimplemented from Cutelyst::ValidatorRule.

Definition at line 39 of file validatoraccepted.cpp.

References Cutelyst::ValidatorRule::debugString(), validate(), Cutelyst::ValidatorRule::validationError(), and Cutelyst::ValidatorRule::value().