2023-08-02 17:35:35 +01:00
|
|
|
#include <QDebug>
|
2021-12-04 00:18:05 +00:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
2023-08-02 17:35:35 +01:00
|
|
|
#include <QNetworkRequest>
|
2021-12-04 00:18:05 +00:00
|
|
|
|
|
|
|
#include "AuthFlow.h"
|
|
|
|
#include "katabasis/Globals.h"
|
|
|
|
|
|
|
|
#include <Application.h>
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
AuthFlow::AuthFlow(AccountData* data, QObject* parent) : AccountTask(data, parent) {}
|
2021-12-04 00:18:05 +00:00
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void AuthFlow::succeed()
|
|
|
|
{
|
2021-12-04 00:18:05 +00:00
|
|
|
m_data->validity_ = Katabasis::Validity::Certain;
|
2023-08-02 17:35:35 +01:00
|
|
|
changeState(AccountTaskState::STATE_SUCCEEDED, tr("Finished all authentication steps"));
|
2021-12-04 00:18:05 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void AuthFlow::executeTask()
|
|
|
|
{
|
|
|
|
if (m_currentStep) {
|
2021-12-04 00:18:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
changeState(AccountTaskState::STATE_WORKING, tr("Initializing"));
|
|
|
|
nextStep();
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void AuthFlow::nextStep()
|
|
|
|
{
|
|
|
|
if (m_steps.size() == 0) {
|
2021-12-04 00:18:05 +00:00
|
|
|
// we got to the end without an incident... assume this is all.
|
|
|
|
m_currentStep.reset();
|
|
|
|
succeed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_currentStep = m_steps.front();
|
|
|
|
qDebug() << "AuthFlow:" << m_currentStep->describe();
|
|
|
|
m_steps.pop_front();
|
|
|
|
connect(m_currentStep.get(), &AuthStep::finished, this, &AuthFlow::stepFinished);
|
|
|
|
connect(m_currentStep.get(), &AuthStep::showVerificationUriAndCode, this, &AuthFlow::showVerificationUriAndCode);
|
|
|
|
connect(m_currentStep.get(), &AuthStep::hideVerificationUriAndCode, this, &AuthFlow::hideVerificationUriAndCode);
|
|
|
|
|
|
|
|
m_currentStep->perform();
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
QString AuthFlow::getStateMessage() const
|
|
|
|
{
|
|
|
|
switch (m_taskState) {
|
2021-12-04 00:18:05 +00:00
|
|
|
case AccountTaskState::STATE_WORKING: {
|
2023-08-02 17:35:35 +01:00
|
|
|
if (m_currentStep) {
|
2021-12-04 00:18:05 +00:00
|
|
|
return m_currentStep->describe();
|
2023-08-02 17:35:35 +01:00
|
|
|
} else {
|
2021-12-04 00:18:05 +00:00
|
|
|
return tr("Working...");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return AccountTask::getStateMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-02 17:35:35 +01:00
|
|
|
void AuthFlow::stepFinished(AccountTaskState resultingState, QString message)
|
|
|
|
{
|
|
|
|
if (changeState(resultingState, message)) {
|
2021-12-04 00:18:05 +00:00
|
|
|
nextStep();
|
|
|
|
}
|
|
|
|
}
|