From 894613e2577e4edc14ecc300277464a570843f80 Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Tue, 11 Jul 2023 03:19:58 -0400 Subject: [PATCH] chore: move updateAdminHistory to AdminLog.php --- includes/Models/AdminLog.php | 11 +++++++++++ includes/functions.php | 15 --------------- public/admin/configuration.php | 2 +- public/admin/index.php | 4 ++-- public/admin/paste_action.php | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/includes/Models/AdminLog.php b/includes/Models/AdminLog.php index 750d08a..0c9df6a 100644 --- a/includes/Models/AdminLog.php +++ b/includes/Models/AdminLog.php @@ -26,4 +26,15 @@ class AdminLog extends Model { public function user() { 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(); + } } diff --git a/includes/functions.php b/includes/functions.php index 4fc8fe6..4e8076e 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -331,18 +331,3 @@ function pp_setup_pagination() : array { 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(); -} \ No newline at end of file diff --git a/public/admin/configuration.php b/public/admin/configuration.php index 026778e..ffcdb36 100644 --- a/public/admin/configuration.php +++ b/public/admin/configuration.php @@ -88,7 +88,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { '; } - updateAdminHistory($current_user, AdminLog::ACTION_EDIT_CONFIG); + AdminLog::updateAdminHistory($current_user, AdminLog::ACTION_EDIT_CONFIG); } ?> diff --git a/public/admin/index.php b/public/admin/index.php index 06ec3a8..05008b1 100644 --- a/public/admin/index.php +++ b/public/admin/index.php @@ -19,7 +19,7 @@ $flashes = getFlashes(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { 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; if (isset($_SESSION['redirect_back'])) { flashSuccess('You have been logged in. Please try your action again.'); @@ -29,7 +29,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { } exit(); } else { - updateAdminHistory($current_user, AdminLog::ACTION_FAIL_LOGIN); + AdminLog::updateAdminHistory($current_user, AdminLog::ACTION_FAIL_LOGIN); $msg = '