Commit caec1a7e authored by Martin Straka's avatar Martin Straka
Browse files

Added support for async totp login method with QML input dialogue

parent 6a410c62
......@@ -52,8 +52,11 @@ Dialog {
rootpwd.placeholderText = placeholderText
rootpwd.echoMode = (hidePwd) ? TextInput.Password : TextInput.Normal
if (pwdType == "totp" || pwdType == "hotp") {
rootpwd.inputMethodHints = Qt.ImhDigitsOnly
rootpwd.inputMethodHints = Qt.ImhPreferNumbers
} else {
rootpwd.inputMethodHints = Qt.ImhNone
}
rootpwd.focus = true
root.open()
}
......
......@@ -241,7 +241,12 @@ void IsdsWrapper::doIsdsAction(const QString &isdsAction,
return;
}
/* Begin login phase to ISDS */
if (m_isdsSession.isdsCtxMap[userName].login_method ==
USERNAME_PWD_TOTP) {
doTotpLoginAction(isdsAction, userName);
return;
}
doLoginAction(isdsAction, userName);
}
......@@ -336,7 +341,7 @@ void IsdsWrapper::returnInputDialogText(const QString &isdsAction,
doLoginAction(isdsAction, userName);
} else if (pwdType == PWD_TOTP) {
m_isdsSession.isdsCtxMap[userName].pass_phrase = pwd;
runSecondTOTPLoginPhase(m_isdsSession.isdsCtxMap[userName],
runSmsLoginPhase(m_isdsSession.isdsCtxMap[userName],
isdsAction);
}
}
......@@ -486,18 +491,42 @@ void IsdsWrapper::doLoginAction(const QString &isdsAction,
{
qDebug("%s()", __func__);
/* Login phase is requried */
/* All login data are requried */
if (hasCtxAllLoginData(isdsAction, userName)) {
/* has all requried login data, login to databox */
if (loginToIsds(m_isdsSession.isdsCtxMap[userName], isdsAction)) {
if (loginToIsds(m_isdsSession.isdsCtxMap[userName])) {
/* login was successed so run isds action */
doIsdsAction(isdsAction, userName);
} else {
/* login was not successed, show error dialog */
m_isdsSession.isdsCtxMap[userName].password.clear();
m_isdsSession.isdsCtxMap[userName].pass_phrase.clear();
showLoginProblemDialog(userName,
m_isdsSession.isdsCtxMap[userName].last_isds_msg);
if (m_isdsSession.isdsCtxMap[userName].login_method == USERNAME_PWD_ONLY) {
m_isdsSession.isdsCtxMap[userName].password.clear();
} 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();
}
}
}
......@@ -624,8 +653,7 @@ bool IsdsWrapper::isLoggedToIsds(const QString &userName)
return false;
}
bool IsdsWrapper::loginToIsds(IsdsSession::IsdsContext &ctx,
const QString &isdsAction)
bool IsdsWrapper::loginToIsds(IsdsSession::IsdsContext &ctx)
{
qDebug("%s()", __func__);
......@@ -646,24 +674,20 @@ bool IsdsWrapper::loginToIsds(IsdsSession::IsdsContext &ctx,
/* Login was not succesfull */
if (!success) {
/* Password was wrong, clear it */
/* Password was wrong, clear it. It is OK? */
ctx.password = "";
/* Leave login proccess */
return success;
}
/* Run second login phase for TOTP login method */
if (ctx.login_method == USERNAME_PWD_TOTP) {
ctx.pass_phrase.clear();
runSecondTOTPLoginPhase(ctx, isdsAction);
} else {
if (ctx.login_method != USERNAME_PWD_TOTP) {
emit statusBarTextChanged(ctx.last_isds_msg, false, true);
}
return success;
}
bool IsdsWrapper::runSecondTOTPLoginPhase(IsdsSession::IsdsContext &ctx,
void IsdsWrapper::runSmsLoginPhase(IsdsSession::IsdsContext &ctx,
const QString &isdsAction)
{
qDebug("%s()", __func__);
......@@ -676,7 +700,7 @@ bool IsdsWrapper::runSecondTOTPLoginPhase(IsdsSession::IsdsContext &ctx,
tr("SMS code for '%1' required").arg(ctx.account_name),
tr("Enter SMS code"),
false);
return false;
return;
}
/* Start SMS login proccess */
......@@ -694,12 +718,13 @@ bool IsdsWrapper::runSecondTOTPLoginPhase(IsdsSession::IsdsContext &ctx,
tr("Correct SMS code for '%1' required").arg(ctx.account_name),
tr("Enter SMS code again"),
false);
return false;
return;
}
emit statusBarTextChanged(ctx.last_isds_msg, false, true);
return success;
/* login was successed so run isds action */
doIsdsAction(isdsAction, ctx.username);
}
void IsdsWrapper::showLoginProblemDialog(const QString &userName,
......@@ -724,7 +749,7 @@ void IsdsWrapper::syncAllAccounts(void)
emit runSyncOneAccountSig(userName);
continue;
}
doLoginAction("syncOneAccount", userName);
doIsdsAction("syncOneAccount", userName);
}
}
......
......@@ -329,6 +329,15 @@ 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.
*
......@@ -373,17 +382,15 @@ private:
* @param[in,out] ctx Account isds context structure.
* @return true if login success.
*/
bool loginToIsds(IsdsSession::IsdsContext &ctx,
const QString &isdsAction);
bool loginToIsds(IsdsSession::IsdsContext &ctx);
/*!
* @brief Run second TOTP login phase with SMS code.
*
* @param[in] ctx Account isds context structure.
* @param[in] isdsAction Isds action identificator.
* @return true if login success.
*/
bool runSecondTOTPLoginPhase(IsdsSession::IsdsContext &ctx,
void runSmsLoginPhase(IsdsSession::IsdsContext &ctx,
const QString &isdsAction);
/*!
......
Supports Markdown
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