summaryrefslogtreecommitdiff
path: root/ui/qt5
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2024-10-05 07:10:47 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2024-10-05 07:12:06 -0500
commit84925ed56fb4a299998773293b92c920779ccbec (patch)
tree2c62f4dac31b54f476aeb7605daec1620e23ea8f /ui/qt5
parentd56707af8b9c856776b546952a23686b210f22d8 (diff)
downloadhorizon-current.tar.gz
horizon-current.tar.bz2
horizon-current.tar.xz
horizon-current.zip
Refactor handling of valid account namesHEADcurrent
* Move our system_names and system_groups out to a util header. * Qt UI: Validate that the user's chosen account name is not contained in either system_names nor system_groups. Closes: #388 Acked-by: Síle Ekaterin Liszka <sheila@vulpine.house>
Diffstat (limited to 'ui/qt5')
-rw-r--r--ui/qt5/accountpage.cc27
-rw-r--r--ui/qt5/accountpage.hh4
2 files changed, 24 insertions, 7 deletions
diff --git a/ui/qt5/accountpage.cc b/ui/qt5/accountpage.cc
index f4be6ac..bc0eb2f 100644
--- a/ui/qt5/accountpage.cc
+++ b/ui/qt5/accountpage.cc
@@ -11,12 +11,15 @@
*/
#include "accountpage.hh"
+#include "util/user.hh"
+
#ifdef HAS_INSTALL_ENV
# include "commitpage.hh"
#endif /* HAS_INSTALL_ENV */
#include <algorithm>
#include <QLabel>
+#include <QMessageBox>
#include <QVBoxLayout>
AccountPage::AccountPage(QWidget *parent) : HorizonWizardPage(parent) {
@@ -48,19 +51,35 @@ AccountPage::AccountPage(QWidget *parent) : HorizonWizardPage(parent) {
}
bool AccountPage::isComplete() const {
- return std::all_of(accountWidgets.begin(), accountWidgets.end(),
+ return std::all_of(accountWidgets.cbegin(), accountWidgets.cend(),
[](UserAccountWidget *widget) {
if(widget == nullptr) return true;
return widget->isValid();
});
}
-#ifdef HAS_INSTALL_ENV
bool AccountPage::validatePage() {
+#ifdef HAS_INSTALL_ENV
/* hack to re-initialise page in case the user goes back */
horizonWizard()->removePage(HorizonWizard::Page_Commit);
horizonWizard()->setPage(HorizonWizard::Page_Commit, new CommitPage);
+#endif /* HAS_INSTALL_ENV */
- return true;
+ return std::all_of(accountWidgets.cbegin(), accountWidgets.cend(),
+ [this](const auto &widget) {
+ auto accountText = widget->accountText();
+ if(accountText.isEmpty()) return true;
+
+ auto username = accountText.toStdString();
+ if(system_names.find(username) != system_names.end() ||
+ system_groups.find(username) != system_groups.end()) {
+ QMessageBox::critical(this, tr("Invalid Username"),
+ tr("The username you have chosen (%1) is reserved "
+ "by the system. Choose a different username.")
+ .arg(accountText));
+ return false;
+ }
+
+ return true;
+ });
}
-#endif /* HAS_INSTALL_ENV */
diff --git a/ui/qt5/accountpage.hh b/ui/qt5/accountpage.hh
index 9ca7577..cf1a4ff 100644
--- a/ui/qt5/accountpage.hh
+++ b/ui/qt5/accountpage.hh
@@ -20,11 +20,9 @@
class AccountPage : public HorizonWizardPage {
public:
- AccountPage(QWidget *parent = nullptr);
+ explicit AccountPage(QWidget *parent = nullptr);
bool isComplete() const override;
-#ifdef HAS_INSTALL_ENV
bool validatePage() override;
-#endif
std::array<UserAccountWidget *, 4> accountWidgets;
};