accounts.h 7.47 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 13 14
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24
#pragma once
25 26 27

#include <QObject>

28 29
class AccountListModel; /* Forward declaration. */

30 31 32 33 34
/*
 * Class Accounts provides interface between QML and account database, settings.
 * Class is initialised in the main function (main.cpp)
 */
class Accounts : public QObject {
Karel Slaný's avatar
Karel Slaný committed
35
	Q_OBJECT
36 37

public:
38
	explicit Accounts(QObject *parent = Q_NULLPTR);
39

Martin Straka's avatar
Martin Straka committed
40 41 42 43 44 45
	/*!
	 * @brief Get account data box ID from database.
	 *
	 * @param[in] userName User name identifying account.
	 * @return Databox id string.
	 */
Martin Straka's avatar
Martin Straka committed
46
	Q_INVOKABLE static
Martin Straka's avatar
Martin Straka committed
47 48
	QString boxId(const QString &userName);

49 50 51 52 53 54 55 56 57
	/*!
	 * @brief Check whether data box has effective OVM.
	 *
	 * @param[in] userName User name identifying account.
	 * @return True if data box has effective OVM.
	 */
	Q_INVOKABLE static
	bool boxEffectiveOVM(const QString &userName);

58 59 60 61 62 63 64 65
	/*!
	 * @brief Update message counters in account list.
	 *
	 * @param[in] accountModel Model whose counters should be updated.
	 */
	Q_INVOKABLE static
	void updateAccountCounters(const QVariant &acntModelVariant);

66 67
	/*!
	 * @brief Update new message counter.
68
	 *
Martin Straka's avatar
Martin Straka committed
69 70
	 * @param[in,out] acntModelVariant QVariant holding account model.
	 * @param[in] userName User name identifying account.
71
	 */
72 73 74
	Q_INVOKABLE static
	void updateNewMessageCounter(const QVariant &acntModelVariant,
	    const QString &userName);
75 76

	/*!
Martin Straka's avatar
Martin Straka committed
77 78 79
	 * @brief Load account info from database for QML page.
	 *
	 * @param[in] userName User name identifying account.
80
	 * @return Account detail info html string.
81
	 */
82 83
	Q_INVOKABLE
	QString fillAccountInfo(const QString &userName);
84

Martin Straka's avatar
Martin Straka committed
85 86 87 88 89
	/*!
	 * @brief Get account data for QML page.
	 *
	 * @param[in] userName User name identifying account.
	 */
90 91
	Q_INVOKABLE
	void getAccountData(const QString &userName);
Martin Straka's avatar
Martin Straka committed
92

93 94
	/*!
	 * @brief Create account.
Martin Straka's avatar
Martin Straka committed
95 96 97 98 99 100 101 102 103 104 105
	 *
	 * @param[in,out] acntModelVariant QVariant holding account model.
	 * @param[in] loginMetod User name identifying account.
	 * @param[in] acntName Account name.
	 * @param[in] userName User name identifying account.
	 * @param[in] pwd Password.
	 * @param[in] isTestAccount True if account is isds test enveiroment.
	 * @param[in] rememberPwd True if remember password.
	 * @param[in] storeToDisk True if database store to local storage.
	 * @param[in] certPath Certificate path (can be null).
	 * @return True if success.
106
	 */
107
	Q_INVOKABLE static
108 109 110 111
	bool createAccount(const QVariant &acntModelVariant,
	    const QString &loginMetod, const QString &acntName,
	    const QString &userName, const QString &pwd, bool isTestAccount,
	    bool rememberPwd, bool storeToDisk, const QString &certPath);
112 113 114

	/*!
	 * @brief Update account.
Martin Straka's avatar
Martin Straka committed
115 116 117 118
	 *
	 * @param[in,out] acntModelVariant QVariant holding account model.
	 * @param[in] loginMetod User name identifying account.
	 * @param[in] acntName Account name.
119
	 * @param[in] userName User name identifying account.
Martin Straka's avatar
Martin Straka committed
120 121 122 123 124 125
	 * @param[in] pwd Password.
	 * @param[in] isTestAccount True if account is isds test enveiroment.
	 * @param[in] rememberPwd True if remember password.
	 * @param[in] storeToDisk True if database store to local storage.
	 * @param[in] certPath Certificate path (can be null).
	 * @return True if success.
126
	 */
127
	Q_INVOKABLE
128
	bool updateAccount(const QVariant &acntModelVariant,
129
	    const QString &loginMetod, const QString &acntName,
130
	    const QString &userName, const QString &pwd, bool isTestAccount,
131
	    bool rememberPwd, bool storeToDisk, const QString &certPath);
132 133 134

	/*!
	 * @brief Remove account.
135
	 *
Martin Straka's avatar
Martin Straka committed
136 137 138
	 * @param[in,out] acntModelVariant QVariant holding account model.
	 * @param[in] userName User name identifying account.
	 * @param[in] showDialogue Whether to notify the user using a dialogue.
139
	 */
140 141 142
	Q_INVOKABLE
	bool removeAccount(const QVariant &acntModelVariant,
	    const QString &userName, bool showDialogue);
143

144 145 146 147 148 149 150 151 152 153 154 155 156 157
	/*!
	 * @brief Loads model counters from database.
	 *
	 * @param[in,out] accountModel Model whose counters should be updated.
	 */
	static
	void loadModelCounters(AccountListModel *accountModel);

	/*!
	 * @brief Prepare change account user name.
	 *
	 * @param[in,out] acntModelVariant QVariant holding account model.
	 * @param[in] loginMetod User name identifying account.
	 * @param[in] acntName Account name.
Martin Straka's avatar
Martin Straka committed
158
	 * @param[in] newUserName New user name identifying account.
159
	 * @param[in] pwd Password.
160
	 * @param[in] isTestAccount True if account is ISDS test environment.
161 162 163
	 * @param[in] rememberPwd True if remember password.
	 * @param[in] storeToDisk True if database store to local storage.
	 * @param[in] certPath Certificate path (can be null).
Martin Straka's avatar
Martin Straka committed
164
	 * @param[in] oldUserName Original old user name of account.
165 166 167 168 169 170 171 172 173
	 * @return True if success.
	 */
	Q_INVOKABLE
	bool prepareChangeUserName(const QVariant &acntModelVariant,
	    const QString &loginMetod, const QString &acntName,
	    const QString &newUserName, const QString &pwd, bool isTestAccount,
	    bool rememberPwd, bool storeToDisk, const QString &certPath,
	    const QString &oldUserName);

174
	/*!
Martin Straka's avatar
Martin Straka committed
175
	 * @brief Change account user name and store account to settings.
176 177 178
	 *
	 * @param[in,out] acntModelVariant QVariant holding account model.
	 * @param[in] acntName Account name.
Martin Straka's avatar
Martin Straka committed
179
	 * @param[in] newUserName New user name identifying account.
180 181 182 183 184 185 186 187 188 189
	 * @param[in] storeToDisk True if database store to local storage.
	 * @param[in] oldUserName Original user name of account.
	 * @param[in] newDbId Databox id of new user name.
	 * @return True if success.
	 */
	Q_INVOKABLE
	bool changeAccountUserName(const QVariant &acntModelVariant,
	    const QString &acntName, const QString &newUserName,
	    bool storeToDisk, const QString &oldUserName, const QString &newDbId);

190 191 192
signals:
	/*!
	 * @brief Send account settings to QML settings page.
Martin Straka's avatar
Martin Straka committed
193 194 195 196 197
	 *
	 * @param[in] acntName Account name.
	 * @param[in] userName User name identifying account.
	 * @param[in] loginMetod User name identifying account.
	 * @param[in] pwd Password.
198
	 * @param[in] isTestAccount True if account is ISDS test environment.
Martin Straka's avatar
Martin Straka committed
199 200 201
	 * @param[in] rememberPwd True if remember password.
	 * @param[in] storeToDisk True if database store to local storage.
	 * @param[in] certPath Certificate path (can be null).
202 203
	 */
	void sendAccountData(QString acntName, QString userName,
204
	    QString loginMethod, QString password, bool isTestAccount,
Martin Straka's avatar
Martin Straka committed
205
	    bool rememberPwd, bool storeToDisk, QString certPath);
206 207

	/*!
208
	 * @brief Remove ISDS context for account in the ISDS session.
Martin Straka's avatar
Martin Straka committed
209
	 *
210
	 * @param[in] userName User name.
211 212
	 */
	void removeIsdsCtx(QString userName);
213 214

private:
Martin Straka's avatar
Martin Straka committed
215 216 217 218 219 220 221 222
	/*!
	 * @brief Delete account from model.
	 *
	 * @param[in,out] accountModel Model whose counters should be updated.
	 * @param[in] userName User name identifying account.
	 */
	void deleteAccountFromModel(AccountListModel *accountModel,
	    const QString &userName);
223
};