Cutelyst  2.13.0
minimal.cpp
1 /*
2  * Copyright (C) 2013-2017 Daniel Nicoletti <dantti12@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #include "minimal.h"
19 
20 #include <QVariant>
21 
22 using namespace Cutelyst;
23 
24 StoreMinimal::StoreMinimal(const QString &idField, QObject *parent) : AuthenticationStore(parent)
25  , m_idField(idField)
26 {
27 
28 }
29 
30 StoreMinimal::~StoreMinimal()
31 {
32 
33 }
34 
36 {
37  m_users << user;
38 }
39 
40 
42 {
43  Q_UNUSED(c)
45  const QString id = userInfo[m_idField];
46 
47  const auto users = m_users;
48  for (const AuthenticationUser &user : users) {
49  if (user.id() == id) {
50  ret = user;
51  break;
52  }
53  }
54 
55  return ret;
56 }
57 
59 {
60  return user.id();
61 }
62 
63 AuthenticationUser StoreMinimal::fromSession(Context *c, const QVariant &frozenUser)
64 {
65  return findUser(c, {
66  {m_idField, frozenUser.toString()}
67  });
68 }
69 
70 #include "moc_minimal.cpp"
Cutelyst::ParamsMultiMap
QMap< QString, QString > ParamsMultiMap
Definition: paramsmultimap.h:36
Cutelyst::AuthenticationUser::id
QVariant id() const
Definition: authenticationuser.cpp:39
Cutelyst::Context
The Cutelyst Context.
Definition: context.h:50
Cutelyst::AuthenticationUser
Definition: authenticationuser.h:31
Cutelyst::StoreMinimal::StoreMinimal
StoreMinimal(const QString &idField, QObject *parent=nullptr)
Definition: minimal.cpp:24
Cutelyst::StoreMinimal::findUser
virtual AuthenticationUser findUser(Context *c, const ParamsMultiMap &userInfo) final
Definition: minimal.cpp:41
Cutelyst::StoreMinimal::fromSession
virtual AuthenticationUser fromSession(Context *c, const QVariant &frozenUser) final
Definition: minimal.cpp:63
Cutelyst::AuthenticationStore
Definition: authenticationstore.h:26
Cutelyst
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Cutelyst::StoreMinimal::forSession
virtual QVariant forSession(Context *c, const AuthenticationUser &user) final
Definition: minimal.cpp:58
Cutelyst::StoreMinimal::addUser
void addUser(const AuthenticationUser &user)
Definition: minimal.cpp:35