chore: move updateAdminHistory to AdminLog.php

This commit is contained in:
Floorb 2023-07-11 03:19:58 -04:00
parent f1b2e10c72
commit 894613e257
5 changed files with 16 additions and 20 deletions

View file

@ -26,4 +26,15 @@ class AdminLog extends Model {
public function user() { public function user() {
return $this->belongsto(User::class); return $this->belongsto(User::class);
} }
public static function updateAdminHistory(User $admin, int $action, string $message = null) : void {
$log = new AdminLog([
'user_id' => $admin->id,
'action' => $action,
'ip' => $_SERVER['REMOTE_ADDR'],
'message' => $message
]);
$log->save();
}
} }

View file

@ -331,18 +331,3 @@ function pp_setup_pagination() : array {
return [$per_page, $current_page]; return [$per_page, $current_page];
} }
function pp_output_paginator(int $per_page, int $current_page) : void {
}
function updateAdminHistory(User $admin, int $action, string $message = null) : void {
$log = new AdminLog([
'user_id' => $admin->id,
'action' => $action,
'ip' => $_SERVER['REMOTE_ADDR'],
'message' => $message
]);
$log->save();
}

View file

@ -88,7 +88,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</div>'; </div>';
} }
updateAdminHistory($current_user, AdminLog::ACTION_EDIT_CONFIG); AdminLog::updateAdminHistory($current_user, AdminLog::ACTION_EDIT_CONFIG);
} }
?> ?>

View file

@ -19,7 +19,7 @@ $flashes = getFlashes();
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (pp_password_verify($_POST['password'], $current_user->admin_password_hash)) { if (pp_password_verify($_POST['password'], $current_user->admin_password_hash)) {
updateAdminHistory($current_user, AdminLog::ACTION_LOGIN); AdminLog::updateAdminHistory($current_user, AdminLog::ACTION_LOGIN);
$_SESSION['admin_login'] = true; $_SESSION['admin_login'] = true;
if (isset($_SESSION['redirect_back'])) { if (isset($_SESSION['redirect_back'])) {
flashSuccess('You have been logged in. Please try your action again.'); flashSuccess('You have been logged in. Please try your action again.');
@ -29,7 +29,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
} }
exit(); exit();
} else { } else {
updateAdminHistory($current_user, AdminLog::ACTION_FAIL_LOGIN); AdminLog::updateAdminHistory($current_user, AdminLog::ACTION_FAIL_LOGIN);
$msg = '<div class="paste-alert alert6" style="text-align:center;"> $msg = '<div class="paste-alert alert6" style="text-align:center;">
Wrong Password Wrong Password
</div>'; </div>';

View file

@ -35,7 +35,7 @@ if (isset($_POST['hide'])) {
$paste->save(); $paste->save();
$redis->del('ajax_pastes'); /* Expire from Redis so it doesn't show up anymore */ $redis->del('ajax_pastes'); /* Expire from Redis so it doesn't show up anymore */
updateAdminHistory($current_user, AdminLog::ACTION_HIDE_PASTE, 'Paste ' . $paste->id . ' ' . ($is_hidden ? 'hidden' : 'unhidden') . '.'); AdminLog::updateAdminHistory($current_user, AdminLog::ACTION_HIDE_PASTE, 'Paste ' . $paste->id . ' ' . ($is_hidden ? 'hidden' : 'unhidden') . '.');
flashSuccess('Paste ' . ($is_hidden ? 'hidden' : 'unhidden') . '.'); flashSuccess('Paste ' . ($is_hidden ? 'hidden' : 'unhidden') . '.');
} }
@ -51,7 +51,7 @@ if (isset($_POST['hide'])) {
$paste->save(); $paste->save();
$redis->del('ajax_pastes'); /* Expire from Redis so it doesn't show up anymore */ $redis->del('ajax_pastes'); /* Expire from Redis so it doesn't show up anymore */
updateAdminHistory($current_user, AdminLog::ACTION_BLANK_PASTE, 'Paste ' . $paste->id . 'blanked.'); AdminLog::updateAdminHistory($current_user, AdminLog::ACTION_BLANK_PASTE, 'Paste ' . $paste->id . 'blanked.');
flashSuccess('Paste contents blanked.'); flashSuccess('Paste contents blanked.');
} }