Commit 798f79ce authored by Martin Straka's avatar Martin Straka Committed by Karel Slaný

Check if new username is relevant to databox id

parent 7e776261
......@@ -96,17 +96,25 @@ Item {
isds.doIsdsAction("addNewAccount", userNameTextField.text.toString())
}
} else {
// Update account context data.
if (accounts.updateAccount(accountModel, sLoginMethod,
// Change account user name.
if (userNameTextField.text.toString() !== oldUserName) {
if (accounts.createAccount(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString(),
oldUserName)) {
settings.saveAllSettings(accountModel)
if (userNameTextField.text.toString() !== oldUserName) {
isds.doIsdsAction("getAccountInfo", userNameTextField.text.toString())
useLS.checked, certPathLabelId.text.toString())) {
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())) {
settings.saveAllSettings(accountModel)
}
}
pageView.pop(StackView.Immediate)
......@@ -119,24 +127,25 @@ Item {
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
}
}
Connections {
// Connection is activated when login to new account fails.
target: isds
onUnsuccessedLoginToIsdsSig: {
if (accounts.removeAccount(accountModel, userName, false)) {
settings.saveAllSettings(accountModel)
}
}
}
Connections {
// Connection is activated when login phase was succeeded and
// try download account info.
target: isds
onRunGetAccountInfoSig: {
settings.saveAllSettings(accountModel)
isds.getAccountInfo(userName)
}
onRunChangeUserNameSig: {
var dbId = isds.getAccountDbId(userName)
if (accounts.changeAccountUserName(accountModel,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
useLS.checked, oldUserName, dbId)) {
settings.saveAllSettings(accountModel)
isds.getAccountInfo(userName)
}
}
}
}
}
......@@ -178,7 +187,7 @@ Item {
if (sLoginMethod === "cert") {
certificateLabel.visible = true
certPathButtonId.visible = true
certPathLabelId.visible = (certPathLabelId.text != "")
certPathLabelId.visible = (certPathLabelId.text !== "")
} else {
certificateLabel.visible = false
certPathLabelId.visible = false
......
This diff is collapsed.
......@@ -104,7 +104,7 @@ public:
* @param[in] certPath Certificate path (can be null).
* @return True if success.
*/
Q_INVOKABLE static
Q_INVOKABLE
bool createAccount(const QVariant &acntModelVariant,
const QString &loginMetod, const QString &acntName,
const QString &userName, const QString &pwd, bool isTestAccount,
......@@ -122,15 +122,13 @@ public:
* @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).
* @param[in] oldUserName Original user name of account.
* @return True if success.
*/
Q_INVOKABLE
bool updateAccount(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);
bool rememberPwd, bool storeToDisk, const QString &certPath);
/*!
* @brief Remove account.
......@@ -143,6 +141,22 @@ public:
bool removeAccount(const QVariant &acntModelVariant,
const QString &userName, bool showDialogue);
/*!
* @brief Change account user name and update account settings.
*
* @param[in,out] acntModelVariant QVariant holding account model.
* @param[in] acntName Account name.
* @param[in] newUserName User name identifying account.
* @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);
/*!
* @brief Loads model counters from database.
*
......@@ -178,23 +192,44 @@ signals:
private:
/*!
* @brief Change account user name and update account settings.
* @brief Change file database name to new user name.
*
* @param[in,out] accountModel Holding account model.
* @param[in] loginMetod User name identifying account.
* @param[in] acntName Account name.
* @param[in] newUserName User name identifying account.
* @param[in] password Password.
* @param[in] isTestAccount True if account is isds test enveiroment.
* @param[in] rememberPwd True if remember password.
* @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[in] certPath Certificate path (can be null).
* @param[out] errTxt Error description.
* @return True if success.
*/
bool changeFileDbName(const QString &oldUserName,
const QString &newUserName, bool storeToDisk, QString &errTxt);
/*!
* @brief Change message database name to new user name.
*
* @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.
*/
bool changeAccountUserName(AccountListModel *accountModel,
const QString &loginMetod, const QString &acntName,
const QString &newUserName, const QString &password,
bool isTestAccount, bool rememberPwd, bool storeToDisk,
const QString &certPath, const QString &oldUserName);
bool changeMessageDbName(const QString &oldUserName,
const QString &newUserName, bool storeToDisk, QString &errTxt);
/*!
* @brief Check correct length of user name.
*
* @param[in] userName New user name identifying account.
* @return True if length is correct.
*/
bool checkCorrectLengthUserName(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 isRelevantUserName(const QString &userName,
const QString &dbId);
};
......@@ -261,6 +261,8 @@ void IsdsWrapper::doIsdsAction(const QString &isdsAction,
emit runDownloadMessageSig(userName);
} else if (isdsAction == "addNewAccount") {
emit runGetAccountInfoSig(userName);
} else if (isdsAction == "changeUserName") {
emit runChangeUserNameSig(userName);
} else if (isdsAction == "getAccountInfo") {
emit runGetAccountInfoSig(userName);
} else if (isdsAction == "syncOneAccount") {
......@@ -321,12 +323,46 @@ void IsdsWrapper::getAccountInfo(const QString &userName)
arg(userName), true, true);
TaskDownloadAccountInfo *task;
/* Last param: true = store account info into database */
task = new (std::nothrow) TaskDownloadAccountInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer);
m_isdsSession.isdsCtxMap[userName], &m_netLayer, true);
task->setAutoDelete(true);
GlobInstcs::workPoolPtr->assignHi(task);
}
QString IsdsWrapper::getAccountDbId(const QString &userName)
{
debugFuncCall();
if (Q_UNLIKELY(GlobInstcs::workPoolPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return QString();
}
QString errTxt = tr("Wrong username");
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return QString();
}
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
return QString();
}
TaskDownloadAccountInfo *task;
/* Last param: false = account info won't store into database */
task = new (std::nothrow) TaskDownloadAccountInfo(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, false);
task->setAutoDelete(false);
GlobInstcs::workPoolPtr->runSingle(task);
QString dbId = task->m_dbID;
delete task; task = Q_NULLPTR;
return dbId;
}
int IsdsWrapper::findDataboxFulltext(const QString &userName,
const QVariant &dbModelVariant, const QString &phrase,
const QString &searchType, const QString &searchScope, int page)
......@@ -516,7 +552,7 @@ bool IsdsWrapper::isCorrectPassword(const QString &password)
void IsdsWrapper::inputDialogCancelPostAction(const QString &isdsAction,
const QString &userName)
{
if (isdsAction == "addNewAccount") {
if (isdsAction == "addNewAccount" || isdsAction == "changeUserName") {
emit unsuccessedLoginToIsdsSig(userName);
}
}
......@@ -1124,6 +1160,14 @@ void IsdsWrapper::doLoginAction(const QString &isdsAction,
tr("ISDS returns:") + " " + m_isdsSession.isdsCtxMap[userName].last_isds_msg + "\n\n" +
tr("Check your login data and try again."));
emit unsuccessedLoginToIsdsSig(userName);
} else if (isdsAction == "changeUserName") {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("User name change: %1").arg(userName),
tr("User name could not be changed because an error occurred "
"while trying to log in with new user name '%1'.").arg(userName),
tr("ISDS returns:") + " " + m_isdsSession.isdsCtxMap[userName].last_isds_msg + "\n\n" +
tr("Check your login data and try again."));
emit unsuccessedLoginToIsdsSig(userName);
} else {
/* Show error login dialogue */
Dialogues::errorMessage(Dialogues::CRITICAL,
......
......@@ -8,7 +8,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
......@@ -130,6 +130,15 @@ public:
Q_INVOKABLE
void getAccountInfo(const QString &userName);
/*!
* @brief Get databox ID from ISDS.
*
* @param[in] userName Account username string.
* @return Return databox ID.
*/
Q_INVOKABLE
QString getAccountDbId(const QString &userName);
/*!
* @brief Downloads delivery info.
*
......@@ -347,6 +356,13 @@ signals:
*/
void downloadAccountInfoFinishedSig(QString userName);
/*!
* @brief Signal is emitted when account username can be changed.
*
* @param[in] userName Account user name string.
*/
void runChangeUserNameSig(QString userName);
/*!
* @brief Run download mesasge isds action from QML.
*
......
......@@ -33,10 +33,12 @@
#include "src/xml/xml_get_db_user_info.h"
TaskDownloadAccountInfo::TaskDownloadAccountInfo(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer)
NetLayer *netLayer, bool storeToDb)
: m_result(DL_ERR),
m_dbID(QString()),
m_ctx(ctx),
m_netLayer(netLayer)
m_netLayer(netLayer),
m_storeToDb(storeToDb)
{
}
......@@ -52,13 +54,15 @@ void TaskDownloadAccountInfo::run(void)
logDebugLv0NL("%s", "--------------ACCOUNT INFO TASK---------------");
logDebugLv0NL("Starting in thread '%p'", QThread::currentThreadId());
m_result = downloadAccountInfo(m_ctx, m_netLayer);
m_result = downloadAccountInfo(m_ctx, m_netLayer, m_storeToDb, m_dbID);
if (GlobInstcs::msgProcEmitterPtr != Q_NULLPTR) {
emit GlobInstcs::msgProcEmitterPtr->downloadAccountInfoFinishedSignal(
m_ctx.username,
TaskDownloadAccountInfo::DL_SUCCESS == m_result,
m_ctx.last_isds_msg);
if (m_storeToDb) {
if (GlobInstcs::msgProcEmitterPtr != Q_NULLPTR) {
emit GlobInstcs::msgProcEmitterPtr->downloadAccountInfoFinishedSignal(
m_ctx.username,
TaskDownloadAccountInfo::DL_SUCCESS == m_result,
m_ctx.last_isds_msg);
}
}
logDebugLv0NL("Finished in thread '%p'", QThread::currentThreadId());
......@@ -68,7 +72,8 @@ void TaskDownloadAccountInfo::run(void)
}
enum TaskDownloadAccountInfo::Result TaskDownloadAccountInfo::downloadAccountInfo(
IsdsSession::IsdsContext &ctx, NetLayer *netLayer)
IsdsSession::IsdsContext &ctx, NetLayer *netLayer, bool storeToDb,
QString &dbID)
{
if (ctx.username.isEmpty()) {
logErrorNL("%s", "Account user name missing!");
......@@ -97,6 +102,11 @@ enum TaskDownloadAccountInfo::Result TaskDownloadAccountInfo::downloadAccountInf
return DL_XML_ERROR;
}
if (!storeToDb) {
dbID = dbOwnerInfo.dbID();
return DL_SUCCESS;
}
/* Store data into db */
if (!DbWrapper::insertAccountInfoToDb(ctx.username, dbOwnerInfo)) {
logErrorNL("Cannot store owner info into database: '%s'",
......
......@@ -8,7 +8,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
......@@ -21,8 +21,7 @@
* the two.
*/
#ifndef _TASK_DOWNLOAD_ACCOUNT_INFO_H_
#define _TASK_DOWNLOAD_ACCOUNT_INFO_H_
#pragma once
#include "src/net/isds_session.h"
#include "src/net/net_layer.h"
......@@ -47,11 +46,12 @@ public:
/*!
* @brief Constructor.
*
* @param[in] ctx Account isds context (include username).
* @param[in] netLayer Pointer to network manager.
* @param[in] ctx Account isds context (include username).
* @param[in] netLayer Pointer to network manager.
* @param[in] storeToDb True if account info will store into database.
*/
explicit TaskDownloadAccountInfo(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer);
NetLayer *netLayer, bool storeToDb);
/*!
* @brief Performs actual account info download.
......@@ -62,15 +62,18 @@ public:
/*!
* @brief Download account info.
*
* @param[in] ctx Account isds context (include username).
* @param[in] netLayer Pointer to network manager.
* @param[in] ctx Account isds context (include username).
* @param[in] netLayer Pointer to network manager.
* @param[in] storeToDb True if account info will store into database.
* @param[out] dbID Holds and returns databox ID.
* @return Error state.
*/
static
enum Result downloadAccountInfo(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer);
NetLayer *netLayer, bool storeToDb, QString &dbID);
enum Result m_result; /*!< Return state. */
QString m_dbID; /*!< Return databox ID. */
private:
/*!
......@@ -81,6 +84,5 @@ private:
IsdsSession::IsdsContext m_ctx; /*!< Account isds context. */
NetLayer *m_netLayer; /*!< Pointer to network manager to send request. */
bool m_storeToDb; /*!< True if account info will store into database. */
};
#endif /* _TASK_DOWNLOAD_ACCOUNT_INFO_H_ */
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