summaryrefslogtreecommitdiffstats
path: root/logic/auth
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-12-15 15:01:34 -0600
committerAndrew <forkk@forkk.net>2013-12-15 15:01:34 -0600
commit9d8006b597aead06f1d51dacbdb346ebab3d5e8f (patch)
tree1f99ca1da321be32930198e3d72b2fc9d3bf53de /logic/auth
parent0ee8f90d40f5b3ddb177286c9066a4e59748c681 (diff)
parentb0e8037feb5b9d48defe6b8263d068f87bdb141c (diff)
downloadMultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar.gz
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar.lz
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.tar.xz
MultiMC-9d8006b597aead06f1d51dacbdb346ebab3d5e8f.zip
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into feature_news
Conflicts: CMakeLists.txt
Diffstat (limited to 'logic/auth')
-rw-r--r--logic/auth/MojangAccount.cpp4
-rw-r--r--logic/auth/MojangAccount.h5
-rw-r--r--logic/auth/MojangAccountList.cpp64
-rw-r--r--logic/auth/MojangAccountList.h7
-rw-r--r--logic/auth/flows/AuthenticateTask.cpp6
-rw-r--r--logic/auth/flows/RefreshTask.cpp9
6 files changed, 82 insertions, 13 deletions
diff --git a/logic/auth/MojangAccount.cpp b/logic/auth/MojangAccount.cpp
index 185c735c..bc6af98f 100644
--- a/logic/auth/MojangAccount.cpp
+++ b/logic/auth/MojangAccount.cpp
@@ -68,6 +68,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
User u;
QJsonObject userStructure = object.value("user").toObject();
u.id = userStructure.value("id").toString();
+ /*
QJsonObject propMap = userStructure.value("properties").toObject();
for(auto key: propMap.keys())
{
@@ -75,6 +76,7 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject &object)
for(auto value: values)
u.properties.insert(key, value.toString());
}
+ */
account->m_user = u;
}
account->m_username = username;
@@ -119,6 +121,7 @@ QJsonObject MojangAccount::saveToJson() const
QJsonObject userStructure;
{
userStructure.insert("id", m_user.id);
+ /*
QJsonObject userAttrs;
for(auto key: m_user.properties.keys())
{
@@ -126,6 +129,7 @@ QJsonObject MojangAccount::saveToJson() const
userAttrs.insert(key, array);
}
userStructure.insert("properties", userAttrs);
+ */
}
json.insert("user", userStructure);
diff --git a/logic/auth/MojangAccount.h b/logic/auth/MojangAccount.h
index 9eecbc4f..325aa826 100644
--- a/logic/auth/MojangAccount.h
+++ b/logic/auth/MojangAccount.h
@@ -122,6 +122,11 @@ public: /* queries */
return m_profiles;
}
+ const User & user()
+ {
+ return m_user;
+ }
+
//! Get the session ID required for legacy Minecraft versions
QString sessionId() const
{
diff --git a/logic/auth/MojangAccountList.cpp b/logic/auth/MojangAccountList.cpp
index 0d13cd34..70bc0cf2 100644
--- a/logic/auth/MojangAccountList.cpp
+++ b/logic/auth/MojangAccountList.cpp
@@ -22,10 +22,12 @@
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonParseError>
+#include <QDir>
#include "logger/QsLog.h"
#include "logic/auth/MojangAccount.h"
+#include <pathutils.h>
#define ACCOUNT_LIST_FORMAT_VERSION 2
@@ -148,9 +150,6 @@ QVariant MojangAccountList::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
switch (index.column())
{
- case ActiveColumn:
- return account == m_activeAccount;
-
case NameColumn:
return account->username();
@@ -164,6 +163,13 @@ QVariant MojangAccountList::data(const QModelIndex &index, int role) const
case PointerRole:
return qVariantFromValue(account);
+ case Qt::CheckStateRole:
+ switch (index.column())
+ {
+ case ActiveColumn:
+ return account == m_activeAccount;
+ }
+
default:
return QVariant();
}
@@ -212,6 +218,36 @@ int MojangAccountList::columnCount(const QModelIndex &parent) const
return 2;
}
+Qt::ItemFlags MojangAccountList::flags(const QModelIndex &index) const
+{
+ if (index.row() < 0 || index.row() >= rowCount(index) || !index.isValid())
+ {
+ return Qt::NoItemFlags;
+ }
+
+ return Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+
+bool MojangAccountList::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (index.row() < 0 || index.row() >= rowCount(index) || !index.isValid())
+ {
+ return false;
+ }
+
+ if(role == Qt::CheckStateRole)
+ {
+ if(value == Qt::Checked)
+ {
+ MojangAccountPtr account = this->at(index.row());
+ this->setActiveAccount(account->username());
+ }
+ }
+
+ emit dataChanged(index, index);
+ return true;
+}
+
void MojangAccountList::updateListData(QList<MojangAccountPtr> versions)
{
beginResetModel();
@@ -311,6 +347,18 @@ bool MojangAccountList::saveList(const QString &filePath)
return false;
}
+ // make sure the parent folder exists
+ if(!ensureFilePathExists(path))
+ return false;
+
+ // make sure the file wasn't overwritten with a folder before (fixes a bug)
+ QFileInfo finfo(path);
+ if(finfo.isDir())
+ {
+ QDir badDir(path);
+ badDir.removeRecursively();
+ }
+
QLOG_INFO() << "Writing account list to" << path;
QLOG_DEBUG() << "Building JSON data structure.";
@@ -366,3 +414,13 @@ void MojangAccountList::setListFilePath(QString path, bool autosave)
m_listFilePath = path;
m_autosave = autosave;
}
+
+bool MojangAccountList::anyAccountIsValid()
+{
+ for(auto account:m_accounts)
+ {
+ if(account->accountStatus() != NotVerified)
+ return true;
+ }
+ return false;
+}
diff --git a/logic/auth/MojangAccountList.h b/logic/auth/MojangAccountList.h
index b3301bf6..6f4fbb17 100644
--- a/logic/auth/MojangAccountList.h
+++ b/logic/auth/MojangAccountList.h
@@ -64,6 +64,8 @@ public:
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int rowCount(const QModelIndex &parent) const;
virtual int columnCount(const QModelIndex &parent) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
/*!
* Adds a the given Mojang account to the account list.
@@ -124,6 +126,11 @@ public:
* If the username given is an empty string, sets the active account to nothing.
*/
virtual void setActiveAccount(const QString &username);
+
+ /*!
+ * Returns true if any of the account is at least Validated
+ */
+ bool anyAccountIsValid();
signals:
/*!
diff --git a/logic/auth/flows/AuthenticateTask.cpp b/logic/auth/flows/AuthenticateTask.cpp
index cc26cd1b..f60be35d 100644
--- a/logic/auth/flows/AuthenticateTask.cpp
+++ b/logic/auth/flows/AuthenticateTask.cpp
@@ -162,23 +162,17 @@ bool AuthenticateTask::processResponse(QJsonObject responseData)
}
// this is what the vanilla launcher passes to the userProperties launch param
- // doesn't seem to be used for anything so far? I don't get any of this data on my account
- // (peterixxx)
- // is it a good idea to log this?
if (responseData.contains("user"))
{
User u;
auto obj = responseData.value("user").toObject();
u.id = obj.value("id").toString();
- QLOG_DEBUG() << "User ID: " << u.id ;
auto propArray = obj.value("properties").toArray();
- QLOG_DEBUG() << "User Properties: ";
for (auto prop : propArray)
{
auto propTuple = prop.toObject();
auto name = propTuple.value("name").toString();
auto value = propTuple.value("value").toString();
- QLOG_DEBUG() << name << " : " << value;
u.properties.insert(name, value);
}
m_account->m_user = u;
diff --git a/logic/auth/flows/RefreshTask.cpp b/logic/auth/flows/RefreshTask.cpp
index 16feac6e..5f68ccc7 100644
--- a/logic/auth/flows/RefreshTask.cpp
+++ b/logic/auth/flows/RefreshTask.cpp
@@ -112,20 +112,21 @@ bool RefreshTask::processResponse(QJsonObject responseData)
// this is what the vanilla launcher passes to the userProperties launch param
if (responseData.contains("user"))
{
+ User u;
auto obj = responseData.value("user").toObject();
- auto userId = obj.value("id").toString();
+ u.id = obj.value("id").toString();
auto propArray = obj.value("properties").toArray();
- QLOG_DEBUG() << "User ID: " << userId;
- QLOG_DEBUG() << "User Properties: ";
for (auto prop : propArray)
{
auto propTuple = prop.toObject();
auto name = propTuple.value("name").toString();
auto value = propTuple.value("value").toString();
- QLOG_DEBUG() << name << " : " << value;
+ u.properties.insert(name, value);
}
+ m_account->m_user = u;
}
+
// We've made it through the minefield of possible errors. Return true to indicate that
// we've succeeded.
QLOG_DEBUG() << "Finished reading refresh response.";