summaryrefslogtreecommitdiff
path: root/ui/qt5
diff options
context:
space:
mode:
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;
};