Commit fdab54bf authored by Martin Straka's avatar Martin Straka

Reenter password during login procedure (issue #47)

parent e7c55949
......@@ -137,7 +137,7 @@ ApplicationWindow {
Connections {
target: isds
onStatusBarTextChanged: {
statusBar.visible = true
statusBar.visible = isVisible
statusBarText.text = txt
busyuIndicator.running = busy
timerId.running = !busy
......
......@@ -215,7 +215,7 @@ int main(int argc, char *argv[])
if (!globSet.lastUpdateStr().isEmpty() && globSet.pinCode.isEmpty()) {
emit isds.statusBarTextChanged(
QObject::tr("Last synchronisation: %1").
arg(globSet.lastUpdateStr()), false);
arg(globSet.lastUpdateStr()), false, true);
}
} else {
emit isds.showErrorMessageBox(QObject::tr("Security problem"),
......
......@@ -24,7 +24,6 @@
#include <QDebug>
#include <QFileInfo>
#include <QMessageBox>
#include "src/common.h"
#include "src/net/isds_const.h"
......@@ -64,7 +63,6 @@ bool IsdsSession::createIsdsCtx(const QString &userName, QString &errText)
/* new context */
} else {
IsdsContext isdsCtx;
bool ok;
isdsCtx.username = userName;
isdsCtx.account_name = acntData.accountName();
isdsCtx.login_method = acntData.loginMethod();
......@@ -73,18 +71,7 @@ bool IsdsSession::createIsdsCtx(const QString &userName, QString &errText)
isdsCtx.timeout = ISDS_TIMEOUT;
isdsCtx.url = getUrlFromLoginMethod(
acntData.loginMethod(), acntData.isTestAccount());
if (!acntData.password().isEmpty()) {
isdsCtx.password = acntData.password();
} else {
QString text = PasteInputDialogue::getText(0,
tr("Password: %1").arg(userName),
tr("Enter password for account\n'%1'").arg(acntData.accountName()),
QLineEdit::Password, NULL, &ok, Qt::Dialog);
if (ok && !text.isEmpty()) {
isdsCtx.password = text;
} else return false;
}
isdsCtx.password = acntData.password();
if (acntData.loginMethod() == USERNAME_PWD_CERT) {
if (!setCertificateData(userName,
......@@ -93,18 +80,6 @@ bool IsdsSession::createIsdsCtx(const QString &userName, QString &errText)
isdsCtx.last_isds_msg = errText;
return false;
}
} else if (acntData.loginMethod() == USERNAME_PWD_TOTP) {
/* show SMS request dialog */
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle(tr("SMS code: %1").arg(userName));
msgBox.setText(tr("Account '%1' requires authentication with SMS code.").arg(userName));
msgBox.setInformativeText("Do you want to send SMS code now?");
msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::Yes);
if (QMessageBox::No == msgBox.exec()) {
return false;
}
}
isdsCtxMap.insert(userName, isdsCtx);
}
......
......@@ -56,7 +56,7 @@ void IsdsWrapper::downloadMessage(const QString &userName, int mesasgeType,
}
emit statusBarTextChanged(tr("Downloading message %1").
arg(QString::number(msgId)), true);
arg(QString::number(msgId)), true, true);
if (!isLoggedToIsds(userName, errTxt)) {
showLoginProblemDialog(userName, errTxt);
......@@ -92,7 +92,7 @@ void IsdsWrapper::downloadMessage(const QString &userName, int mesasgeType,
emit messageDownloadFinish(userName, msgId);
emit statusBarTextChanged(tr("Message %1 has been downloaded").arg(msgId),
false);
false, true);
}
......@@ -113,7 +113,7 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
}
emit statusBarTextChanged(tr("Downloading delivery info %1").
arg(QString::number(msgId)), true);
arg(QString::number(msgId)), true, true);
if (!isLoggedToIsds(userName, errTxt)) {
showLoginProblemDialog(userName, errTxt);
......@@ -128,7 +128,8 @@ void IsdsWrapper::getDeliveryInfo(const QString &userName, qint64 msgId)
false);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false);
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false,
true);
}
}
......@@ -159,12 +160,18 @@ void IsdsWrapper::syncOneAccount(const QString &userName)
qDebug("%s()", __func__);
if (syncSingleAccountSent(userName)) {
/* Download sent only when received successfully downloaded. */
/* Download received only when sent successfully downloaded. */
syncSingleAccountReceived(userName);
}
}
/* ========================================================================= */
/*
* Slot: Synchronize recevied messages.
*/
bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
/* ========================================================================= */
{
if (userName.isEmpty()) {
showErrorMessageBox(tr("Error"), tr("Empty user name"),
......@@ -173,7 +180,7 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
}
emit statusBarTextChanged(tr("%1: downloading received").arg(userName),
true);
true, true);
QString errText;
if (!isLoggedToIsds(userName, errText)) {
......@@ -188,13 +195,14 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
m_isdsSession.isdsCtxMap[userName],
globSet.downloadOnlyNewMsgs, receivedMsgIds)) {
showErrorMessageBox(tr("%1: received messages").arg(userName),
tr("Failed to download list of received messages for user name '%1'.")
.arg(userName),
tr("Failed to download list of received messages "
"for user name '%1'.").arg(userName),
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
true);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false);
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
false, true);
}
globSet.setLastUpdateToNow();
......@@ -210,7 +218,13 @@ bool IsdsWrapper::syncSingleAccountReceived(const QString &userName)
return true;
}
/* ========================================================================= */
/*
* Slot: Synchronize sent messages.
*/
bool IsdsWrapper::syncSingleAccountSent(const QString &userName)
/* ========================================================================= */
{
if (userName.isEmpty()) {
showErrorMessageBox(tr("Error"), tr("Empty user name"),
......@@ -219,7 +233,7 @@ bool IsdsWrapper::syncSingleAccountSent(const QString &userName)
}
emit statusBarTextChanged(tr("%1: downloading sent").arg(userName),
true);
true, true);
QString errText;
if (!isLoggedToIsds(userName, errText)) {
......@@ -233,12 +247,14 @@ bool IsdsWrapper::syncSingleAccountSent(const QString &userName)
m_isdsSession.isdsCtxMap[userName],
globSet.downloadOnlyNewMsgs, sentMsgIds)) {
showErrorMessageBox(tr("%1: sent messages").arg(userName),
tr("Failed to download list of sent messages for user name %1.").arg(userName),
tr("Failed to download list of sent messages "
"for user name %1.").arg(userName),
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
true);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false);
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
false, true);
}
if (globSet.downloadCompleteMsgs) {
......@@ -268,7 +284,7 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool firstLogin)
}
emit statusBarTextChanged(tr("Getting account info %1").
arg(userName), true);
arg(userName), true, true);
if (!isLoggedToIsds(userName, errTxt)) {
if (firstLogin) {
......@@ -283,13 +299,13 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool firstLogin)
m_xmlLayer.isdsGetOwnerInfoFromLogin(m_isdsSession.isdsCtxMap[userName]);
emit statusBarTextChanged(tr("Getting user info %1").
arg(userName), true);
arg(userName), true, true);
success = success &&
m_xmlLayer.isdsGetUserInfoFromLogin(m_isdsSession.isdsCtxMap[userName]);
emit statusBarTextChanged(tr("Getting password info %1").
arg(userName), true);
arg(userName), true, true);
success = success &&
m_xmlLayer.isdsGetPasswordExpiration(m_isdsSession.isdsCtxMap[userName]);
......@@ -301,7 +317,8 @@ bool IsdsWrapper::getAccountInfo(const QString &userName, bool firstLogin)
true);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false);
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
false, true);
}
return true;
......@@ -396,7 +413,7 @@ void IsdsWrapper::changePassword(const QString &userName,
}
emit statusBarTextChanged(tr("Password changing: %1").arg(userName),
true);
true, true);
if (!m_xmlLayer.isdsChangePassword(m_isdsSession.isdsCtxMap[userName],
newPwd)) {
......@@ -406,7 +423,8 @@ void IsdsWrapper::changePassword(const QString &userName,
true);
} else {
emit statusBarTextChanged(
m_isdsSession.isdsCtxMap[userName].last_isds_msg, false);
m_isdsSession.isdsCtxMap[userName].last_isds_msg,
false, true);
m_isdsSession.removeIsdsCtx(userName);
......@@ -552,7 +570,6 @@ void IsdsWrapper::showErrorMessageBox(const QString &title,
const QString &text, const QString &informatinText, bool isError)
/* ========================================================================= */
{
emit statusBarTextChanged("", false);
QMessageBox msgBox;
msgBox.setWindowTitle(title);
if (isError) {
......@@ -576,6 +593,8 @@ void IsdsWrapper::showLoginProblemDialog(const QString &userName,
const QString &errTxt)
/* ========================================================================= */
{
emit statusBarTextChanged("", false, false);
if (!errTxt.isEmpty()) {
showErrorMessageBox(tr("Login problem: %1").arg(userName),
tr("Error while logging in with username '%1'.").arg(userName),
......@@ -594,6 +613,8 @@ void IsdsWrapper::showFirstLoginProblemDialog(const QString &userName,
const QString &errTxt)
/* ========================================================================= */
{
emit statusBarTextChanged("", false, false);
if (!errTxt.isEmpty()) {
showErrorMessageBox(tr("Problem adding account: %1").arg(userName),
tr("New account could not be created because an error occurred "
......
......@@ -128,11 +128,13 @@ signals:
/*!
* @brief Set new statusbar text and active busy indicator to QML.
*
* @param[in] txt - text message for statusbar.
* @param[in] busy - true means the statusbar busy indicator is active
* and shown, false = disabled and hidden
* @param[in] txt - text message for statusbar.
* @param[in] busy - true means the statusbar busy indicator is
* active and shown, false = disabled and hidden
* @param[in] isVisible - true means the statusbar is visible,
* false = hidden
*/
void statusBarTextChanged(QString txt, bool busy);
void statusBarTextChanged(QString txt, bool busy, bool isVisible);
public slots:
......
......@@ -24,6 +24,7 @@
#include <QDebug>
#include <QEventLoop>
#include <QMessageBox>
#include <QNetworkAccessManager>
#include <QNetworkCookie>
#include <QNetworkCookieJar>
......@@ -129,6 +130,9 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx,
{
QNetworkRequest request;
QByteArray authorization;
bool ok;
QString pwd;
bool success = false;
/* Fill some header items of request */
fillRequestHeader(request);
......@@ -137,28 +141,58 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx,
request.setUrl(QUrl(url));
request.setRawHeader("Host", ctx.url.host().toUtf8());
if (ctx.password.isEmpty()) {
do {
pwd = PasteInputDialogue::getText(0,
tr("Password: %1").arg(ctx.username),
tr("Enter password for account\n'%1'").arg(ctx.account_name),
QLineEdit::Password, NULL, &ok, Qt::Dialog);
if (!ok) {
ctx.password = "";
ctx.last_isds_msg = "";
return success;
}
} while (ok && pwd.isEmpty());
ctx.password = pwd;
}
/* Create authorization string for header of request */
if (ctx.login_method == USERNAME_PWD_HOTP) {
bool ok;
QString code;
do {
code = PasteInputDialogue::getText(0,
pwd = PasteInputDialogue::getText(0,
tr("Security code: %1").arg(ctx.username),
tr("Enter security code for account\n'%1'").arg(ctx.account_name),
QLineEdit::Normal, NULL, &ok, Qt::Dialog,
Qt::ImhDigitsOnly);
if (!ok) {
ctx.last_isds_msg = "";
return false;
return success;
}
} while (ok && code.isEmpty());
} while (ok && pwd.isEmpty());
ctx.pass_phrase = code;
ctx.pass_phrase = pwd;
authorization.append(ctx.username + ":" +
ctx.password + ctx.pass_phrase) ;
} else if (ctx.login_method == USERNAME_PWD_TOTP) {
/* show SMS dialog */
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle(tr("SMS code: %1").arg(ctx.username));
msgBox.setText(tr("Account '%1' requires authentication with SMS code.").arg(ctx.account_name));
msgBox.setInformativeText("Do you want to send SMS code now?");
msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
msgBox.setDefaultButton(QMessageBox::Yes);
if (QMessageBox::No == msgBox.exec()) {
return success;
}
authorization.append(ctx.username + ":" + ctx.password);
} else {
authorization.append(ctx.username + ":" + ctx.password);
}
authorization = authorization.toBase64();
......@@ -175,7 +209,12 @@ bool NetLayer::createLoginRequest(IsdsContext &ctx,
request.setRawHeader("Content-Length",
QString::number(dataIn.length()).toUtf8());
bool success = sendRequest(ctx, request, dataIn, xmlDataOut);
success = sendRequest(ctx, request, dataIn, xmlDataOut);
if (!success) {
ctx.password = "";
return success;
}
/* Run second phase of HOTP/TOTP login if first phase is success*/
if (ctx.login_method == USERNAME_PWD_TOTP && success) {
......
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