diff options
author | Andrew <forkk@forkk.net> | 2013-11-19 12:53:30 -0600 |
---|---|---|
committer | Andrew <forkk@forkk.net> | 2013-11-19 12:53:30 -0600 |
commit | 928e0d0b151a4690a5849c2ec4a44d97338937c5 (patch) | |
tree | 817c32e38fd1492c1f3456be7764e7643a5ef433 /logic/auth | |
parent | a9a0b65358b3799746fa9c8e1aa879e0b59ef526 (diff) | |
download | MultiMC-928e0d0b151a4690a5849c2ec4a44d97338937c5.tar MultiMC-928e0d0b151a4690a5849c2ec4a44d97338937c5.tar.gz MultiMC-928e0d0b151a4690a5849c2ec4a44d97338937c5.tar.lz MultiMC-928e0d0b151a4690a5849c2ec4a44d97338937c5.tar.xz MultiMC-928e0d0b151a4690a5849c2ec4a44d97338937c5.zip |
Implement saving account list to file
Currently it only saves when accounts are added or removed. We'll have
to fix this, but we need signals for when account objects change first.
Diffstat (limited to 'logic/auth')
-rw-r--r-- | logic/auth/MojangAccount.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/logic/auth/MojangAccount.cpp b/logic/auth/MojangAccount.cpp index 936046fb..80b88082 100644 --- a/logic/auth/MojangAccount.cpp +++ b/logic/auth/MojangAccount.cpp @@ -19,6 +19,8 @@ #include <QUuid> +#include <logger/QsLog.h> + MojangAccount::MojangAccount(const QString& username, QObject* parent) : QObject(parent) { @@ -113,6 +115,34 @@ void MojangAccount::loadProfiles(const ProfileList& profiles) m_profiles.append(profile); } +MojangAccountPtr MojangAccount::loadFromJson(const QJsonObject& object) +{ + // The JSON object must at least have a username for it to be valid. + if (!object.value("username").isString()) + { + QLOG_ERROR() << "Can't load Mojang account info from JSON object. Username field is missing or of the wrong type."; + return nullptr; + } + + QString username = object.value("username").toString(""); + QString clientToken = object.value("clientToken").toString(""); + QString accessToken = object.value("accessToken").toString(""); + + // TODO: Load profiles? + + return MojangAccountPtr(new MojangAccount(username, clientToken, accessToken)); +} + +QJsonObject MojangAccount::saveToJson() +{ + QJsonObject json; + json.insert("username", username()); + json.insert("clientToken", clientToken()); + json.insert("accessToken", accessToken()); + // TODO: Save profiles? + return json; +} + AccountProfile::AccountProfile(const QString& id, const QString& name) { |