From 21942f1db857ac8a1a9f06b7e7a2ac6769c1a2a4 Mon Sep 17 00:00:00 2001 From: emeric Date: Mon, 6 Jul 2020 13:54:03 +0200 Subject: [PATCH] Fixed user creation --- src/lms/ui/admin/UserView.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lms/ui/admin/UserView.cpp b/src/lms/ui/admin/UserView.cpp index 3daad20f..909af333 100644 --- a/src/lms/ui/admin/UserView.cpp +++ b/src/lms/ui/admin/UserView.cpp @@ -66,12 +66,9 @@ class UserModel : public Wt::WFormModel setValidator(LoginField, createNameValidator()); } + addField(AuthModeField); addField(PasswordField); addField(DemoField); - addField(AuthModeField); - - if (!_userId) - setValidator(PasswordField, createMandatoryValidator()); loadData(); } @@ -153,12 +150,19 @@ class UserModel : public Wt::WFormModel { auto transaction {LmsApp->getDbSession().createSharedTransaction()}; - // Allow an empty password if and only if the user previously had one set - const Database::User::pointer user {Database::User::getById(LmsApp->getDbSession(), *_userId)}; - if (!user) - throw UserNotFoundException {*_userId}; + bool needPassword {true}; - if (user->getPasswordHash().hash.empty()) + // Allow an empty password if and only if the user previously had one set + if (_userId) + { + const Database::User::pointer user {Database::User::getById(LmsApp->getDbSession(), *_userId)}; + if (!user) + throw UserNotFoundException {*_userId}; + + needPassword = user->getPasswordHash().hash.empty(); + } + + if (needPassword) error = Wt::WString::tr("Lms.password-must-not-be-empty"); } }