mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-21 20:27:45 +00:00
Introduce new and dedicated keychain functions
This replaced the manual use of QtKeychain which could be error-prone, and nasty. This WILL reset saved passwords unfortunately, because the name was set wrong (it was previously LauncherWindow instead of Astra).
This commit is contained in:
parent
21f63b8abd
commit
8fbe1b6514
4 changed files with 45 additions and 78 deletions
|
@ -98,6 +98,16 @@ public:
|
||||||
|
|
||||||
GameLicense license = GameLicense::WindowsStandalone;
|
GameLicense license = GameLicense::WindowsStandalone;
|
||||||
bool isFreeTrial = false;
|
bool isFreeTrial = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sets a value in the keychain. This function is asynchronous.
|
||||||
|
*/
|
||||||
|
void setKeychainValue(QString key, QString value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retrieves a value from the keychain. This function is synchronous.
|
||||||
|
*/
|
||||||
|
QString getKeychainValue(QString key);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AppSettings {
|
struct AppSettings {
|
||||||
|
|
|
@ -649,49 +649,9 @@ void LauncherCore::login(LoginInformation* loginInformation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LauncherCore::autoLogin(ProfileSettings& profile) {
|
bool LauncherCore::autoLogin(ProfileSettings& profile) {
|
||||||
auto loop = new QEventLoop();
|
QString username = profile.getKeychainValue("username");
|
||||||
|
QString password = profile.getKeychainValue("password");
|
||||||
QString username, password;
|
QString otpSecret = profile.getKeychainValue("otpsecret");
|
||||||
QString otpSecret;
|
|
||||||
|
|
||||||
auto usernameJob = new QKeychain::ReadPasswordJob("LauncherWindow");
|
|
||||||
usernameJob->setKey(profile.name + "-username");
|
|
||||||
usernameJob->start();
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
usernameJob, &QKeychain::ReadPasswordJob::finished, [loop, usernameJob, &username](QKeychain::Job* j) {
|
|
||||||
username = usernameJob->textData();
|
|
||||||
loop->quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
loop->exec();
|
|
||||||
|
|
||||||
auto passwordJob = new QKeychain::ReadPasswordJob("LauncherWindow");
|
|
||||||
passwordJob->setKey(profile.name + "-password");
|
|
||||||
passwordJob->start();
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
passwordJob, &QKeychain::ReadPasswordJob::finished, [loop, passwordJob, &password](QKeychain::Job* j) {
|
|
||||||
password = passwordJob->textData();
|
|
||||||
loop->quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
loop->exec();
|
|
||||||
|
|
||||||
// TODO: handle cases where the user doesn't want to store their OTP secret, so we have to manually prompt them
|
|
||||||
if(profile.useOneTimePassword && profile.rememberOTPSecret) {
|
|
||||||
auto otpJob = new QKeychain::ReadPasswordJob("LauncherWindow");
|
|
||||||
otpJob->setKey(profile.name + "-otpsecret");
|
|
||||||
otpJob->start();
|
|
||||||
|
|
||||||
QObject::connect(
|
|
||||||
otpJob, &QKeychain::ReadPasswordJob::finished, [loop, otpJob, &otpSecret](QKeychain::Job* j) {
|
|
||||||
otpSecret = otpJob->textData();
|
|
||||||
loop->quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
loop->exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto info = new LoginInformation();
|
auto info = new LoginInformation();
|
||||||
info->settings = &profile;
|
info->settings = &profile;
|
||||||
|
@ -713,3 +673,30 @@ bool LauncherCore::autoLogin(ProfileSettings& profile) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileSettings::setKeychainValue(QString key, QString value) {
|
||||||
|
auto job = new QKeychain::WritePasswordJob("Astra");
|
||||||
|
job->setTextData(value);
|
||||||
|
job->setKey(name + "-" + key);
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ProfileSettings::getKeychainValue(QString key) {
|
||||||
|
auto loop = new QEventLoop();
|
||||||
|
|
||||||
|
auto job = new QKeychain::ReadPasswordJob("Astra");
|
||||||
|
job->setKey(name + "-" + key);
|
||||||
|
job->start();
|
||||||
|
|
||||||
|
QString value;
|
||||||
|
|
||||||
|
QObject::connect(
|
||||||
|
job, &QKeychain::ReadPasswordJob::finished, [loop, job, &value](QKeychain::Job* j) {
|
||||||
|
value = job->textData();
|
||||||
|
loop->quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
loop->exec();
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
|
@ -285,23 +285,13 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo
|
||||||
info->password = passwordEdit->text();
|
info->password = passwordEdit->text();
|
||||||
info->oneTimePassword = otpEdit->text();
|
info->oneTimePassword = otpEdit->text();
|
||||||
|
|
||||||
#ifndef QT_DEBUG
|
|
||||||
if (currentProfile().rememberUsername) {
|
if (currentProfile().rememberUsername) {
|
||||||
auto job = new QKeychain::WritePasswordJob("LauncherWindow");
|
profile.setKeychainValue("username", usernameEdit->text());
|
||||||
job->setTextData(usernameEdit->text());
|
|
||||||
job->setKey(currentProfile().name + "-username");
|
|
||||||
job->start();
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef QT_DEBUG
|
|
||||||
if (currentProfile().rememberPassword) {
|
if (currentProfile().rememberPassword) {
|
||||||
auto job = new QKeychain::WritePasswordJob("LauncherWindow");
|
profile.setKeychainValue("password", passwordEdit->text());
|
||||||
job->setTextData(passwordEdit->text());
|
|
||||||
job->setKey(currentProfile().name + "-password");
|
|
||||||
job->start();
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
this->core.login(info);
|
this->core.login(info);
|
||||||
});
|
});
|
||||||
|
@ -368,30 +358,14 @@ void LauncherWindow::reloadControls() {
|
||||||
}
|
}
|
||||||
|
|
||||||
rememberUsernameBox->setChecked(currentProfile().rememberUsername);
|
rememberUsernameBox->setChecked(currentProfile().rememberUsername);
|
||||||
#ifndef QT_DEBUG
|
|
||||||
if (currentProfile().rememberUsername) {
|
if (currentProfile().rememberUsername) {
|
||||||
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
usernameEdit->setText(currentProfile().getKeychainValue("username"));
|
||||||
job->setKey(currentProfile().name + "-username");
|
|
||||||
job->start();
|
|
||||||
|
|
||||||
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
|
||||||
usernameEdit->setText(job->textData());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
rememberPasswordBox->setChecked(currentProfile().rememberPassword);
|
rememberPasswordBox->setChecked(currentProfile().rememberPassword);
|
||||||
#ifndef QT_DEBUG
|
|
||||||
if (currentProfile().rememberPassword) {
|
if (currentProfile().rememberPassword) {
|
||||||
auto job = new QKeychain::ReadPasswordJob("LauncherWindow");
|
passwordEdit->setText(currentProfile().getKeychainValue("password"));
|
||||||
job->setKey(currentProfile().name + "-password");
|
|
||||||
job->start();
|
|
||||||
|
|
||||||
connect(job, &QKeychain::ReadPasswordJob::finished, [=](QKeychain::Job* j) {
|
|
||||||
passwordEdit->setText(job->textData());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool canLogin = true;
|
bool canLogin = true;
|
||||||
if (currentProfile().isSapphire) {
|
if (currentProfile().isSapphire) {
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <qt5keychain/keychain.h>
|
|
||||||
|
|
||||||
#include "gamescopesettingswindow.h"
|
#include "gamescopesettingswindow.h"
|
||||||
#include "launchercore.h"
|
#include "launchercore.h"
|
||||||
|
@ -446,10 +445,7 @@ void SettingsWindow::setupLoginTab(QFormLayout& layout) {
|
||||||
connect(otpSecretButton, &QPushButton::pressed, [=] {
|
connect(otpSecretButton, &QPushButton::pressed, [=] {
|
||||||
auto otpSecret = QInputDialog::getText(this, "OTP Input", "Enter your OTP Secret:");
|
auto otpSecret = QInputDialog::getText(this, "OTP Input", "Enter your OTP Secret:");
|
||||||
|
|
||||||
auto job = new QKeychain::WritePasswordJob("LauncherWindow");
|
getCurrentProfile().setKeychainValue("otpsecret", otpSecret);
|
||||||
job->setTextData(otpSecret);
|
|
||||||
job->setKey(this->getCurrentProfile().name + "-otpsecret");
|
|
||||||
job->start();
|
|
||||||
});
|
});
|
||||||
otpSecretButton->setToolTip("Enter your OTP secret from Square Enix here. You cannot easily retrieve this if you forget it.");
|
otpSecretButton->setToolTip("Enter your OTP secret from Square Enix here. You cannot easily retrieve this if you forget it.");
|
||||||
layout.addRow(otpSecretButton);
|
layout.addRow(otpSecretButton);
|
||||||
|
|
Loading…
Add table
Reference in a new issue