1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-06-08 15:07:45 +00:00

Add "use one-time password" option that can hide the field

This is useful for users who choose to not use OTP, and the layout
is improved so the field is automatically hidden for Sapphire servers,
which don't support OTP.

The register button is also hidden automatically for Square Enix
accounts, instead of simply disabling the button.
This commit is contained in:
Joshua Goins 2022-04-10 17:43:05 -04:00
parent 9ed269c697
commit a9c6bda52a
6 changed files with 42 additions and 10 deletions

View file

@ -75,6 +75,7 @@ struct ProfileSettings {
bool isSapphire = false;
QString lobbyURL;
bool rememberUsername = false, rememberPassword = false;
bool useOneTimePassword = false;
GameLicense license = GameLicense::WindowsStandalone;
};

View file

@ -6,6 +6,7 @@
#include <QPushButton>
#include <QTreeWidget>
#include <QGridLayout>
#include <QFormLayout>
#include "launchercore.h"
#include "headline.h"
@ -31,6 +32,7 @@ private:
bool currentlyReloadingControls = false;
QGridLayout* layout;
QFormLayout* loginLayout;
QLabel* bannerImageView;
QTreeWidget* newsListView;

View file

@ -54,6 +54,7 @@ private:
QLineEdit* lobbyServerURL = nullptr;
QCheckBox* rememberUsernameBox = nullptr, *rememberPasswordBox = nullptr;
QComboBox* gameLicenseBox = nullptr;
QCheckBox* useOneTimePassword = nullptr;
// dalamud
QCheckBox* enableDalamudBox = nullptr;

View file

@ -370,6 +370,7 @@ void LauncherCore::readInitialInformation() {
profile.lobbyURL = settings.value("lobbyURL", defaultSettings.lobbyURL).toString();
profile.rememberUsername = settings.value("rememberUsername", defaultSettings.rememberUsername).toBool();
profile.rememberPassword = settings.value("rememberPassword", defaultSettings.rememberPassword).toBool();
profile.useOneTimePassword = settings.value("useOneTimePassword", defaultSettings.useOneTimePassword).toBool();
profile.license = (GameLicense)settings.value("license", (int)defaultSettings.license).toInt();
profile.useDX9 = settings.value("useDX9", defaultSettings.useDX9).toBool();
@ -589,6 +590,7 @@ void LauncherCore::saveSettings() {
settings.setValue("lobbyURL", profile.lobbyURL);
settings.setValue("rememberUsername", profile.rememberUsername);
settings.setValue("rememberPassword", profile.rememberPassword);
settings.setValue("useOneTimePassword", profile.useOneTimePassword);
settings.setValue("license", (int)profile.license);
settings.setValue("enableDalamud", profile.dalamud.enabled);

View file

@ -110,7 +110,7 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo
QDesktopServices::openUrl(url);
});
auto loginLayout = new QFormLayout();
loginLayout = new QFormLayout();
layout->addLayout(loginLayout, 0, 1, 1, 1);
profileSelect = new QComboBox();
@ -142,13 +142,8 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo
loginLayout->addRow("Remember Password?", rememberPasswordBox);
otpEdit = new QLineEdit();
loginLayout->addRow("One-Time Password", otpEdit);
loginButton = new QPushButton("Login");
loginLayout->addRow(loginButton);
registerButton = new QPushButton("Register");
loginLayout->addRow(registerButton);
auto emptyWidget = new QWidget();
emptyWidget->setLayout(layout);
@ -274,10 +269,6 @@ void LauncherWindow::reloadControls() {
loginButton->setText("Login (Game is not installed)");
}
loginButton->setEnabled(canLogin);
registerButton->setEnabled(currentProfile().isSapphire);
otpEdit->setEnabled(!currentProfile().isSapphire);
launchOfficial->setEnabled(currentProfile().isGameInstalled());
launchSysInfo->setEnabled(currentProfile().isGameInstalled());
launchCfgBackup->setEnabled(currentProfile().isGameInstalled());
@ -292,6 +283,30 @@ void LauncherWindow::reloadControls() {
layout->removeWidget(newsListView);
newsListView->hide();
auto field = loginLayout->labelForField(otpEdit);
if(field != nullptr)
field->deleteLater();
loginLayout->takeRow(otpEdit);
otpEdit->hide();
if(currentProfile().useOneTimePassword && !currentProfile().isSapphire) {
loginLayout->addRow("One-Time Password", otpEdit);
otpEdit->show();
}
loginLayout->takeRow(loginButton);
loginButton->setEnabled(canLogin);
loginLayout->addRow(loginButton);
loginLayout->takeRow(registerButton);
registerButton->hide();
if(currentProfile().isSapphire) {
loginLayout->addRow(registerButton);
registerButton->show();
}
if(core.appSettings.showBanners || core.appSettings.showNewsList) {
int totalRow = 0;
if(core.appSettings.showBanners) {

View file

@ -239,6 +239,16 @@ SettingsWindow::SettingsWindow(int defaultTab, LauncherWindow& window, LauncherC
});
loginBoxLayout->addRow("Remember Password", rememberPasswordBox);
useOneTimePassword = new QCheckBox();
connect(useOneTimePassword, &QCheckBox::stateChanged, [=](int) {
getCurrentProfile().useOneTimePassword =
useOneTimePassword->isChecked();
this->core.saveSettings();
this->window.reloadControls();
});
loginBoxLayout->addRow("Use One-time Password", useOneTimePassword);
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
auto wineBox = new QGroupBox("Wine Options");
auto wineBoxLayout = new QFormLayout();
@ -516,6 +526,7 @@ void SettingsWindow::reloadControls() {
}
rememberUsernameBox->setChecked(profile.rememberUsername);
rememberPasswordBox->setChecked(profile.rememberPassword);
useOneTimePassword->setChecked(profile.useOneTimePassword);
gameLicenseBox->setCurrentIndex((int)profile.license);
// dalamud