Commit ccfa3c7c authored by Karel Slaný's avatar Karel Slaný

Modification in interface of Accounts.

parent a26a343d
......@@ -146,6 +146,18 @@ void Accounts::getAccountData(const QString &userName)
acntData.rememberPwd(), acntData.storeToDisk(), acntData.certPath());
}
/*!
* @brief Check if username has correct length.
*
* @param[in] username Account login.
* @return True if length is correct.
*/
static
bool usernameCorrectLength(const QString &userName)
{
return userName.length() == 6;
}
bool Accounts::createAccount(const QVariant &acntModelVariant,
const QString &loginMetod, const QString &acntName, const QString &userName,
const QString &pwd, bool isTestAccount, bool rememberPwd, bool storeToDisk,
......@@ -170,7 +182,7 @@ bool Accounts::createAccount(const QVariant &acntModelVariant,
goto fail;
}
if (!hasCorrectLengthUserName(newUserName)) {
if (!usernameCorrectLength(newUserName)) {
errTxt = tr("User name '%1' has wrong length.").arg(newUserName);
goto fail;
}
......@@ -484,14 +496,15 @@ bool Accounts::changeAccountUserName(const QVariant &acntModelVariant,
/* Check if new user name corresponds with data box id. */
if (!boxMatchesUser(newDbId, oldUserName)) {
errTxt = tr("New data box identifier '%1' does not correspond with the user name '%2'.")
.arg(newDbId).arg(newUserName);
errTxt = tr("New data box identifier '%1' does not correspond with the old username '%2'.")
.arg(newDbId).arg(oldUserName);
goto fail;
}
/* First: Change user name in the account database (user_info, account_info) */
if (!GlobInstcs::accountDbPtr->changeUserName(oldUserName, newUserName)) {
errTxt = tr("Cannot change user name '%1' in the account database.").arg(newUserName);
errTxt = tr("Cannot change username '%1' in the account database.")
.arg(newUserName);
goto fail;
}
......@@ -508,12 +521,13 @@ bool Accounts::changeAccountUserName(const QVariant &acntModelVariant,
/* Last: Delete original/old account from model and settings */
deleteAccountFromModel(accountModel, oldUserName);
logInfoNL("Username has been changed on '%s'.",
logInfoNL("Username has been changed to '%s'.",
newUserName.toUtf8().constData());
Dialogues::errorMessage(Dialogues::INFORMATION,
tr("Change user name: %1").arg(oldUserName),
tr("The new user name '%1' for account '%2' has been set.").arg(newUserName).arg(acntName),
tr("A new user name '%1' for the account '%2' has been set.")
.arg(newUserName).arg(acntName),
tr("Account will use the new settings."));
return true;
......@@ -522,23 +536,26 @@ rollbackFilesChanges:
/* Change back file database name */
if (changeFileDbName(newUserName, oldUserName, storeToDisk, errTxt)) {
logErrorNL("Cannot change back file database name %s.",
logErrorNL("Cannot restore file database name '%s'.",
oldUserName.toUtf8().constData());
}
rollbackAccountChanges:
/* Change back origial user name in the account database */
/* Change back original user name in the account database. */
if (!GlobInstcs::accountDbPtr->changeUserName(newUserName, oldUserName)) {
logErrorNL("%s", "Cannot change back user name in the account database.");
logErrorNL("%s",
"Cannot restore user name in the account database.");
}
fail:
/* Show error dialog with message what happened */
/* Show error dialogue with message what happened */
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("User name problem: %1").arg(oldUserName),
tr("The new user name '%1' for account '%2' has not been set!").arg(newUserName).arg(acntName),
errTxt + " " +tr("Account will use the original settings."));
tr("The new user name '%1' for account '%2' has not been set!")
.arg(newUserName).arg(acntName),
errTxt + QStringLiteral(" ") +
tr("Account will use the original settings."));
exit:
/* Remove new account */
......@@ -554,7 +571,7 @@ bool Accounts::changeFileDbName(const QString &oldUserName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, oldUserName, storeToDisk);
if (fDb == Q_NULLPTR) {
if (Q_UNLIKELY(fDb == Q_NULLPTR)) {
errTxt = tr("Cannot access file database for the user name '%1'.").arg(oldUserName);
return false;
}
......@@ -577,8 +594,9 @@ bool Accounts::changeMessageDbName(const QString &oldUserName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, oldUserName, storeToDisk);
if (msgDb == Q_NULLPTR) {
errTxt = tr("Cannot access message database for user name '%1'.").arg(oldUserName);
if (Q_UNLIKELY(msgDb == Q_NULLPTR)) {
errTxt = tr("Cannot access message database for user name '%1'.")
.arg(oldUserName);
return false;
}
......@@ -586,25 +604,25 @@ bool Accounts::changeMessageDbName(const QString &oldUserName,
QString currentDbFileName = msgDb->fileName();
currentDbFileName.replace(oldUserName, newUserName);
if (!msgDb->moveDb(currentDbFileName)) {
errTxt = tr("Cannot change message database on the user name '%1'.").arg(newUserName);
errTxt = tr("Cannot change message database on the user name '%1'.")
.arg(newUserName);
return false;
}
return true;
}
bool Accounts::hasCorrectLengthUserName(const QString &userName)
{
/* Check if new user name has correct length */
return (userName.length() == 6);
}
void Accounts::deleteAccountFromModel(AccountListModel *accountModel,
const QString &userName)
{
if (Q_UNLIKELY((accountModel == Q_NULLPTR) || userName.isEmpty())) {
Q_ASSERT(0);
return;
}
/* Remove old account from model */
accountModel->deleteAccount(userName);
/* Delete isds session context of old account */
/* Delete ISDS session context of old account */
emit removeIsdsCtx(userName);
/* Load message counters of all accounts */
loadModelCounters(accountModel);
......
......@@ -205,23 +205,23 @@ signals:
bool rememberPwd, bool storeToDisk, QString certPath);
/*!
* @brief Remove isds context for account in the isds session.
* @brief Remove ISDS context for account in the ISDS session.
*
* @param[in] acntName Account name.
* @param[in] userName User name.
*/
void removeIsdsCtx(QString userName);
private:
/*!
* @brief Change file database name to new user name.
* @brief Change file database name to new username.
*
* @param[in] oldUserName Original user name of account.
* @param[in] newUserName New user name identifying account.
* @param[in] storeToDisk True if database store to local storage.
* @param[out] errTxt Error description.
* @return True if success.
* @return True on success.
*/
static
bool changeFileDbName(const QString &oldUserName,
const QString &newUserName, bool storeToDisk, QString &errTxt);
......@@ -234,18 +234,10 @@ private:
* @param[out] errTxt Error description.
* @return True if success.
*/
static
bool changeMessageDbName(const QString &oldUserName,
const QString &newUserName, bool storeToDisk, QString &errTxt);
/*!
* @brief Check if user name has correct length.
*
* @param[in] userName New user name identifying account.
* @return True if length is correct.
*/
static
bool hasCorrectLengthUserName(const QString &userName);
/*!
* @brief Delete account from model.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment