Removed AccountTask
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
3336f8107c
commit
e285a85fe8
@ -209,11 +209,8 @@ set(MINECRAFT_SOURCES
|
|||||||
minecraft/auth/AccountData.h
|
minecraft/auth/AccountData.h
|
||||||
minecraft/auth/AccountList.cpp
|
minecraft/auth/AccountList.cpp
|
||||||
minecraft/auth/AccountList.h
|
minecraft/auth/AccountList.h
|
||||||
minecraft/auth/AccountTask.cpp
|
|
||||||
minecraft/auth/AccountTask.h
|
|
||||||
minecraft/auth/AuthSession.cpp
|
minecraft/auth/AuthSession.cpp
|
||||||
minecraft/auth/AuthSession.h
|
minecraft/auth/AuthSession.h
|
||||||
minecraft/auth/AuthStep.cpp
|
|
||||||
minecraft/auth/AuthStep.h
|
minecraft/auth/AuthStep.h
|
||||||
minecraft/auth/MinecraftAccount.cpp
|
minecraft/auth/MinecraftAccount.cpp
|
||||||
minecraft/auth/MinecraftAccount.h
|
minecraft/auth/MinecraftAccount.h
|
||||||
|
@ -57,7 +57,6 @@
|
|||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
#include "JavaCommon.h"
|
#include "JavaCommon.h"
|
||||||
#include "launch/steps/TextPrint.h"
|
#include "launch/steps/TextPrint.h"
|
||||||
#include "minecraft/auth/AccountTask.h"
|
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
LaunchController::LaunchController(QObject* parent) : Task(parent) {}
|
LaunchController::LaunchController(QObject* parent) : Task(parent) {}
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
|
|
||||||
#include "AccountList.h"
|
#include "AccountList.h"
|
||||||
#include "AccountData.h"
|
#include "AccountData.h"
|
||||||
#include "AccountTask.h"
|
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "MinecraftAccount.h"
|
#include "MinecraftAccount.h"
|
||||||
|
#include "minecraft/auth/flows/AuthFlow.h"
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@ -144,7 +145,7 @@ class AccountList : public QAbstractListModel {
|
|||||||
QList<QString> m_refreshQueue;
|
QList<QString> m_refreshQueue;
|
||||||
QTimer* m_refreshTimer;
|
QTimer* m_refreshTimer;
|
||||||
QTimer* m_nextTimer;
|
QTimer* m_nextTimer;
|
||||||
shared_qobject_ptr<AccountTask> m_currentTask;
|
shared_qobject_ptr<AuthFlow> m_currentTask;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Called whenever the list changes.
|
* Called whenever the list changes.
|
||||||
|
@ -1,134 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
/*
|
|
||||||
* Prism Launcher - Minecraft Launcher
|
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This file incorporates work covered by the following copyright and
|
|
||||||
* permission notice:
|
|
||||||
*
|
|
||||||
* Copyright 2013-2021 MultiMC Contributors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "AccountTask.h"
|
|
||||||
#include "MinecraftAccount.h"
|
|
||||||
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
AccountTask::AccountTask(AccountData* data, QObject* parent) : Task(parent), m_data(data)
|
|
||||||
{
|
|
||||||
changeState(AccountTaskState::STATE_CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString AccountTask::getStateMessage() const
|
|
||||||
{
|
|
||||||
switch (m_taskState) {
|
|
||||||
case AccountTaskState::STATE_CREATED:
|
|
||||||
return "Waiting...";
|
|
||||||
case AccountTaskState::STATE_WORKING:
|
|
||||||
return tr("Sending request to auth servers...");
|
|
||||||
case AccountTaskState::STATE_SUCCEEDED:
|
|
||||||
return tr("Authentication task succeeded.");
|
|
||||||
case AccountTaskState::STATE_OFFLINE:
|
|
||||||
return tr("Failed to contact the authentication server.");
|
|
||||||
case AccountTaskState::STATE_DISABLED:
|
|
||||||
return tr("Client ID has changed. New session needs to be created.");
|
|
||||||
case AccountTaskState::STATE_FAILED_SOFT:
|
|
||||||
return tr("Encountered an error during authentication.");
|
|
||||||
case AccountTaskState::STATE_FAILED_HARD:
|
|
||||||
return tr("Failed to authenticate. The session has expired.");
|
|
||||||
case AccountTaskState::STATE_FAILED_GONE:
|
|
||||||
return tr("Failed to authenticate. The account no longer exists.");
|
|
||||||
default:
|
|
||||||
return tr("...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AccountTask::changeState(AccountTaskState newState, QString reason)
|
|
||||||
{
|
|
||||||
m_taskState = newState;
|
|
||||||
// FIXME: virtual method invoked in constructor.
|
|
||||||
// We want that behavior, but maybe make it less weird?
|
|
||||||
setStatus(getStateMessage());
|
|
||||||
switch (newState) {
|
|
||||||
case AccountTaskState::STATE_CREATED: {
|
|
||||||
m_data->errorString.clear();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case AccountTaskState::STATE_WORKING: {
|
|
||||||
m_data->accountState = AccountState::Working;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
case AccountTaskState::STATE_SUCCEEDED: {
|
|
||||||
m_data->accountState = AccountState::Online;
|
|
||||||
emitSucceeded();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case AccountTaskState::STATE_OFFLINE: {
|
|
||||||
m_data->errorString = reason;
|
|
||||||
m_data->accountState = AccountState::Offline;
|
|
||||||
emitFailed(reason);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case AccountTaskState::STATE_DISABLED: {
|
|
||||||
m_data->errorString = reason;
|
|
||||||
m_data->accountState = AccountState::Disabled;
|
|
||||||
emitFailed(reason);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case AccountTaskState::STATE_FAILED_SOFT: {
|
|
||||||
m_data->errorString = reason;
|
|
||||||
m_data->accountState = AccountState::Errored;
|
|
||||||
emitFailed(reason);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case AccountTaskState::STATE_FAILED_HARD: {
|
|
||||||
m_data->errorString = reason;
|
|
||||||
m_data->accountState = AccountState::Expired;
|
|
||||||
emitFailed(reason);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case AccountTaskState::STATE_FAILED_GONE: {
|
|
||||||
m_data->errorString = reason;
|
|
||||||
m_data->accountState = AccountState::Gone;
|
|
||||||
emitFailed(reason);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
QString error = tr("Unknown account task state: %1").arg(int(newState));
|
|
||||||
m_data->accountState = AccountState::Errored;
|
|
||||||
emitFailed(error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
/*
|
|
||||||
* Prism Launcher - Minecraft Launcher
|
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This file incorporates work covered by the following copyright and
|
|
||||||
* permission notice:
|
|
||||||
*
|
|
||||||
* Copyright 2013-2021 MultiMC Contributors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <tasks/Task.h>
|
|
||||||
|
|
||||||
#include <qsslerror.h>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QString>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "MinecraftAccount.h"
|
|
||||||
|
|
||||||
class QNetworkReply;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enum for describing the state of the current task.
|
|
||||||
* Used by the getStateMessage function to determine what the status message should be.
|
|
||||||
*/
|
|
||||||
enum class AccountTaskState {
|
|
||||||
STATE_CREATED,
|
|
||||||
STATE_WORKING,
|
|
||||||
STATE_SUCCEEDED,
|
|
||||||
STATE_DISABLED, //!< MSA Client ID has changed. Tell user to reloginn
|
|
||||||
STATE_FAILED_SOFT, //!< soft failure. authentication went through partially
|
|
||||||
STATE_FAILED_HARD, //!< hard failure. main tokens are invalid
|
|
||||||
STATE_FAILED_GONE, //!< hard failure. main tokens are invalid, and the account no longer exists
|
|
||||||
STATE_OFFLINE //!< soft failure. authentication failed in the first step in a 'soft' way
|
|
||||||
};
|
|
||||||
|
|
||||||
class AccountTask : public Task {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit AccountTask(AccountData* data, QObject* parent = 0);
|
|
||||||
virtual ~AccountTask(){};
|
|
||||||
|
|
||||||
AccountTaskState m_taskState = AccountTaskState::STATE_CREATED;
|
|
||||||
|
|
||||||
AccountTaskState taskState() { return m_taskState; }
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void showVerificationUriAndCode(const QUrl& uri, const QString& code, int expiresIn);
|
|
||||||
void hideVerificationUriAndCode();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* Returns the state message for the given state.
|
|
||||||
* Used to set the status message for the task.
|
|
||||||
* Should be overridden by subclasses that want to change messages for a given state.
|
|
||||||
*/
|
|
||||||
virtual QString getStateMessage() const;
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
// NOTE: true -> non-terminal state, false -> terminal state
|
|
||||||
bool changeState(AccountTaskState newState, QString reason = QString());
|
|
||||||
|
|
||||||
protected:
|
|
||||||
AccountData* m_data = nullptr;
|
|
||||||
};
|
|
@ -1,3 +0,0 @@
|
|||||||
#include "AuthStep.h"
|
|
||||||
|
|
||||||
AuthStep::AuthStep(AccountData* data) : QObject(nullptr), m_data(data) {}
|
|
@ -3,18 +3,31 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "AccountTask.h"
|
|
||||||
#include "QObjectPtr.h"
|
#include "QObjectPtr.h"
|
||||||
#include "minecraft/auth/AccountData.h"
|
#include "minecraft/auth/AccountData.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum for describing the state of the current task.
|
||||||
|
* Used by the getStateMessage function to determine what the status message should be.
|
||||||
|
*/
|
||||||
|
enum class AccountTaskState {
|
||||||
|
STATE_CREATED,
|
||||||
|
STATE_WORKING,
|
||||||
|
STATE_SUCCEEDED,
|
||||||
|
STATE_DISABLED, //!< MSA Client ID has changed. Tell user to reloginn
|
||||||
|
STATE_FAILED_SOFT, //!< soft failure. authentication went through partially
|
||||||
|
STATE_FAILED_HARD, //!< hard failure. main tokens are invalid
|
||||||
|
STATE_FAILED_GONE, //!< hard failure. main tokens are invalid, and the account no longer exists
|
||||||
|
STATE_OFFLINE //!< soft failure. authentication failed in the first step in a 'soft' way
|
||||||
|
};
|
||||||
|
|
||||||
class AuthStep : public QObject {
|
class AuthStep : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Ptr = shared_qobject_ptr<AuthStep>;
|
using Ptr = shared_qobject_ptr<AuthStep>;
|
||||||
|
|
||||||
public:
|
explicit AuthStep(AccountData* data) : QObject(nullptr), m_data(data){};
|
||||||
explicit AuthStep(AccountData* data);
|
|
||||||
virtual ~AuthStep() noexcept = default;
|
virtual ~AuthStep() noexcept = default;
|
||||||
|
|
||||||
virtual QString describe() = 0;
|
virtual QString describe() = 0;
|
||||||
|
@ -53,6 +53,8 @@
|
|||||||
#include "flows/MSA.h"
|
#include "flows/MSA.h"
|
||||||
#include "flows/Offline.h"
|
#include "flows/Offline.h"
|
||||||
#include "minecraft/auth/AccountData.h"
|
#include "minecraft/auth/AccountData.h"
|
||||||
|
#include "minecraft/auth/flows/AuthFlow.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent)
|
MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
@ -120,7 +122,7 @@ QPixmap MinecraftAccount::getFace() const
|
|||||||
return skin.scaled(64, 64, Qt::KeepAspectRatio);
|
return skin.scaled(64, 64, Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<AccountTask> MinecraftAccount::loginMSA()
|
shared_qobject_ptr<AuthFlow> MinecraftAccount::loginMSA()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_currentTask.get() == nullptr);
|
Q_ASSERT(m_currentTask.get() == nullptr);
|
||||||
|
|
||||||
@ -132,7 +134,7 @@ shared_qobject_ptr<AccountTask> MinecraftAccount::loginMSA()
|
|||||||
return m_currentTask;
|
return m_currentTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<AccountTask> MinecraftAccount::loginOffline()
|
shared_qobject_ptr<AuthFlow> MinecraftAccount::loginOffline()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_currentTask.get() == nullptr);
|
Q_ASSERT(m_currentTask.get() == nullptr);
|
||||||
|
|
||||||
@ -144,7 +146,7 @@ shared_qobject_ptr<AccountTask> MinecraftAccount::loginOffline()
|
|||||||
return m_currentTask;
|
return m_currentTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<AccountTask> MinecraftAccount::refresh()
|
shared_qobject_ptr<AuthFlow> MinecraftAccount::refresh()
|
||||||
{
|
{
|
||||||
if (m_currentTask) {
|
if (m_currentTask) {
|
||||||
return m_currentTask;
|
return m_currentTask;
|
||||||
@ -163,7 +165,7 @@ shared_qobject_ptr<AccountTask> MinecraftAccount::refresh()
|
|||||||
return m_currentTask;
|
return m_currentTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_qobject_ptr<AccountTask> MinecraftAccount::currentTask()
|
shared_qobject_ptr<AuthFlow> MinecraftAccount::currentTask()
|
||||||
{
|
{
|
||||||
return m_currentTask;
|
return m_currentTask;
|
||||||
}
|
}
|
||||||
|
@ -43,15 +43,13 @@
|
|||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "AccountData.h"
|
#include "AccountData.h"
|
||||||
#include "AuthSession.h"
|
#include "AuthSession.h"
|
||||||
#include "QObjectPtr.h"
|
#include "QObjectPtr.h"
|
||||||
#include "Usable.h"
|
#include "Usable.h"
|
||||||
|
#include "minecraft/auth/flows/AuthFlow.h"
|
||||||
|
|
||||||
class Task;
|
class Task;
|
||||||
class AccountTask;
|
|
||||||
class MinecraftAccount;
|
class MinecraftAccount;
|
||||||
|
|
||||||
using MinecraftAccountPtr = shared_qobject_ptr<MinecraftAccount>;
|
using MinecraftAccountPtr = shared_qobject_ptr<MinecraftAccount>;
|
||||||
@ -97,13 +95,13 @@ class MinecraftAccount : public QObject, public Usable {
|
|||||||
QJsonObject saveToJson() const;
|
QJsonObject saveToJson() const;
|
||||||
|
|
||||||
public: /* manipulation */
|
public: /* manipulation */
|
||||||
shared_qobject_ptr<AccountTask> loginMSA();
|
shared_qobject_ptr<AuthFlow> loginMSA();
|
||||||
|
|
||||||
shared_qobject_ptr<AccountTask> loginOffline();
|
shared_qobject_ptr<AuthFlow> loginOffline();
|
||||||
|
|
||||||
shared_qobject_ptr<AccountTask> refresh();
|
shared_qobject_ptr<AuthFlow> refresh();
|
||||||
|
|
||||||
shared_qobject_ptr<AccountTask> currentTask();
|
shared_qobject_ptr<AuthFlow> currentTask();
|
||||||
|
|
||||||
public: /* queries */
|
public: /* queries */
|
||||||
QString internalId() const { return data.internalId; }
|
QString internalId() const { return data.internalId; }
|
||||||
@ -166,7 +164,7 @@ class MinecraftAccount : public QObject, public Usable {
|
|||||||
AccountData data;
|
AccountData data;
|
||||||
|
|
||||||
// current task we are executing here
|
// current task we are executing here
|
||||||
shared_qobject_ptr<AccountTask> m_currentTask;
|
shared_qobject_ptr<AuthFlow> m_currentTask;
|
||||||
|
|
||||||
protected: /* methods */
|
protected: /* methods */
|
||||||
void incrementUses() override;
|
void incrementUses() override;
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
|
||||||
#include "AuthFlow.h"
|
#include "AuthFlow.h"
|
||||||
#include "katabasis/Globals.h"
|
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
|
||||||
AuthFlow::AuthFlow(AccountData* data, QObject* parent) : AccountTask(data, parent) {}
|
AuthFlow::AuthFlow(AccountData* data, QObject* parent) : Task(parent), m_data(data)
|
||||||
|
{
|
||||||
|
changeState(AccountTaskState::STATE_CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
void AuthFlow::succeed()
|
void AuthFlow::succeed()
|
||||||
{
|
{
|
||||||
@ -46,16 +48,26 @@ void AuthFlow::nextStep()
|
|||||||
QString AuthFlow::getStateMessage() const
|
QString AuthFlow::getStateMessage() const
|
||||||
{
|
{
|
||||||
switch (m_taskState) {
|
switch (m_taskState) {
|
||||||
case AccountTaskState::STATE_WORKING: {
|
case AccountTaskState::STATE_CREATED:
|
||||||
if (m_currentStep) {
|
return "Waiting...";
|
||||||
|
case AccountTaskState::STATE_WORKING:
|
||||||
|
if (m_currentStep)
|
||||||
return m_currentStep->describe();
|
return m_currentStep->describe();
|
||||||
} else {
|
|
||||||
return tr("Working...");
|
return tr("Working...");
|
||||||
}
|
case AccountTaskState::STATE_SUCCEEDED:
|
||||||
}
|
return tr("Authentication task succeeded.");
|
||||||
default: {
|
case AccountTaskState::STATE_OFFLINE:
|
||||||
return AccountTask::getStateMessage();
|
return tr("Failed to contact the authentication server.");
|
||||||
}
|
case AccountTaskState::STATE_DISABLED:
|
||||||
|
return tr("Client ID has changed. New session needs to be created.");
|
||||||
|
case AccountTaskState::STATE_FAILED_SOFT:
|
||||||
|
return tr("Encountered an error during authentication.");
|
||||||
|
case AccountTaskState::STATE_FAILED_HARD:
|
||||||
|
return tr("Failed to authenticate. The session has expired.");
|
||||||
|
case AccountTaskState::STATE_FAILED_GONE:
|
||||||
|
return tr("Failed to authenticate. The account no longer exists.");
|
||||||
|
default:
|
||||||
|
return tr("...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,3 +77,62 @@ void AuthFlow::stepFinished(AccountTaskState resultingState, QString message)
|
|||||||
nextStep();
|
nextStep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AuthFlow::changeState(AccountTaskState newState, QString reason)
|
||||||
|
{
|
||||||
|
m_taskState = newState;
|
||||||
|
// FIXME: virtual method invoked in constructor.
|
||||||
|
// We want that behavior, but maybe make it less weird?
|
||||||
|
setStatus(getStateMessage());
|
||||||
|
switch (newState) {
|
||||||
|
case AccountTaskState::STATE_CREATED: {
|
||||||
|
m_data->errorString.clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case AccountTaskState::STATE_WORKING: {
|
||||||
|
m_data->accountState = AccountState::Working;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case AccountTaskState::STATE_SUCCEEDED: {
|
||||||
|
m_data->accountState = AccountState::Online;
|
||||||
|
emitSucceeded();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case AccountTaskState::STATE_OFFLINE: {
|
||||||
|
m_data->errorString = reason;
|
||||||
|
m_data->accountState = AccountState::Offline;
|
||||||
|
emitFailed(reason);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case AccountTaskState::STATE_DISABLED: {
|
||||||
|
m_data->errorString = reason;
|
||||||
|
m_data->accountState = AccountState::Disabled;
|
||||||
|
emitFailed(reason);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case AccountTaskState::STATE_FAILED_SOFT: {
|
||||||
|
m_data->errorString = reason;
|
||||||
|
m_data->accountState = AccountState::Errored;
|
||||||
|
emitFailed(reason);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case AccountTaskState::STATE_FAILED_HARD: {
|
||||||
|
m_data->errorString = reason;
|
||||||
|
m_data->accountState = AccountState::Expired;
|
||||||
|
emitFailed(reason);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case AccountTaskState::STATE_FAILED_GONE: {
|
||||||
|
m_data->errorString = reason;
|
||||||
|
m_data->accountState = AccountState::Gone;
|
||||||
|
emitFailed(reason);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
QString error = tr("Unknown account task state: %1").arg(int(newState));
|
||||||
|
m_data->accountState = AccountState::Errored;
|
||||||
|
emitFailed(error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,32 +10,48 @@
|
|||||||
#include <katabasis/DeviceFlow.h>
|
#include <katabasis/DeviceFlow.h>
|
||||||
|
|
||||||
#include "minecraft/auth/AccountData.h"
|
#include "minecraft/auth/AccountData.h"
|
||||||
#include "minecraft/auth/AccountTask.h"
|
|
||||||
#include "minecraft/auth/AuthStep.h"
|
#include "minecraft/auth/AuthStep.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
class AuthFlow : public AccountTask {
|
class AuthFlow : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AuthFlow(AccountData* data, QObject* parent = 0);
|
explicit AuthFlow(AccountData* data, QObject* parent = 0);
|
||||||
|
virtual ~AuthFlow() = default;
|
||||||
|
|
||||||
Katabasis::Validity validity() { return m_data->validity_; };
|
Katabasis::Validity validity() { return m_data->validity_; };
|
||||||
|
|
||||||
QString getStateMessage() const override;
|
|
||||||
|
|
||||||
void executeTask() override;
|
void executeTask() override;
|
||||||
|
|
||||||
|
AccountTaskState taskState() { return m_taskState; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void showVerificationUriAndCode(const QUrl& uri, const QString& code, int expiresIn);
|
||||||
|
void hideVerificationUriAndCode();
|
||||||
|
|
||||||
void activityChanged(Katabasis::Activity activity);
|
void activityChanged(Katabasis::Activity activity);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* Returns the state message for the given state.
|
||||||
|
* Used to set the status message for the task.
|
||||||
|
* Should be overridden by subclasses that want to change messages for a given state.
|
||||||
|
*/
|
||||||
|
virtual QString getStateMessage() const;
|
||||||
|
void succeed();
|
||||||
|
void nextStep();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
// NOTE: true -> non-terminal state, false -> terminal state
|
||||||
|
bool changeState(AccountTaskState newState, QString reason = QString());
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void stepFinished(AccountTaskState resultingState, QString message);
|
void stepFinished(AccountTaskState resultingState, QString message);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void succeed();
|
AccountTaskState m_taskState = AccountTaskState::STATE_CREATED;
|
||||||
void nextStep();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QList<AuthStep::Ptr> m_steps;
|
QList<AuthStep::Ptr> m_steps;
|
||||||
AuthStep::Ptr m_currentStep;
|
AuthStep::Ptr m_currentStep;
|
||||||
|
AccountData* m_data = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "minecraft/auth/AccountTask.h"
|
|
||||||
#include "minecraft/auth/Parsers.h"
|
#include "minecraft/auth/Parsers.h"
|
||||||
#include "net/NetUtils.h"
|
#include "net/NetUtils.h"
|
||||||
#include "net/StaticHeaderProxy.h"
|
#include "net/StaticHeaderProxy.h"
|
||||||
|
@ -170,6 +170,8 @@ void NetRequest::downloadError(QNetworkReply::NetworkError error)
|
|||||||
}
|
}
|
||||||
// error happened during download.
|
// error happened during download.
|
||||||
qCCritical(logCat) << getUid().toString() << "Failed " << m_url.toString() << " with reason " << error;
|
qCCritical(logCat) << getUid().toString() << "Failed " << m_url.toString() << " with reason " << error;
|
||||||
|
if (m_reply)
|
||||||
|
qCCritical(logCat) << getUid().toString() << "HTTP Status " << replyStatusCode() << ";error " << errorString();
|
||||||
m_state = State::Failed;
|
m_state = State::Failed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
#include "ui_MSALoginDialog.h"
|
#include "ui_MSALoginDialog.h"
|
||||||
|
|
||||||
#include "DesktopServices.h"
|
#include "DesktopServices.h"
|
||||||
#include "minecraft/auth/AccountTask.h"
|
#include "minecraft/auth/flows/AuthFlow.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
@ -67,8 +67,8 @@ int MSALoginDialog::exec()
|
|||||||
connect(m_loginTask.get(), &Task::succeeded, this, &MSALoginDialog::onTaskSucceeded);
|
connect(m_loginTask.get(), &Task::succeeded, this, &MSALoginDialog::onTaskSucceeded);
|
||||||
connect(m_loginTask.get(), &Task::status, this, &MSALoginDialog::onTaskStatus);
|
connect(m_loginTask.get(), &Task::status, this, &MSALoginDialog::onTaskStatus);
|
||||||
connect(m_loginTask.get(), &Task::progress, this, &MSALoginDialog::onTaskProgress);
|
connect(m_loginTask.get(), &Task::progress, this, &MSALoginDialog::onTaskProgress);
|
||||||
connect(m_loginTask.get(), &AccountTask::showVerificationUriAndCode, this, &MSALoginDialog::showVerificationUriAndCode);
|
connect(m_loginTask.get(), &AuthFlow::showVerificationUriAndCode, this, &MSALoginDialog::showVerificationUriAndCode);
|
||||||
connect(m_loginTask.get(), &AccountTask::hideVerificationUriAndCode, this, &MSALoginDialog::hideVerificationUriAndCode);
|
connect(m_loginTask.get(), &AuthFlow::hideVerificationUriAndCode, this, &MSALoginDialog::hideVerificationUriAndCode);
|
||||||
connect(&m_externalLoginTimer, &QTimer::timeout, this, &MSALoginDialog::externalLoginTick);
|
connect(&m_externalLoginTimer, &QTimer::timeout, this, &MSALoginDialog::externalLoginTick);
|
||||||
m_loginTask->start();
|
m_loginTask->start();
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <QtWidgets/QDialog>
|
#include <QtWidgets/QDialog>
|
||||||
|
|
||||||
#include "minecraft/auth/MinecraftAccount.h"
|
#include "minecraft/auth/MinecraftAccount.h"
|
||||||
|
#include "minecraft/auth/flows/AuthFlow.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MSALoginDialog;
|
class MSALoginDialog;
|
||||||
@ -52,7 +53,7 @@ class MSALoginDialog : public QDialog {
|
|||||||
private:
|
private:
|
||||||
Ui::MSALoginDialog* ui;
|
Ui::MSALoginDialog* ui;
|
||||||
MinecraftAccountPtr m_account;
|
MinecraftAccountPtr m_account;
|
||||||
shared_qobject_ptr<AccountTask> m_loginTask;
|
shared_qobject_ptr<AuthFlow> m_loginTask;
|
||||||
QTimer m_externalLoginTimer;
|
QTimer m_externalLoginTimer;
|
||||||
int m_externalLoginElapsed = 0;
|
int m_externalLoginElapsed = 0;
|
||||||
int m_externalLoginTimeout = 0;
|
int m_externalLoginTimeout = 0;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "OfflineLoginDialog.h"
|
#include "OfflineLoginDialog.h"
|
||||||
#include "ui_OfflineLoginDialog.h"
|
#include "ui_OfflineLoginDialog.h"
|
||||||
|
|
||||||
#include "minecraft/auth/AccountTask.h"
|
|
||||||
|
|
||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
|
|
||||||
OfflineLoginDialog::OfflineLoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::OfflineLoginDialog)
|
OfflineLoginDialog::OfflineLoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::OfflineLoginDialog)
|
||||||
|
Loading…
Reference in New Issue
Block a user