account_db.h 3.9 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2018 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 15 16 17 18 19 20 21 22 23
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * 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 28

#include <QList>
#include <QString>

29
#include "src/datovka_shared/io/sqlite/db_single.h"
30 31 32 33 34
#include "src/net/db_wrapper.h"

/*!
 * @brief Encapsulates account database.
 */
35
class AccountDb : public SQLiteDbSingle {
36 37

public:
38 39
	/* Use parent class constructor. */
	using SQLiteDbSingle::SQLiteDbSingle;
40 41 42

	/*!
	 * @brief Return data box identifier.
43 44 45 46
	 *
	 * @param[in] userName Account user name.
	 * @param[in] defaultValue Default value.
	 * @return Databox id string.
47 48 49 50
	 */
	const QString dbId(const QString &userName,
	    const QString &defaultValue = QString()) const;

51 52 53 54 55 56 57 58
	/*!
	 * @brief Check if databox has effective OVM.
	 *
	 * @param[in] userName User name identifying account.
	 * @return True if databox is effective OVM.
	 */
	bool boxEffectiveOVM(const QString &userName) const;

59
	/*!
60 61 62 63
	 * @brief Delete account info from db.
	 *
	 * @param[in] userName Account user name.
	 * @return True on success.
64
	 */
65
	bool deleteAccountInfoFromDb(const QString &userName) const;
66 67

	/*!
68 69 70
	 * @brief Delete user info from db.
	 *
	 * @param[in] userName Account user name.
71
	 * @return True on success.
72
	 */
73
	bool deleteUserInfoFromDb(const QString &userName) const;
74 75

	/*!
76 77 78 79
	 * @brief Get account info and user info from db as html text.
	 *
	 * @param[in] userName Account user name.
	 * @return Html string of account detail.
80
	 */
81
	QString accountDetailHtml(const QString &userName) const;
82 83

	/*!
84 85
	 * @brief Insert account info into db.
	 *
86 87
	 * @param[in] userName Account user name.
	 * @param[in] dbOwnerInfo Account (owner) info structure.
88 89
	 * @return True on success.
	 */
90 91
	bool insertAccountInfoIntoDb(const QString &userName,
	    const Isds::DbOwnerInfo &dbOwnerInfo);
92 93 94 95

	/*!
	 * @brief Insert user info into db.
	 *
96 97
	 * @param[in] userName Account user name.
	 * @param[in] dbUserInfo User info structure.
98
	 * @return True on success.
99
	 */
100 101
	bool insertUserInfoIntoDb(const QString &userName,
	    const Isds::DbUserInfo &dbUserInfo);
102 103

	/*!
104 105 106 107 108
	 * @brief Update pwd expiration in db.
	 *
	 * @param[in] userName Account user name.
	 * @param[in] date New expiration date.
	 * @return True on success.
109
	 */
110
	bool updatePwdExpirInDb(const QString &userName, const QString &date);
111

112 113 114 115 116 117 118 119
	/*!
	 * @brief Get account/owner info from database.
	 *
	 * @param[in] key Key value.
	 * @return DbOwnerInfo structure - account info.
	 */
	const Isds::DbOwnerInfo getOwnerInfo(const QString &key) const;

120 121 122 123 124 125 126 127 128 129
	/*!
	 * @brief Change user name in account db.
	 *
	 * @param[in] oldUserName Current account user name.
	 * @param[in] newUserName New account user name.
	 * @return True on success.
	 */
	bool changeUserName(const QString &oldUserName,
	    const QString &newUserName);

130 131 132 133 134 135 136 137
protected:
	/*!
	 * @brief Returns list of tables.
	 *
	 * @return List of pointers to tables.
	 */
	virtual
	QList<class SQLiteTbl *> listOfTables(void) const Q_DECL_OVERRIDE;
138

139
private:
140 141 142 143 144 145 146
	static
	const QVector<QString> dsPrintedAttribs;
	static
	const QVector<QString> ownerPrintedAttribs;
	static
	const QVector<QString> userPrintedAttribs;
};