Commit 422622da authored by Martin Straka's avatar Martin Straka

Final solution of change password via QML page

parent 84e38c31
......@@ -99,7 +99,13 @@ Item {
errLineText.visible = true
} else {
errLineText.visible = false
isds.doIsdsAction("changePassword", userName)
if (isds.changePassword(userName, oldPwd.text.toString(), newPwd.text.toString(), otpCode.text.toString())) {
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
} else {
errLineText.text = qsTr("Password change failed!")
errLineText.visible = true
}
}
} else {
errLineText.text = qsTr("Wrong password format! The new password must contain at least 8 characters including at least 1 number and at least 1 upper-case letter.")
......@@ -112,18 +118,6 @@ Item {
}
}
}
Connections {
target: isds
onRunChangePasswordSig: {
if (isds.changePassword(userName, oldPwd.text.toString(), newPwd.text.toString(), otpCode.text.toString())) {
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
} else {
errLineText.text = qsTr("Password change failed!")
errLineText.visible = true
}
}
}
}
}
} // PageHeader
......@@ -164,7 +158,7 @@ Item {
echoMode: TextInput.Password
passwordMaskDelay: 500 // milliseconds
inputMethodHints: Qt.ImhNone
placeholderText: qsTr("current password")
placeholderText: qsTr("Current password")
horizontalAlignment: TextInput.AlignHCenter
text: ""
}
......@@ -178,7 +172,7 @@ Item {
echoMode: TextInput.Password
passwordMaskDelay: 500 // milliseconds
inputMethodHints: Qt.ImhNone
placeholderText: qsTr("new password")
placeholderText: qsTr("New password")
horizontalAlignment: TextInput.AlignHCenter
text: ""
}
......@@ -191,7 +185,7 @@ Item {
echoMode: TextInput.Password
passwordMaskDelay: 500 // milliseconds
inputMethodHints: Qt.ImhNone
placeholderText: qsTr("confirm the new password")
placeholderText: qsTr("Confirm the new password")
horizontalAlignment: TextInput.AlignHCenter
text: ""
}
......@@ -216,18 +210,19 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Send SMS code")
onClicked: {
isds.doIsdsAction("sendSms", userName)
}
Connections {
target: isds
onRunSendSmsSig: {
if (isds.sendSMS(userName)) {
errLineText.text = qsTr("SMS code was sent")
if (oldPwd.text == "") {
errLineText.text = qsTr("Enter current password for SMS code sending!")
errLineText.visible = true
sendSmsButton.enabled = true
sendSmsButton.visible = true
} else {
if (isds.sendSMS(userName, oldPwd.text.toString())) {
errLineText.text = qsTr("SMS code was sent...")
errLineText.visible = true
sendSmsButton.enabled = false
sendSmsButton.visible = false
} else {
errLineText.text = qsTr("Problem: SMS code cannot be sent!")
errLineText.text = qsTr("SMS code cannot be sent! Wrong current password or ISDS server is out of service.")
errLineText.visible = true
sendSmsButton.enabled = true
sendSmsButton.visible = true
......
......@@ -84,73 +84,60 @@ bool IsdsWrapper::changePassword(const QString &userName, const QString &oldPwd,
qDebug("%s()", __func__);
bool success = false;
QString isdsText = tr("Unknow error");
QString errTxt = tr("Wrong username");
if (userName.isEmpty()) {
/* These fields must be set */
if (userName.isEmpty() || oldPwd.isEmpty() || newPwd.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return success;
}
if (!isLoggedToIsds(userName)) {
return success;
}
/* Check if isds context exist. If not, create new context */
isLoggedToIsds(userName);
/* Set current password entered by user */
m_isdsSession.isdsCtxMap[userName].password = oldPwd;
if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_TOTP) {
/* Set OTP type and OTP code */
QString otpType(OTP_NO_OTP);
if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_TOTP) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = otpCode;
TaskChangePassword *task;
task = new (std::nothrow) TaskChangePassword(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, OTP_TYPE_TOTP,
oldPwd, newPwd);
task->setAutoDelete(false);
m_workPool.runSingle(task);
success = TaskChangePassword::DL_SUCCESS == task->m_result;
delete task;
otpType = OTP_TYPE_TOTP;
} else if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_HOTP) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = otpCode;
TaskChangePassword *task;
task = new (std::nothrow) TaskChangePassword(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, OTP_TYPE_HOTP,
oldPwd, newPwd);
task->setAutoDelete(false);
m_workPool.runSingle(task);
success = TaskChangePassword::DL_SUCCESS == task->m_result;
delete task;
} else {
TaskChangePassword *task;
task = new (std::nothrow) TaskChangePassword(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, OTP_NO_OTP,
oldPwd, newPwd);
task->setAutoDelete(false);
m_workPool.runSingle(task);
success = TaskChangePassword::DL_SUCCESS == task->m_result;
delete task;
otpType = OTP_TYPE_HOTP;
}
TaskChangePassword *task;
task = new (std::nothrow) TaskChangePassword(
m_isdsSession.isdsCtxMap[userName], &m_netLayer, otpType,
oldPwd, newPwd);
task->setAutoDelete(false);
m_workPool.runSingle(task);
success = TaskChangePassword::DL_SUCCESS == task->m_result;
isdsText = task->m_isdsText;
delete task;
/* Show result dialogue */
if (!success) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Change password: %1").arg(userName),
tr("Change password error: %1").arg(userName),
tr("Failed to change password for username '%1'.").arg(userName),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
tr("ISDS returns: %1").arg(isdsText));
return success;
} else {
Dialogues::errorMessage(Dialogues::INFORMATION,
tr("Change password: %1").arg(userName),
tr("Password for username '%1' has changed.").arg(userName),
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
tr("ISDS returns: %1").arg(isdsText));
}
emit statusBarTextChanged(isdsText, false, true);
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false, true);
m_isdsSession.removeIsdsCtx(userName);
/* Set new password to current isds context */
m_isdsSession.isdsCtxMap[userName].password = userName;
/* Store new password to account settings */
AcntData &acntData(AccountListModel::globAccounts[userName]);
acntData.setPassword(newPwd);
......@@ -162,17 +149,15 @@ void IsdsWrapper::doIsdsAction(const QString &isdsAction,
{
qDebug("%s()", __func__);
/* Do sync via all accounts separately */
if (isdsAction == "syncAllAccounts") {
syncAllAccounts();
return;
}
/* If user is logged to isds then run isds action else run login phase */
if (isLoggedToIsds(userName)) {
if (isdsAction == "changePassword") {
emit runChangePasswordSig(userName);
} else if (isdsAction == "sendSms") {
emit runSendSmsSig(userName);
} else if (isdsAction == "downloadMessage") {
if (isdsAction == "downloadMessage") {
emit runDownloadMessageSig(userName);
} else if (isdsAction == "addNewAccount") {
emit runGetAccountInfoSig(userName);
......@@ -185,10 +170,9 @@ void IsdsWrapper::doIsdsAction(const QString &isdsAction,
} else if (isdsAction == "syncSingleAccountSent") {
emit runSyncSingleAccountSentSig(userName);
}
return;
} else {
doLoginAction(isdsAction, userName);
}
doLoginAction(isdsAction, userName);
}
void IsdsWrapper::downloadMessage(const QVariant &msgModelVariant,
......@@ -215,6 +199,7 @@ void IsdsWrapper::getAccountInfo(const QString &userName)
return;
}
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
return;
}
......@@ -240,6 +225,7 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
return;
}
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
return;
}
......@@ -252,7 +238,6 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
m_isdsSession.isdsCtxMap[userName], &m_netLayer, &m_dbWrapper, msgId);
task->setAutoDelete(true);
m_workPool.assignHi(task);
bool success = TaskDownloadDeliveryInfo::DL_SUCCESS == task->m_result;
delete task;
......@@ -314,30 +299,33 @@ void IsdsWrapper::returnInputDialogText(const QString &isdsAction,
}
}
bool IsdsWrapper::sendSMS(const QString &userName)
bool IsdsWrapper::sendSMS(const QString &userName, const QString &oldPwd)
{
qDebug("%s()", __func__);
bool success = false;
QString errTxt = tr("Wrong username");
if (userName.isEmpty()) {
QString errTxt = tr("Username or password missing");
if (userName.isEmpty() || oldPwd.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
tr("Error"), errTxt, tr("Internal error"));
return success;
}
/* Check if isds context exist. If not, create new context */
isLoggedToIsds(userName);
/* Set current password entered by user */
m_isdsSession.isdsCtxMap[userName].password = oldPwd;
/* Show send SMS dialogue. */
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("SMS code: %1").arg(userName),
tr("Account '%1' requires authentication with SMS code.").arg(m_isdsSession.isdsCtxMap[userName].account_name),
tr("Account '%1' requires SMS code for password changing.").
arg(m_isdsSession.isdsCtxMap[userName].account_name),
tr("Do you want to send SMS code now?"),
Dialogues::NO | Dialogues::YES, Dialogues::YES);
if (msgResponse == Dialogues::NO) {
return success;
}
if (!isLoggedToIsds(userName)) {
return success;
return false;
}
TaskSendSMS *taskSMS;
......@@ -558,6 +546,7 @@ void IsdsWrapper::downloadMessage(MessageListModel *messageModel,
return;
}
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
return;
}
......@@ -667,9 +656,12 @@ bool IsdsWrapper::loginToIsds(IsdsSession::IsdsContext &ctx)
/* Login was not succesfull */
if (!success) {
/* Password was wrong, clear it. It is OK? */
/*
* TODO
* The password should be deleted when login failed.
* But I dont know if passsword reset is OK...
*/
ctx.password = "";
/* Leave login proccess */
return success;
}
......@@ -758,6 +750,7 @@ void IsdsWrapper::syncSingleAccount(const QVariant &acntModelVariant,
return;
}
/* User must be logged to isds */
if (!isLoggedToIsds(userName)) {
return;
}
......
......@@ -134,10 +134,11 @@ public:
* @brief Sent SMS request.
*
* @param[in] userName Account username string.
* @param[in] oldPwd Current/old password string.
* @return true if SMS was sent.
*/
Q_INVOKABLE
bool sendSMS(const QString &userName);
bool sendSMS(const QString &userName, const QString &oldPwd);
/*!
* @brief Download message list of one account.
......@@ -244,13 +245,6 @@ signals:
*/
void downloadAccountInfoFinishedSig(QString userName);
/*!
* @brief Run change password isds action from QML.
*
* @param[in] userName Account user name string.
*/
void runChangePasswordSig(QString userName);
/*!
* @brief Run download mesasge isds action from QML.
*
......@@ -265,13 +259,6 @@ signals:
*/
void runGetAccountInfoSig(QString userName);
/*!
* @brief Run send sms action from QML.
*
* @param[in] userName Account user name string.
*/
void runSendSmsSig(QString userName);
/*!
* @brief Run sync all accounts action from QML.
*
......
......@@ -31,6 +31,7 @@ TaskChangePassword::TaskChangePassword(IsdsSession::IsdsContext &ctx,
NetLayer *netLayer, const QString &dbOTPType, const QString &oldPwd,
const QString &newPwd)
: m_result(DL_ERR),
m_isdsText(),
m_ctx(ctx),
m_netLayer(netLayer),
m_dbOTPType(dbOTPType),
......@@ -57,6 +58,7 @@ void TaskChangePassword::run(void)
logDebugLv1NL("%s", "-----------------------------------------------");
m_result = changePassword(m_ctx, m_netLayer, m_dbOTPType, m_oldPwd, m_newPwd);
m_isdsText = m_ctx.last_isds_msg;
/* ### Worker task end. ### */
......
......@@ -79,6 +79,7 @@ public:
const QString &newPwd);
enum Result m_result; /*!< Return state. */
QString m_isdsText; /*!< Return isds result text. */
private:
/*!
......
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