Fix user creation during installation.

pull/3890/head
Julio Montoya 4 years ago
parent 4f5cd5c4a7
commit 8c8eae2e64
  1. 14
      public/main/inc/lib/usermanager.lib.php
  2. 2
      public/main/install/install.lib.php
  3. 21
      src/CoreBundle/Entity/Listener/UserListener.php

@ -140,7 +140,7 @@ class UserManager
* @param int $creatorId
* @param array $emailTemplate
* @param string $redirectToURLAfterLogin
* @param bool $addUserToNode
* @param bool $addUserToNode Only needed during installation.
*
* @return mixed new user id - if the new user creation succeeds, false otherwise
* @desc The function tries to retrieve user id from the session.
@ -178,10 +178,18 @@ class UserManager
) {
$authSource = !empty($authSource) ? $authSource : PLATFORM_AUTH_SOURCE;
$creatorId = empty($creatorId) ? api_get_user_id() : 0;
if ($addUserToNode && 0 === $creatorId) {
Display::addFlash(
Display::return_message(get_lang('A user creator is needed'))
);
return false;
}
$creatorInfo = api_get_user_info($creatorId);
$creatorEmail = isset($creatorInfo['email']) ? $creatorInfo['email'] : '';
// First check wether the login already exists
// First check if the login exists.
if (!self::is_username_available($loginName)) {
Display::addFlash(
Display::return_message(get_lang('This login is already taken !'))
@ -279,7 +287,7 @@ class UserManager
if (empty($expirationDate) || '0000-00-00 00:00:00' === $expirationDate) {
$expirationDate = null;
// Default expiration date
// Default expiration date
// if there is a default duration of a valid account then
// we have to change the expiration_date accordingly
// Accept 0000-00-00 00:00:00 as a null value to avoid issues with

@ -2470,7 +2470,7 @@ function finishInstallationWithContainer(
// Inserting default data
$data = file_get_contents($sysPath.'public/main/install/data.sql');
$result = $manager->getConnection()->prepare($data);
$executeResult = $result->execute();
$executeResult = $result->executeQuery();
if ($executeResult) {
error_log('data.sql Ok');

@ -15,8 +15,8 @@ use Symfony\Component\Security\Core\Security;
class UserListener
{
protected UserRepository $userRepository;
protected Security $security;
private UserRepository $userRepository;
private Security $security;
public function __construct(UserRepository $userRepository, Security $security)
{
@ -30,21 +30,32 @@ class UserListener
public function prePersist(User $user, LifecycleEventArgs $args): void
{
error_log('User listener prePersist');
if ($user) {
$this->userRepository->updateCanonicalFields($user);
$this->userRepository->updatePassword($user);
if (!$user->hasResourceNode()) {
$addResourceNode = true;
if (0 === $user->getCreatorId()) {
$addResourceNode = false;
}
if ($addResourceNode && !$user->hasResourceNode()) {
$token = $this->security->getToken();
if (null === $token) {
throw new Exception('A user creator is needed');
}
$em = $args->getEntityManager();
$resourceNode = new ResourceNode();
$resourceNode
->setTitle($user->getUsername())
->setCreator($this->security->getUser())
->setResourceType($this->userRepository->getResourceType())
;
->setResourceType($this->userRepository->getResourceType());
$em->persist($resourceNode);
$user->setResourceNode($resourceNode);
}
}
}

Loading…
Cancel
Save