swift
Loading...
Searching...
No Matches
authenticateduser.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_NETWORK_AUTHENTICATEDUSER_H
7#define SWIFT_MISC_NETWORK_AUTHENTICATEDUSER_H
8
9#include <QJsonObject>
10#include <QMetaType>
11#include <QString>
12#include <QStringList>
13
14#include "misc/country.h"
15#include "misc/db/datastore.h"
16#include "misc/metaclass.h"
21#include "misc/valueobject.h"
22
23SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::network, CAuthenticatedUser)
24
25namespace swift::misc::network
26{
31 public CValueObject<CAuthenticatedUser>,
33 {
34 public:
37 {
38 IndexEmail = swift::misc::CPropertyIndexRef::GlobalIndexCAuthenticatedUser,
39 IndexVatsimId,
40 IndexPassword,
41 IndexRealName,
42 IndexUsername
43 };
44
46 CAuthenticatedUser() = default;
47
49 CAuthenticatedUser(int id, const QString &realname);
50
52 CAuthenticatedUser(int id, const QString &realname, const QString &email = "", const QString &password = "");
53
55 const QString &getRealName() const { return m_realname; }
56
58 QString getRealNameAndId() const;
59
61 void setRealName(const QString &realname);
62
64 const QString &getUsername() const { return m_username; }
65
67 void setUsername(const QString &username);
68
70 const QString &getPassword() const { return m_password; }
71
73 void setPassword(const QString &pw) { m_password = pw.trimmed(); }
74
76 bool isValid() const { return !m_realname.isEmpty() && this->hasValidDbKey(); }
77
79 bool hasValidCredentials() const { return this->isValid() && !m_password.isEmpty(); }
80
82 bool hasValidRealName() const { return !m_realname.isEmpty(); }
83
85 swift::misc::CStatusMessageList validate() const;
86
88 const QString &getEmail() const { return m_email; }
89
91 void setEmail(const QString &email) { m_email = email.trimmed(); }
92
94 bool hasValidEmail() const { return !m_email.isEmpty(); }
95
97 int getVatsimId() const { return m_vatsimId; }
98
100 void setVatsimId(int id) { m_vatsimId = id; }
101
103 const CRoleList &getRoles() const { return m_roles; }
104
106 QString getRolesAsString() const { return m_roles.namesAsString(); }
107
109 void setRoles(const CRoleList &roles) { m_roles = roles; }
110
112 bool hasRole(const QString &roleName) const { return m_roles.hasRole(roleName); }
113
115 bool hasAnyRole(const QStringList &roles) const { return m_roles.hasAnyRole(roles); }
116
118 const swift::misc::CCountry &getCountry() const { return m_country; }
119
121 void setCountry(const swift::misc::CCountry &country) { m_country = country; }
122
124 bool hasAdminRole() const;
125
127 bool hasMappingAdminRole() const;
128
130 bool hasBulkRole() const;
131
133 bool hasBulkAddRole() const;
134
136 void setAuthenticated(bool authenticated) { m_authenticated = authenticated; }
137
139 bool isAuthenticated() const;
140
142 void setEnabled(bool enabled) { m_enabled = enabled; }
143
145 bool isEnabled() const { return m_enabled; }
146
148 bool canDirectlyWriteModels() const;
149
151 swift::misc::CIcons::IconIndex toIcon() const;
152
154 QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
155
157 void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
158
160 QString convertToQString(bool i18n = false) const;
161
163 static CAuthenticatedUser fromDatabaseJson(const QJsonObject &json);
164
165 private:
166 int m_vatsimId = -1;
167 QString m_realname;
168 QString m_username;
169 QString m_email;
170 QString m_password;
171 swift::misc::CCountry m_country;
172 bool m_enabled = false;
173 bool m_authenticated = false;
174 CRoleList m_roles;
175
178 SWIFT_METAMEMBER(dbKey),
179 SWIFT_METAMEMBER(vatsimId),
180 SWIFT_METAMEMBER(realname),
181 SWIFT_METAMEMBER(username),
182 SWIFT_METAMEMBER(email),
183 SWIFT_METAMEMBER(password),
184 SWIFT_METAMEMBER(country),
185 SWIFT_METAMEMBER(enabled),
186 SWIFT_METAMEMBER(authenticated),
187 SWIFT_METAMEMBER(roles));
188 };
189} // namespace swift::misc::network
190
192
193#endif // SWIFT_MISC_NETWORK_AUTHENTICATEDUSER_H
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition icons.h:32
Non-owning reference to a CPropertyIndex with a subset of its features.
Status messages, e.g. from Core -> GUI.
Class from which a derived class can inherit datastore-related functions.
Definition datastore.h:70
bool hasValidDbKey() const
Has valid DB key.
Definition datastore.h:102
Value object encapsulating information of an authentiated user.
CAuthenticatedUser()=default
Default constructor.
const CRoleList & getRoles() const
Roles.
bool hasRole(const QString &roleName) const
Has role?
void setAuthenticated(bool authenticated)
Authenticated.
bool hasValidRealName() const
Valid real name?
void setEmail(const QString &email)
Set email.
bool hasValidCredentials() const
Valid credentials?
const swift::misc::CCountry & getCountry() const
Country.
void setCountry(const swift::misc::CCountry &country)
Country.
bool hasAnyRole(const QStringList &roles) const
Has any role?
void setRoles(const CRoleList &roles)
Roles.
const QString & getUsername() const
Username.
const QString & getRealName() const
Get full name.
void setPassword(const QString &pw)
Set password.
const QString & getPassword() const
Get password.
const QString & getEmail() const
Get email.
bool isValid() const
Valid user object?
Value object encapsulating a list of servers.
Definition rolelist.h:27
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition metaclass.h:52
QString trimmed() const const
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition valueobject.h:65