cutelyst
4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatorconfirmed.cpp
1
/*
2
* SPDX-FileCopyrightText: (C) 2017-2023 Matthias Fehring <mf@huessenbergnetz.de>
3
* SPDX-License-Identifier: BSD-3-Clause
4
*/
5
6
#include "validatorconfirmed_p.h"
7
8
using namespace
Cutelyst
;
9
10
ValidatorConfirmed::ValidatorConfirmed
(
const
QString
&field,
const
ValidatorMessages
&messages)
11
:
ValidatorRule
(*new ValidatorConfirmedPrivate(field, messages))
12
{
13
}
14
15
ValidatorConfirmed::~ValidatorConfirmed
() =
default
;
16
17
ValidatorReturnType
ValidatorConfirmed::validate
(
Context
*c,
const
ParamsMultiMap
¶ms)
const
18
{
19
ValidatorReturnType
result;
20
21
const
QString
v =
value
(params);
22
23
if
(!v.
isEmpty
()) {
24
const
QString
ofn =
field
() +
QLatin1String
(
"_confirmation"
);
25
QString
ofv = params.
value
(ofn);
26
27
if
(
trimBefore
()) {
28
ofv = ofv.
trimmed
();
29
}
30
31
if
(Q_UNLIKELY(v != ofv)) {
32
result.
errorMessage
=
validationError
(c);
33
qCDebug(C_VALIDATOR).noquote().nospace()
34
<<
debugString
(c) <<
" The value in \""
<< ofn <<
"\" does not fit: \""
<< v
35
<<
"\" != \""
<< ofv <<
"\""
;
36
}
else
{
37
result.
value
.
setValue
(v);
38
}
39
}
40
41
return
result;
42
}
43
44
QString
ValidatorConfirmed::genericValidationError
(
Context
*c,
const
QVariant
&errorData)
const
45
{
46
QString
error;
47
Q_UNUSED(errorData)
48
const
QString
_label =
label
(c);
49
if
(_label.
isEmpty
()) {
50
//% "Confirmation failed."
51
return
c->
qtTrId
(
"cutelyst-valconfirmed-genvalerr"
);
52
}
else
{
53
//: %1 will be replaced by the field label
54
//% "The value in the “%1“ field has not been confirmed."
55
return
c->
qtTrId
(
"cutelyst-valconfirmed-genvalerr-label"
).
arg
(_label);
56
}
57
return
error;
58
}
Cutelyst::Context
The Cutelyst Context.
Definition
context.h:42
Cutelyst::Context::qtTrId
QString qtTrId(const char *id, int n=-1) const
Definition
context.h:656
Cutelyst::ValidatorConfirmed::genericValidationError
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Definition
validatorconfirmed.cpp:44
Cutelyst::ValidatorConfirmed::~ValidatorConfirmed
~ValidatorConfirmed() override
Cutelyst::ValidatorConfirmed::ValidatorConfirmed
ValidatorConfirmed(const QString &field, const ValidatorMessages &messages=ValidatorMessages())
Definition
validatorconfirmed.cpp:10
Cutelyst::ValidatorConfirmed::validate
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
Definition
validatorconfirmed.cpp:17
Cutelyst::ValidatorRule
Base class for all validator rules.
Definition
validatorrule.h:304
Cutelyst::ValidatorRule::field
QString field() const noexcept
Definition
validatorrule.cpp:28
Cutelyst::ValidatorRule::validationError
QString validationError(Context *c, const QVariant &errorData={}) const
Definition
validatorrule.cpp:61
Cutelyst::ValidatorRule::label
QString label(Context *c) const
Definition
validatorrule.cpp:49
Cutelyst::ValidatorRule::trimBefore
bool trimBefore() const noexcept
Definition
validatorrule.cpp:165
Cutelyst::ValidatorRule::value
QString value(const ParamsMultiMap ¶ms) const
Definition
validatorrule.cpp:34
Cutelyst::ValidatorRule::debugString
QString debugString(Context *c) const
Definition
validatorrule.cpp:157
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition
group-core-actions.dox:1
QLatin1String
QMultiMap
QMultiMap::value
T value(const Key &key, const T &defaultValue) const const
QString
QString::arg
QString arg(Args &&... args) const const
QString::isEmpty
bool isEmpty() const const
QString::trimmed
QString trimmed() const const
QVariant
QVariant::setValue
void setValue(QVariant &&value)
Cutelyst::ValidatorMessages
Stores custom error messages and the input field label.
Definition
validatorrule.h:142
Cutelyst::ValidatorReturnType
Contains the result of a single input parameter validation.
Definition
validatorrule.h:49
Cutelyst::ValidatorReturnType::value
QVariant value
Definition
validatorrule.h:54
Cutelyst::ValidatorReturnType::errorMessage
QString errorMessage
Definition
validatorrule.h:50
Cutelyst
Plugins
Utils
Validator
validatorconfirmed.cpp
Generated by
1.9.8