cutelyst  5.1.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
authenticationuser.cpp
1 /*
2  * SPDX-FileCopyrightText: (C) 2013-2022 Daniel Nicoletti <dantti12@gmail.com>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #include "authenticationuser.h"
6 
7 #include "authenticationrealm.h"
8 
9 #include <QDataStream>
10 #include <QDebug>
11 
12 using namespace Cutelyst;
13 using namespace Qt::StringLiterals;
14 
16 {
17 }
18 
20 {
21  setId(id);
22 }
23 
25 {
26 }
27 
29 {
30  return m_data.value(u"id"_s);
31 }
32 
34 {
35  m_data.insert(u"id"_s, id);
36 }
37 
39 {
40  return m_data.isEmpty();
41 }
42 
44 {
45  return m_data.value(u"authRealm"_s).toString();
46 }
47 
49 {
50  m_data.insert(u"authRealm"_s, authRealm);
51 }
52 
54  AuthenticationRealm *realm,
55  const QString &password,
56  const QString &passwordField)
57 {
58  if (!realm) {
59  return false;
60  }
61  return realm->checkPassword(c, *this, password, passwordField);
62 }
63 
64 QDataStream &operator<<(QDataStream &out, const AuthenticationUser &user)
65 {
66  out << user.data();
67  return out;
68 }
69 
70 QDataStream &operator>>(QDataStream &in, AuthenticationUser &user)
71 {
72  QVariantMap map;
73  in >> map;
74  user.setData(map);
75  return in;
76 }
77 
78 QDebug operator<<(QDebug dbg, const AuthenticationUser &user)
79 {
80  const QVariantMap map = user.data();
81  const bool oldSetting = dbg.autoInsertSpaces();
82  dbg.nospace() << "AuthenticationUser(";
83  for (const auto &[key, value] : map.asKeyValueRange()) {
84  dbg << '(' << key << ", " << value << ')';
85  }
86  dbg << ')';
87  dbg.setAutoInsertSpaces(oldSetting);
88  return dbg.maybeSpace();
89 }
90 
91 #include "moc_authenticationuser.cpp"
void setId(const QVariant &id)
void setAutoInsertSpaces(bool b)
bool checkPassword(Context *c, AuthenticationRealm *realm, const QString &password, const QString &passwordField=QStringLiteral("password"))
QDebug & nospace()
T value() const const
Combines user store and credential validation into a named realm.
void setData(const QVariantMap &data)
The Cutelyst Context.
Definition: context.h:42
The Cutelyst namespace holds all public Cutelyst API.
QDebug & maybeSpace()
Container for user data retrieved from an AuthenticationStore.
bool autoInsertSpaces() const const
void setAuthRealm(const QString &authRealm)
bool checkPassword(Context *c, const AuthenticationUser &user, const QString &password, const QString &passwordField=QStringLiteral("password"))