summaryrefslogtreecommitdiffstats
path: root/logic/auth
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-11-20 18:31:15 -0600
committerAndrew <forkk@forkk.net>2013-11-20 18:31:15 -0600
commitabf8408911c057d8aafe90790f5d2f5de0e1d97c (patch)
treeb6b77a485702c0a7ac45b5b96d6b8b0f41c14af7 /logic/auth
parent03652b01d2ec8a7c54fb39dd8ed660f0bbc2fa2a (diff)
downloadMultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.gz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.lz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.tar.xz
MultiMC-abf8408911c057d8aafe90790f5d2f5de0e1d97c.zip
Nuke and pave the old login system
Also, account list now saves profile lists.
Diffstat (limited to 'logic/auth')
-rw-r--r--logic/auth/MojangAccount.cpp55
-rw-r--r--logic/auth/MojangAccount.h2
2 files changed, 52 insertions, 5 deletions
diff --git a/logic/auth/MojangAccount.cpp b/logic/auth/MojangAccount.cpp
index 80b88082..4875e5f7 100644
--- a/logic/auth/MojangAccount.cpp
+++ b/logic/auth/MojangAccount.cpp
@@ -18,6 +18,8 @@
#include "MojangAccount.h"
#include <QUuid>
+#include <QJsonObject>
+#include <QJsonArray>
#include <logger/QsLog.h>
@@ -89,7 +91,12 @@ const QList<AccountProfile> MojangAccount::profiles() const
const AccountProfile* MojangAccount::currentProfile() const
{
if (m_currentProfile < 0)
- return nullptr;
+ {
+ if (m_profiles.length() > 0)
+ return &m_profiles.at(0);
+ else
+ return nullptr;
+ }
else
return &m_profiles.at(m_currentProfile);
}
@@ -128,9 +135,36 @@ MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject& object)
QString clientToken = object.value("clientToken").toString("");
QString accessToken = object.value("accessToken").toString("");
- // TODO: Load profiles?
+ QJsonArray profileArray = object.value("profiles").toArray();
+ if (profileArray.size() < 1)
+ {
+ QLOG_ERROR() << "Can't load Mojang account with username \"" << username << "\". No profiles found.";
+ return nullptr;
+ }
+
+ ProfileList profiles;
+ for (QJsonValue profileVal : profileArray)
+ {
+ QJsonObject profileObject = profileVal.toObject();
+ QString id = profileObject.value("id").toString("");
+ QString name = profileObject.value("name").toString("");
+ if (id.isEmpty() || name.isEmpty())
+ {
+ QLOG_WARN() << "Unable to load a profile because it was missing an ID or a name.";
+ continue;
+ }
+ profiles.append(AccountProfile(id, name));
+ }
+
+ MojangAccountPtr account(new MojangAccount(username, clientToken, accessToken));
+ account->loadProfiles(profiles);
- return MojangAccountPtr(new MojangAccount(username, clientToken, accessToken));
+ // Get the currently selected profile.
+ QString currentProfile = object.value("activeProfile").toString("");
+ if (!currentProfile.isEmpty())
+ account->setProfile(currentProfile);
+
+ return account;
}
QJsonObject MojangAccount::saveToJson()
@@ -139,7 +173,20 @@ QJsonObject MojangAccount::saveToJson()
json.insert("username", username());
json.insert("clientToken", clientToken());
json.insert("accessToken", accessToken());
- // TODO: Save profiles?
+
+ QJsonArray profileArray;
+ for (AccountProfile profile : m_profiles)
+ {
+ QJsonObject profileObj;
+ profileObj.insert("id", profile.id());
+ profileObj.insert("name", profile.name());
+ profileArray.append(profileObj);
+ }
+ json.insert("profiles", profileArray);
+
+ if (currentProfile() != nullptr)
+ json.insert("activeProfile", currentProfile()->id());
+
return json;
}
diff --git a/logic/auth/MojangAccount.h b/logic/auth/MojangAccount.h
index 35261d65..e5684b77 100644
--- a/logic/auth/MojangAccount.h
+++ b/logic/auth/MojangAccount.h
@@ -123,7 +123,7 @@ public:
/**
* Returns a pointer to the currently selected profile.
- * If no profile is selected, returns nullptr.
+ * If no profile is selected, returns the first profile in the profile list or nullptr if there are none.
*/
const AccountProfile* currentProfile() const;