Skip to content

UserCreatedEvent emitted twice when creating user via user management webui #23797

@7118path

Description

@7118path

When creating a user account via the user management web ui, the '\OCP\User\Events\UserCreatedEvent' is emitted twice.

Steps to reproduce

  1. Create a listener for the '\OCP\User\Events\UserCreatedEvent' event and let it log or do something
  2. Create a user via the user management webui
  3. See the handle function of the listener is called twice

Expected behaviour

'\OCP\User\Events\UserCreatedEvent' should be emitted once only.

Actual behaviour

'\OCP\User\Events\UserCreatedEvent' is emitted twice.

Server configuration

Tested in official docker based Nextcloud 19.0.4 and 20.0.1

I think this causes the behaviour:

  • Emit Hook and Event in UserManager:
    if ($user instanceof IUser) {
    $this->emit('\OC\User', 'postCreateUser', [$user, $password]);
    $this->eventDispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
    }
  • React on Hook and emit Event a second time:
    $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
    /** @var \OC\User\User $user */
    \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
    /** @var IEventDispatcher $dispatcher */
    $dispatcher = $this->get(IEventDispatcher::class);
    $dispatcher->dispatchTyped(new UserCreatedEvent($user, $password));
    });

If commenting L544-L545of Server.php the listener is only triggerd once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions