Commit 5d57cca9 authored by Martin Straka's avatar Martin Straka

Updated create a new account in the account settings QML

parent caec1a7e
......@@ -72,16 +72,17 @@ Item {
anchors.fill: parent
onClicked: {
if (isNewAccount) {
if (accounts.createAccount(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) {
/* TODO - remove the function or make it asynchronous */
isds.getAccountInfo(userNameTextField.text.toString())
}
// Create a new account context data and add to model.
accounts.createAccount(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())
// Login to new account.
isds.doIsdsAction("addNewAccount", userNameTextField.text.toString())
} else {
// Update account context data.
if (accounts.updateAccount(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
......@@ -95,18 +96,31 @@ Item {
}
}
Connections {
// Connection is activated when account info was downloaded.
target: isds
onDownloadAccountInfoFinishedSig: {
if (isLogged) {
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)
pageView.pop(StackView.Immediate)
} else {
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)
}
}
}
}
} // PageHeader
......@@ -311,6 +325,7 @@ Item {
wrapMode: Text.Wrap
}
Connections {
// Connection is activated when settings of exists account is shown.
target: accounts
onSendAccountData: {
accountNameTextField.text = acntName
......
......@@ -229,6 +229,8 @@ void IsdsWrapper::doIsdsAction(const QString &isdsAction,
emit runChangePasswordSig(userName);
} else if (isdsAction == "downloadMessage") {
emit runDownloadMessageSig(userName);
} else if (isdsAction == "addNewAccount") {
emit runGetAccountInfoSig(userName);
} else if (isdsAction == "getAccountInfo") {
emit runGetAccountInfoSig(userName);
} else if (isdsAction == "syncOneAccount") {
......@@ -241,12 +243,6 @@ void IsdsWrapper::doIsdsAction(const QString &isdsAction,
return;
}
if (m_isdsSession.isdsCtxMap[userName].login_method ==
USERNAME_PWD_TOTP) {
doTotpLoginAction(isdsAction, userName);
return;
}
doLoginAction(isdsAction, userName);
}
......@@ -423,14 +419,13 @@ bool IsdsWrapper::isdsLogoutOTP(const QString &userName)
void IsdsWrapper::downloadAccountInfoFinished(const QString &userName,
bool success, const QString &errTxt)
{
emit downloadAccountInfoFinishedSig(userName, true);
if (!success) {
Dialogues::errorMessage(Dialogues::WARNING,
tr("Account info: %1").arg(userName),
tr("Failed to get account info for username %1.").arg(userName),
errTxt);
} else {
emit downloadAccountInfoFinishedSig(userName);
emit statusBarTextChanged(errTxt, false, true);
}
}
......@@ -495,8 +490,15 @@ void IsdsWrapper::doLoginAction(const QString &isdsAction,
if (hasCtxAllLoginData(isdsAction, userName)) {
/* has all requried login data, login to databox */
if (loginToIsds(m_isdsSession.isdsCtxMap[userName])) {
/* login was successed so run isds action */
doIsdsAction(isdsAction, userName);
/* login was successed */
if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_TOTP) {
/* first login of TOTP was successed so run SMS login phase */
runSmsLoginPhase(m_isdsSession.isdsCtxMap[userName],
isdsAction);
} else {
/* login was successed so run isds action */
doIsdsAction(isdsAction, userName);
}
} else {
/* login was not successed, show error dialog */
showLoginProblemDialog(userName,
......@@ -506,27 +508,14 @@ void IsdsWrapper::doLoginAction(const QString &isdsAction,
} else {
m_isdsSession.isdsCtxMap[userName].pass_phrase.clear();
}
}
}
}
void IsdsWrapper::doTotpLoginAction(const QString &isdsAction,
const QString &userName)
{
qDebug("%s()", __func__);
/* All login data are requried */
if (hasCtxAllLoginData(isdsAction, userName)) {
/* has all requried login data, login to databox */
if (loginToIsds(m_isdsSession.isdsCtxMap[userName])) {
/* first login was successed so run SMS login phase */
runSmsLoginPhase(m_isdsSession.isdsCtxMap[userName],
isdsAction);
} else {
/* login was not successed, show error dialog */
showLoginProblemDialog(userName,
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
m_isdsSession.isdsCtxMap[userName].password.clear();
/*
* if we add a new account and login failed
* then we must emit signal to QML and delele
* account from account model.
*/
if (isdsAction == "addNewAccount") {
emit unsuccessedLoginToIsdsSig(userName);
}
}
}
}
......
......@@ -208,12 +208,11 @@ signals:
void downloadMessageListFinishedSig(bool isMsgReceived);
/*!
* @brief Update account info model in QML.
* @brief Update account info in QML.
*
* @param[in] userName Account user name string.
* @param[in] isLogged True if a new account was login to DS.
*/
void downloadAccountInfoFinishedSig(QString userName, bool isLogged);
void downloadAccountInfoFinishedSig(QString userName);
/*!
* @brief Run change password isds action from QML.
......@@ -264,10 +263,17 @@ signals:
*/
void runSyncSingleAccountSentSig(QString userName);
/*!
* @brief Signal is emitted when login to isds of new account fails.
*
* @param[in] userName Account user name string.
*/
void unsuccessedLoginToIsdsSig(QString userName);
public slots:
/*!
* @brief Do some actions when download account info finished.
* @brief Do post actions when download account info finished.
*
* @param[in] userName Account username string.
* @param[in] success True if success.
......@@ -277,7 +283,7 @@ public slots:
bool success, const QString &errTxt);
/*!
* @brief Do some actions when download delivery info finished.
* @brief Do post actions when download delivery info finished.
*
* @param[in] userName Account username string.
* @param[in] msgId Message ID.
......@@ -288,7 +294,7 @@ public slots:
qint64 msgId, bool success, const QString &errTxt);
/*!
* @brief Do some actions when download message finished.
* @brief Do post actions when download message finished.
*
* @param[in] userName Account username string.
* @param[in] msgId Message ID.
......@@ -299,7 +305,7 @@ public slots:
bool success, const QString &errTxt);
/*!
* @brief Do some actions when download message list finished.
* @brief Do post actions when download message list finished.
*
* @param[in] userName Account username string.
* @param[in] success True if success.
......@@ -329,15 +335,6 @@ private:
*/
void doLoginAction(const QString &isdsAction, const QString &userName);
/*!
* @brief Do TOTP login action.
*
* @param[in] isdsAction Isds action identificator.
* @param[in] userName Account username string.
*/
void doTotpLoginAction(const QString &isdsAction,
const QString &userName);
/*!
* @brief Downloads complete message.
*
......
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