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

Removed isRelevantUserNameToDbId() from Accounts interface.

parent 29b729e2
......@@ -100,22 +100,22 @@ Item {
if (userNameTextField.text.toString() !== oldUserName) {
// Create temporary account with a new user name.
if (accounts.prepareChangeUserName(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString(), oldUserName)) {
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString(), oldUserName)) {
// Login to isds with the new user name.
isds.doIsdsAction("changeUserName", userNameTextField.text.toString())
}
} else {
// Update account context data.
if (accounts.updateAccount(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) {
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) {
settings.saveAllSettings(accountModel)
}
}
......
......@@ -440,6 +440,24 @@ bool Accounts::prepareChangeUserName(const QVariant &acntModelVariant,
certPath);
}
/*!
* @brief Check whether the box identifier matches the username of a known account.
*
* @param[in] dbId Data box ID.
* @param[in] username User name of already existing account.
* @return True if username corresponds to data box id, false on any error.
*/
static
bool boxMatchesUser(const QString &dbId, const QString &username)
{
if (Q_UNLIKELY(dbId.isEmpty() || username.isEmpty())) {
Q_ASSERT(0);
return false;
}
return dbId == GlobInstcs::accountDbPtr->dbId(username);
}
bool Accounts::changeAccountUserName(const QVariant &acntModelVariant,
const QString &acntName, const QString &newUserName, bool storeToDisk,
const QString &oldUserName, const QString &newDbId)
......@@ -458,15 +476,16 @@ bool Accounts::changeAccountUserName(const QVariant &acntModelVariant,
/* Get account model */
accountModel = AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
if (Q_UNLIKELY(accountModel == Q_NULLPTR)) {
Q_ASSERT(0);
logErrorNL("%s", "Cannot access account model.");
goto exit;
}
/* Check if new user name corresponds with databox id */
if (!isRelevantUserNameToDbId(oldUserName, newDbId)) {
errTxt = tr("New user name '%1' not corresponds with databox ID.").arg(newUserName);
/* 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);
goto fail;
}
......@@ -580,12 +599,6 @@ bool Accounts::hasCorrectLengthUserName(const QString &userName)
return (userName.length() == 6);
}
bool Accounts::isRelevantUserNameToDbId(const QString &userName, const QString &dbId)
{
/* Check if new user corresponds with databox id */
return (dbId == GlobInstcs::accountDbPtr->dbId(userName));
}
void Accounts::deleteAccountFromModel(AccountListModel *accountModel,
const QString &userName)
{
......
......@@ -246,16 +246,6 @@ private:
static
bool hasCorrectLengthUserName(const QString &userName);
/*!
* @brief Check if new user name is relevant to databox id.
*
* @param[in] userName Original user name of account.
* @param[in] dbId Databox ID obtained from isds.
* @return True if user name is relevant to databox id.
*/
bool isRelevantUserNameToDbId(const QString &userName,
const QString &dbId);
/*!
* @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