# UserEvent events

> 10 FeatherPanel plugin events on UserEvent (10 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/user/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions.

## Setup

Import `UserEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\UserEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(UserEvent::onUserApiKeyCreated(), function ($userUuid, $apiClient): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:created ' . json_encode(['user_uuid' => $userUuid, 'api_client' => $apiClient]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `UserEvent::onUserApiKeyCreated()`

- Name: `featherpanel:user:api_client:created`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L27)

Docblock: string user uuid, string api key id.

Same event name as `UserApiClientEvent::onUserApiClientCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `api_client` | `$apiClient` | `string`from docblock |

When it fires (1 site)

-   [`ApiClientController::createApiClient`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L407)[`POST /api/user/api-clients`](https://featherpanel.com/docs/api/reference/user/api-clients/#post-user-api-clients)

```php
$event->on(UserEvent::onUserApiKeyCreated(), function ($userUuid, $apiClient): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:created ' . json_encode(['user_uuid' => $userUuid, 'api_client' => $apiClient]));
});
```

## `UserEvent::onUserApiKeyDeleted()`

- Name: `featherpanel:user:api_client:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L43)

Docblock: string user uuid, string api key id.

Same event name as `UserApiClientEvent::onUserApiClientDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `api_client` | `$apiClient` | `string`from docblock |

When it fires (1 site)

-   [`ApiClientController::deleteApiClient`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L799)[`DELETE /api/user/api-clients/{id}`](https://featherpanel.com/docs/api/reference/user/api-clients/#delete-user-api-clients-id)

```php
$event->on(UserEvent::onUserApiKeyDeleted(), function ($userUuid, $apiClient): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:deleted ' . json_encode(['user_uuid' => $userUuid, 'api_client' => $apiClient]));
});
```

## `UserEvent::onUserApiKeyUpdated()`

- Name: `featherpanel:user:api_client:updated`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L35)

Docblock: string user uuid, string api key id. (the emitter passes 3 values, see the table)

Same event name as `UserApiClientEvent::onUserApiClientUpdated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `api_client` | `$apiClient` | not declared |
| 3 | `updated_data` | `$updatedData`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `api_client`, `updated_data` | 
`ApiClientController::updateApiClient`

 |
| `user_uuid`, `api_client`, `action` | 

`ApiClientController::regenerateApiKeys`

 |

When it fires (2 sites)

-   [`ApiClientController::updateApiClient`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L717)[`PUT /api/user/api-clients/{id}`](https://featherpanel.com/docs/api/reference/user/api-clients/#put-user-api-clients-id)
-   [`ApiClientController::regenerateApiKeys`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/ApiClientController.php#L890)[`POST /api/user/api-clients/{id}/regenerate`](https://featherpanel.com/docs/api/reference/user/api-clients/#post-user-api-clients-id-regenerate)

```php
$event->on(UserEvent::onUserApiKeyUpdated(), function ($userUuid, $apiClient, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:api_client:updated');
});
```

## `UserEvent::onUserCreated()`

- Name: `featherpanel:user:created`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L83)

Docblock: array user data, int user id, array created by. (the emitter passes 2 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user` | `$user` | not declared |
| 2 | `created_by` | `$createdBy`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `user`, `created_by` | 
`PterodactylImporterController::importUser`

 |
| `user`, `user_id`, `uuid`, `created_by` | 

`UsersController::create`

 |

When it fires (2 sites)

-   [`PterodactylImporterController::importUser`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PterodactylImporterController.php#L954)[`POST /api/admin/pterodactyl-importer/import-user`](https://featherpanel.com/docs/api/reference/admin/pterodactyl-importer/#post-admin-pterodactyl-importer-import-user)
-   [`UsersController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/UsersController.php#L765)[`PUT /api/admin/users`](https://featherpanel.com/docs/api/reference/admin/users/#put-admin-users)

```php
$event->on(UserEvent::onUserCreated(), function ($user, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:created');
});
```

## `UserEvent::onUserDeleted()`

- Name: `featherpanel:user:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L99)

Docblock: array user data, array deleted by.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user` | `$user` | `array` |
| 2 | `deleted_by` | `$deletedBy` | `array|null` |

When it fires (1 site)

-   [`UserDeletionService::hardDelete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/User/UserDeletionService.php#L171)

```php
$event->on(UserEvent::onUserDeleted(), function ($user, $deletedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:deleted ' . json_encode(['user' => $user, 'deleted_by' => $deletedBy]));
});
```

## `UserEvent::onUserSshKeyCreated()`

- Name: `featherpanel:user:ssh_key:created`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L59)

Docblock: string user uuid, string ssh key id.

Same event name as `UserSshKeyEvent::onUserSshKeyCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `ssh_key` | `$sshKey`not at every site | `string`from docblock |
| 2 | `created_by` | `$createdBy`not at every site | `string`from docblock |

| Arguments passed | Emitted from |
| --- | --- |
| `ssh_key`, `created_by` | 
`PterodactylImporterController::importSshKey`

 |
| `user_uuid`, `ssh_key` | 

`UserSshKeyController::createUserSshKey`

 |

When it fires (2 sites)

-   [`PterodactylImporterController::importSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PterodactylImporterController.php#L1123)[`POST /api/admin/pterodactyl-importer/import-ssh-key`](https://featherpanel.com/docs/api/reference/admin/pterodactyl-importer/#post-admin-pterodactyl-importer-import-ssh-key)
-   [`UserSshKeyController::createUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L371)[`POST /api/user/ssh-keys`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#post-user-ssh-keys)

```php
$event->on(UserEvent::onUserSshKeyCreated(), function (...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:created');
});
```

## `UserEvent::onUserSshKeyDeleted()`

- Name: `featherpanel:user:ssh_key:deleted`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L75)

Docblock: string user uuid, string ssh key id.

Same event name as `UserSshKeyEvent::onUserSshKeyDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `ssh_key` | `$sshKey` | `string`from docblock |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `ssh_key` | 
`UserSshKeyController::deleteUserSshKey`

 |
| `user_uuid`, `ssh_key`, `action` | 

`UserSshKeyController::hardDeleteUserSshKey`

 |

When it fires (2 sites)

-   [`UserSshKeyController::deleteUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L569)[`DELETE /api/user/ssh-keys/{id}`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#delete-user-ssh-keys-id)
-   [`UserSshKeyController::hardDeleteUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L756)[`DELETE /api/user/ssh-keys/{id}/hard-delete`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#delete-user-ssh-keys-id-hard-delete)

```php
$event->on(UserEvent::onUserSshKeyDeleted(), function ($userUuid, $sshKey, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:deleted ' . json_encode(['user_uuid' => $userUuid, 'ssh_key' => $sshKey]));
});
```

## `UserEvent::onUserSshKeyUpdated()`

- Name: `featherpanel:user:ssh_key:updated`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L67)

Docblock: string user uuid, string ssh key id. (the emitter passes 3 values, see the table)

Same event name as `UserSshKeyEvent::onUserSshKeyUpdated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `ssh_key` | `$sshKey` | not declared |
| 3 | `updated_data` | `$updatedData`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `user_uuid`, `ssh_key`, `updated_data` | 
`UserSshKeyController::updateUserSshKey`

 |
| `user_uuid`, `ssh_key`, `action` | 

`UserSshKeyController::restoreUserSshKey`

 |

When it fires (2 sites)

-   [`UserSshKeyController::updateUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L487)[`PUT /api/user/ssh-keys/{id}`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#put-user-ssh-keys-id)
-   [`UserSshKeyController::restoreUserSshKey`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/UserSshKeyController.php#L666)[`POST /api/user/ssh-keys/{id}/restore`](https://featherpanel.com/docs/api/reference/user/ssh-keys/#post-user-ssh-keys-id-restore)

```php
$event->on(UserEvent::onUserSshKeyUpdated(), function ($userUuid, $sshKey, ...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:ssh_key:updated');
});
```

## `UserEvent::onUserUpdate()`

- Name: `featherpanel:user:update`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L51)

Docblock: string user uuid.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |

When it fires (1 site)

-   [`SessionController::put`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/User/SessionController.php#L329)[`PATCH /api/user/session`](https://featherpanel.com/docs/api/reference/user/session/#patch-user-session)

```php
$event->on(UserEvent::onUserUpdate(), function ($userUuid): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:update ' . json_encode(['user_uuid' => $userUuid]));
});
```

## `UserEvent::onUserUpdated()`

- Name: `featherpanel:user:updated`
- emitted at 4 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/UserEvent.php#L91)

Docblock: array user data, array updated data, array updated by.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user` | `$user` | `array`from docblock |
| 2 | `updated_data` | `$updatedData` | `array` |
| 3 | `updated_by` | `$updatedBy` | `array`from docblock |

When it fires (4 sites)

-   [`UsersController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/UsersController.php#L997)[`PATCH /api/admin/users/{uuid}`](https://featherpanel.com/docs/api/reference/admin/users/#patch-admin-users-uuid)
-   [`UsersController::forceVerifyEmail`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/UsersController.php#L1870)[`POST /api/admin/users/{uuid}/verify-email`](https://featherpanel.com/docs/api/reference/admin/users/#post-admin-users-uuid-verify-email)
-   [`UsersController::ban`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/UsersController.php#L1958)[`POST /api/admin/users/{uuid}/ban`](https://featherpanel.com/docs/api/reference/admin/users/#post-admin-users-uuid-ban)
-   [`UsersController::unban`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/UsersController.php#L2044)[`POST /api/admin/users/{uuid}/unban`](https://featherpanel.com/docs/api/reference/admin/users/#post-admin-users-uuid-unban)

```php
$event->on(UserEvent::onUserUpdated(), function ($user, $updatedData, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:updated ' . json_encode(['user' => $user, 'updated_data' => $updatedData, 'updated_by' => $updatedBy]));
});
```
