diff --git a/modules/backend/controllers/Auth.php b/modules/backend/controllers/Auth.php index 4254da550..47626a62a 100644 --- a/modules/backend/controllers/Auth.php +++ b/modules/backend/controllers/Auth.php @@ -7,6 +7,7 @@ use Redirect; use Validator; use BackendAuth; use Backend\Models\User; +use Backend\Models\AccessLog; use Backend\Classes\Controller; use System\Classes\VersionManager; use System\Classes\ApplicationException; @@ -73,6 +74,9 @@ class Auth extends Controller 'password' => post('password') ], true); + // Log the sign in event + AccessLog::add($user); + // Load version updates VersionManager::instance()->updateAll(); diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 2a7b765b7..ea0d4970a 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -16,9 +16,10 @@ use Twig_Environment; use Controller as BaseController; use Cms\Twig\Loader as TwigLoader; use Cms\Twig\Extension as CmsTwigExtension; -use System\Twig\Extension as SystemTwigExtension; use Cms\Classes\FileHelper as CmsFileHelper; +use System\Models\RequestLog; use System\Classes\ErrorHandler; +use System\Twig\Extension as SystemTwigExtension; use October\Rain\Support\Markdown; use October\Rain\Support\ValidationException; use Illuminate\Http\RedirectResponse; @@ -141,6 +142,9 @@ class Controller extends BaseController if (!$page) { $this->setStatusCode(404); + // Log the 404 request + RequestLog::add(); + if (!$page = $this->router->findByUrl('/404')) return Response::make(View::make('cms::404'), $this->statusCode); } diff --git a/modules/system/models/RequestLog.php b/modules/system/models/RequestLog.php index 679e00829..afe948a78 100644 --- a/modules/system/models/RequestLog.php +++ b/modules/system/models/RequestLog.php @@ -23,11 +23,12 @@ class RequestLog extends Model * Creates a log record * @return self */ - public static function add() + public static function add($statusCode = 404) { $record = static::firstOrNew([ 'url' => Request::fullUrl(), 'referer' => Request::header('referer'), + 'status_code' => $statusCode, ]); if (!$record->exists) { diff --git a/modules/system/models/requestlog/columns.yaml b/modules/system/models/requestlog/columns.yaml index b1cd76aa8..41395e974 100644 --- a/modules/system/models/requestlog/columns.yaml +++ b/modules/system/models/requestlog/columns.yaml @@ -3,6 +3,10 @@ # =================================== columns: + status_code: + label: Status + searchable: yes + url: label: URL searchable: yes