Skip to content

Commit

Permalink
Add UserUpdatedEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
partydragen committed May 2, 2024
1 parent b496a9a commit 0e6a70b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/Core/classes/Events/UserUpdatedEvent.php
@@ -0,0 +1,30 @@
<?php

class UserUpdatedEvent extends AbstractEvent implements HasWebhookParams {

public User $user;
public UserData $updated_data;

public function __construct(User $user) {
$this->user = $user;

$data = DB::getInstance()->get('users', ['id', $user->data()->id]);
$this->updated_data = new UserData($data->first());
}

public static function name(): string {
return 'updatedUser';
}

public static function description(): string {
return (new Language())->get('admin', 'user_updated_hook_info');
}

public function webhookParams(): array {
return [
'user_id' => $this->user->data()->id,
'username' => $this->user->getDisplayname(),
'profile_url' => URL::getSelfURL() . ltrim($this->user->getProfileURL(), '/')
];
}
}
1 change: 1 addition & 0 deletions modules/Core/language/en_UK.json
Expand Up @@ -3,6 +3,7 @@
"admin/user_warned_webhook": "{{punished}} has been warned by {{punisher}}.",
"admin/user_group_added_hook_info": "User Group Added",
"admin/user_group_removed_hook_info": "User Group Removed",
"admin/user_updated_hook_info": "User updated",
"admin/acp_logins": "StaffCP Logins",
"admin/action": "Action",
"admin/action_info": "Action Info",
Expand Down
1 change: 1 addition & 0 deletions modules/Core/module.php
Expand Up @@ -317,6 +317,7 @@ public function __construct(Language $language, Pages $pages, User $user, Naviga
EventHandler::registerEvent(UserProfilePostCreatedEvent::class);
EventHandler::registerEvent(UserProfilePostReplyCreatedEvent::class);
EventHandler::registerEvent(UserRegisteredEvent::class);
EventHandler::registerEvent(UserUpdatedEvent::class);
EventHandler::registerEvent(UserValidatedEvent::class);
EventHandler::registerEvent(UserWarnedEvent::class);

Expand Down
4 changes: 4 additions & 0 deletions modules/Core/pages/panel/users_edit.php
Expand Up @@ -208,6 +208,10 @@
}
}

EventHandler::executeEvent(new UserUpdatedEvent(
$view_user,
));

Session::flash('edit_user_success', $language->get('admin', 'user_updated_successfully'));
Redirect::to(URL::build('/panel/users/edit/', 'id=' . urlencode($user_query->id)));
} catch (Exception $e) {
Expand Down
12 changes: 12 additions & 0 deletions modules/Core/pages/user/settings.php
Expand Up @@ -80,6 +80,10 @@
// Logout all other sessions for this user
$user->logoutAllOtherSessions();

EventHandler::executeEvent(new UserUpdatedEvent(
$user,
));

Session::delete('force_tfa_alert');
Session::flash('tfa_success', $language->get('user', 'tfa_successful'));
Redirect::to(URL::build('/user/settings'));
Expand Down Expand Up @@ -125,6 +129,10 @@
'tfa_complete' => false
]);

EventHandler::executeEvent(new UserUpdatedEvent(
$user,
));

Session::flash('settings_success', $language->get('user', 'tfa_disabled'));
Redirect::to(URL::build('/user/settings'));
}
Expand Down Expand Up @@ -330,6 +338,10 @@
}
}

EventHandler::executeEvent(new UserUpdatedEvent(
$user,
));

Session::flash('settings_success', $language->get('user', 'settings_updated_successfully'));
Redirect::to(URL::build('/user/settings'));

Expand Down

0 comments on commit 0e6a70b

Please sign in to comment.