From 702a0ac0ee3ae78a4ae0cd88fa1d988193492d1c Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Thu, 4 Jul 2024 16:40:28 +0200 Subject: [PATCH] Generate more user friendly SHV API key --- 3rdparty/libshv | 2 +- .../plugins/Event/src/eventplugin.cpp | 26 ++++++++++++++----- .../shvapi/shvclientservicewidget.cpp | 3 +-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/3rdparty/libshv b/3rdparty/libshv index 43c7fbb90..124468e32 160000 --- a/3rdparty/libshv +++ b/3rdparty/libshv @@ -1 +1 @@ -Subproject commit 43c7fbb905d67d4b9d4034c0f72e91ac34090a60 +Subproject commit 124468e3253cff998aaf82bc1ff4efdd6840756a diff --git a/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp b/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp index 3a4a94749..8d58004a6 100644 --- a/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp @@ -511,13 +511,25 @@ QString EventPlugin::shvApiEventId() const QString EventPlugin::createShvApiKey() { QString key; - QList cc; - for (auto i = 'a'; i <= 'z'; i++) { cc << i; } - for (auto i = 'A'; i <= 'Z'; i++) { cc << i; } - for (auto i = '0'; i <= '9'; i++) { cc << i; } - for (int i = 0; i < 16; i++) { - quint32 ix = QRandomGenerator::global()->generate() % cc.size(); - key += cc[ix]; + static const QList vowels{'a', 'e', 'i', 'o', 'u', 'y'}; + static const QList consonants = []() { + QList cc; + for (auto i = 'a'; i <= 'z'; i++) { + if (!vowels.contains(i)) { + cc << i; + } + } + return cc; + } (); + for (int i = 0; i < 12; i++) { + if (i % 2 == 0) { + auto ix = QRandomGenerator::global()->generate() % consonants.size(); + key += consonants[ix]; + } + else { + auto ix = QRandomGenerator::global()->generate() % vowels.size(); + key += vowels[ix]; + } } return key; } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/shvapi/shvclientservicewidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/shvapi/shvclientservicewidget.cpp index 5172fc59b..60e655299 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/shvapi/shvclientservicewidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/shvapi/shvclientservicewidget.cpp @@ -71,13 +71,12 @@ bool ShvClientServiceWidget::saveSettings() void ShvClientServiceWidget::updateQrCodeUrl() { QUrl url(ui->shvUrl->text()); + url.setScheme("https"); url.setPath("/" + ui->shvEventPath->text()); auto query = QUrlQuery(url); url.setQuery(QString()); query.addQueryItem("api_key", ui->shvApiKey->text()); url.setQuery(query); - bool b = url.isValid(); - auto es = url.errorString(); auto s = url.toString(); ui->qrCodeUrl->setText(s); }