Fixed user creation
This commit is contained in:
@@ -66,12 +66,9 @@ class UserModel : public Wt::WFormModel
|
|||||||
setValidator(LoginField, createNameValidator());
|
setValidator(LoginField, createNameValidator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addField(AuthModeField);
|
||||||
addField(PasswordField);
|
addField(PasswordField);
|
||||||
addField(DemoField);
|
addField(DemoField);
|
||||||
addField(AuthModeField);
|
|
||||||
|
|
||||||
if (!_userId)
|
|
||||||
setValidator(PasswordField, createMandatoryValidator());
|
|
||||||
|
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
@@ -153,12 +150,19 @@ class UserModel : public Wt::WFormModel
|
|||||||
{
|
{
|
||||||
auto transaction {LmsApp->getDbSession().createSharedTransaction()};
|
auto transaction {LmsApp->getDbSession().createSharedTransaction()};
|
||||||
|
|
||||||
// Allow an empty password if and only if the user previously had one set
|
bool needPassword {true};
|
||||||
const Database::User::pointer user {Database::User::getById(LmsApp->getDbSession(), *_userId)};
|
|
||||||
if (!user)
|
|
||||||
throw UserNotFoundException {*_userId};
|
|
||||||
|
|
||||||
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");
|
error = Wt::WString::tr("Lms.password-must-not-be-empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user