diff options
| author | 2019-11-08 23:18:56 -0500 | |
|---|---|---|
| committer | 2019-11-09 14:00:44 -0500 | |
| commit | 883eb1a1a1bd23636614c42646c2291c96a5b46b (patch) | |
| tree | d90abc81df310c012072c59fe90021c7eb1ddc3e | |
| parent | Merge pull request #3080 from FernandoS27/glsl-fix (diff) | |
| download | yuzu-883eb1a1a1bd23636614c42646c2291c96a5b46b.tar.gz yuzu-883eb1a1a1bd23636614c42646c2291c96a5b46b.tar.xz yuzu-883eb1a1a1bd23636614c42646c2291c96a5b46b.zip | |
yuzu: configure_web: Use Base64 encoded token for simplifying user experience.
| -rw-r--r-- | src/yuzu/configuration/configure_web.cpp | 73 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_web.ui | 12 |
2 files changed, 53 insertions, 32 deletions
diff --git a/src/yuzu/configuration/configure_web.cpp b/src/yuzu/configuration/configure_web.cpp index 336b062b3..8637f5b3c 100644 --- a/src/yuzu/configuration/configure_web.cpp +++ b/src/yuzu/configuration/configure_web.cpp | |||
| @@ -11,6 +11,31 @@ | |||
| 11 | #include "yuzu/configuration/configure_web.h" | 11 | #include "yuzu/configuration/configure_web.h" |
| 12 | #include "yuzu/uisettings.h" | 12 | #include "yuzu/uisettings.h" |
| 13 | 13 | ||
| 14 | static constexpr char token_delimiter{':'}; | ||
| 15 | |||
| 16 | static std::string GenerateDisplayToken(const std::string& username, const std::string& token) { | ||
| 17 | if (username.empty() || token.empty()) { | ||
| 18 | return {}; | ||
| 19 | } | ||
| 20 | |||
| 21 | const std::string unencoded_display_token{username + token_delimiter + token}; | ||
| 22 | QByteArray b{unencoded_display_token.c_str()}; | ||
| 23 | QByteArray b64 = b.toBase64(); | ||
| 24 | return b64.toStdString(); | ||
| 25 | } | ||
| 26 | |||
| 27 | static std::string UsernameFromDisplayToken(const std::string& display_token) { | ||
| 28 | const std::string unencoded_display_token{ | ||
| 29 | QByteArray::fromBase64(display_token.c_str()).toStdString()}; | ||
| 30 | return unencoded_display_token.substr(0, unencoded_display_token.find(token_delimiter)); | ||
| 31 | } | ||
| 32 | |||
| 33 | static std::string TokenFromDisplayToken(const std::string& display_token) { | ||
| 34 | const std::string unencoded_display_token{ | ||
| 35 | QByteArray::fromBase64(display_token.c_str()).toStdString()}; | ||
| 36 | return unencoded_display_token.substr(unencoded_display_token.find(token_delimiter) + 1); | ||
| 37 | } | ||
| 38 | |||
| 14 | ConfigureWeb::ConfigureWeb(QWidget* parent) | 39 | ConfigureWeb::ConfigureWeb(QWidget* parent) |
| 15 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) { | 40 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureWeb>()) { |
| 16 | ui->setupUi(this); | 41 | ui->setupUi(this); |
| @@ -63,13 +88,18 @@ void ConfigureWeb::SetConfiguration() { | |||
| 63 | ui->web_signup_link->setOpenExternalLinks(true); | 88 | ui->web_signup_link->setOpenExternalLinks(true); |
| 64 | ui->web_token_info_link->setOpenExternalLinks(true); | 89 | ui->web_token_info_link->setOpenExternalLinks(true); |
| 65 | 90 | ||
| 91 | if (Settings::values.yuzu_username.empty()) { | ||
| 92 | ui->username->setText(tr("Unspecified")); | ||
| 93 | } else { | ||
| 94 | ui->username->setText(QString::fromStdString(Settings::values.yuzu_username)); | ||
| 95 | } | ||
| 96 | |||
| 66 | ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry); | 97 | ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry); |
| 67 | ui->edit_username->setText(QString::fromStdString(Settings::values.yuzu_username)); | 98 | ui->edit_token->setText(QString::fromStdString( |
| 68 | ui->edit_token->setText(QString::fromStdString(Settings::values.yuzu_token)); | 99 | GenerateDisplayToken(Settings::values.yuzu_username, Settings::values.yuzu_token))); |
| 69 | 100 | ||
| 70 | // Connect after setting the values, to avoid calling OnLoginChanged now | 101 | // Connect after setting the values, to avoid calling OnLoginChanged now |
| 71 | connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged); | 102 | connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged); |
| 72 | connect(ui->edit_username, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged); | ||
| 73 | 103 | ||
| 74 | user_verified = true; | 104 | user_verified = true; |
| 75 | 105 | ||
| @@ -80,12 +110,13 @@ void ConfigureWeb::ApplyConfiguration() { | |||
| 80 | Settings::values.enable_telemetry = ui->toggle_telemetry->isChecked(); | 110 | Settings::values.enable_telemetry = ui->toggle_telemetry->isChecked(); |
| 81 | UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked(); | 111 | UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked(); |
| 82 | if (user_verified) { | 112 | if (user_verified) { |
| 83 | Settings::values.yuzu_username = ui->edit_username->text().toStdString(); | 113 | Settings::values.yuzu_username = |
| 84 | Settings::values.yuzu_token = ui->edit_token->text().toStdString(); | 114 | UsernameFromDisplayToken(ui->edit_token->text().toStdString()); |
| 115 | Settings::values.yuzu_token = TokenFromDisplayToken(ui->edit_token->text().toStdString()); | ||
| 85 | } else { | 116 | } else { |
| 86 | QMessageBox::warning(this, tr("Username and token not verified"), | 117 | QMessageBox::warning( |
| 87 | tr("Username and token were not verified. The changes to your " | 118 | this, tr("Token not verified"), |
| 88 | "username and/or token have not been saved.")); | 119 | tr("Token was not verified. The change to your token has not been saved.")); |
| 89 | } | 120 | } |
| 90 | } | 121 | } |
| 91 | 122 | ||
| @@ -96,17 +127,15 @@ void ConfigureWeb::RefreshTelemetryID() { | |||
| 96 | } | 127 | } |
| 97 | 128 | ||
| 98 | void ConfigureWeb::OnLoginChanged() { | 129 | void ConfigureWeb::OnLoginChanged() { |
| 99 | if (ui->edit_username->text().isEmpty() && ui->edit_token->text().isEmpty()) { | 130 | if (ui->edit_token->text().isEmpty()) { |
| 100 | user_verified = true; | 131 | user_verified = true; |
| 101 | 132 | ||
| 102 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16); | 133 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16); |
| 103 | ui->label_username_verified->setPixmap(pixmap); | ||
| 104 | ui->label_token_verified->setPixmap(pixmap); | 134 | ui->label_token_verified->setPixmap(pixmap); |
| 105 | } else { | 135 | } else { |
| 106 | user_verified = false; | 136 | user_verified = false; |
| 107 | 137 | ||
| 108 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16); | 138 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16); |
| 109 | ui->label_username_verified->setPixmap(pixmap); | ||
| 110 | ui->label_token_verified->setPixmap(pixmap); | 139 | ui->label_token_verified->setPixmap(pixmap); |
| 111 | } | 140 | } |
| 112 | } | 141 | } |
| @@ -114,10 +143,11 @@ void ConfigureWeb::OnLoginChanged() { | |||
| 114 | void ConfigureWeb::VerifyLogin() { | 143 | void ConfigureWeb::VerifyLogin() { |
| 115 | ui->button_verify_login->setDisabled(true); | 144 | ui->button_verify_login->setDisabled(true); |
| 116 | ui->button_verify_login->setText(tr("Verifying...")); | 145 | ui->button_verify_login->setText(tr("Verifying...")); |
| 117 | verify_watcher.setFuture(QtConcurrent::run([username = ui->edit_username->text().toStdString(), | 146 | verify_watcher.setFuture(QtConcurrent::run( |
| 118 | token = ui->edit_token->text().toStdString()] { | 147 | [username = UsernameFromDisplayToken(ui->edit_token->text().toStdString()), |
| 119 | return Core::VerifyLogin(username, token); | 148 | token = TokenFromDisplayToken(ui->edit_token->text().toStdString())] { |
| 120 | })); | 149 | return Core::VerifyLogin(username, token); |
| 150 | })); | ||
| 121 | } | 151 | } |
| 122 | 152 | ||
| 123 | void ConfigureWeb::OnLoginVerified() { | 153 | void ConfigureWeb::OnLoginVerified() { |
| @@ -127,16 +157,15 @@ void ConfigureWeb::OnLoginVerified() { | |||
| 127 | user_verified = true; | 157 | user_verified = true; |
| 128 | 158 | ||
| 129 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16); | 159 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("checked")).pixmap(16); |
| 130 | ui->label_username_verified->setPixmap(pixmap); | ||
| 131 | ui->label_token_verified->setPixmap(pixmap); | 160 | ui->label_token_verified->setPixmap(pixmap); |
| 161 | ui->username->setText( | ||
| 162 | QString::fromStdString(UsernameFromDisplayToken(ui->edit_token->text().toStdString()))); | ||
| 132 | } else { | 163 | } else { |
| 133 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16); | 164 | const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("failed")).pixmap(16); |
| 134 | ui->label_username_verified->setPixmap(pixmap); | ||
| 135 | ui->label_token_verified->setPixmap(pixmap); | 165 | ui->label_token_verified->setPixmap(pixmap); |
| 136 | 166 | ui->username->setText(tr("Unspecified")); | |
| 137 | QMessageBox::critical( | 167 | QMessageBox::critical(this, tr("Verification failed"), |
| 138 | this, tr("Verification failed"), | 168 | tr("Verification failed. Check that you have entered your token " |
| 139 | tr("Verification failed. Check that you have entered your username and token " | 169 | "correctly, and that your internet connection is working.")); |
| 140 | "correctly, and that your internet connection is working.")); | ||
| 141 | } | 170 | } |
| 142 | } | 171 | } |
diff --git a/src/yuzu/configuration/configure_web.ui b/src/yuzu/configuration/configure_web.ui index 2f4b9dd73..8c07d1165 100644 --- a/src/yuzu/configuration/configure_web.ui +++ b/src/yuzu/configuration/configure_web.ui | |||
| @@ -55,11 +55,7 @@ | |||
| 55 | </widget> | 55 | </widget> |
| 56 | </item> | 56 | </item> |
| 57 | <item row="0" column="1" colspan="3"> | 57 | <item row="0" column="1" colspan="3"> |
| 58 | <widget class="QLineEdit" name="edit_username"> | 58 | <widget class="QLabel" name="username" /> |
| 59 | <property name="maxLength"> | ||
| 60 | <number>36</number> | ||
| 61 | </property> | ||
| 62 | </widget> | ||
| 63 | </item> | 59 | </item> |
| 64 | <item row="1" column="0"> | 60 | <item row="1" column="0"> |
| 65 | <widget class="QLabel" name="label_token"> | 61 | <widget class="QLabel" name="label_token"> |
| @@ -79,14 +75,10 @@ | |||
| 79 | </property> | 75 | </property> |
| 80 | </widget> | 76 | </widget> |
| 81 | </item> | 77 | </item> |
| 82 | <item row="0" column="4"> | ||
| 83 | <widget class="QLabel" name="label_username_verified"> | ||
| 84 | </widget> | ||
| 85 | </item> | ||
| 86 | <item row="1" column="1" colspan="3"> | 78 | <item row="1" column="1" colspan="3"> |
| 87 | <widget class="QLineEdit" name="edit_token"> | 79 | <widget class="QLineEdit" name="edit_token"> |
| 88 | <property name="maxLength"> | 80 | <property name="maxLength"> |
| 89 | <number>36</number> | 81 | <number>80</number> |
| 90 | </property> | 82 | </property> |
| 91 | <property name="echoMode"> | 83 | <property name="echoMode"> |
| 92 | <enum>QLineEdit::Password</enum> | 84 | <enum>QLineEdit::Password</enum> |