Skip to content

Commit

Permalink
Merge pull request #7 from binafy/add-disable-for-authentication-moni…
Browse files Browse the repository at this point in the history
…toring

[0.x] Add disable configuration for authentication monitoring
  • Loading branch information
milwad-dev authored Aug 1, 2023
2 parents b88b9d7 + 3988f8e commit 7ba89b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
6 changes: 6 additions & 0 deletions config/user-monitoring.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,11 @@
* If you want to delete authentications-monitoring rows when the user is deleted from the users table you can set true or false.
*/
'delete_user_record_when_user_delete' => true,

/*
* You can set true/false for monitor login or logout.
*/
'on_login' => true,
'on_logout' => true,
],
];
30 changes: 17 additions & 13 deletions src/Providers/LaravelUserMonitoringEventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ public function boot()
$table = config('user-monitoring.authentication_monitoring.table');

// Login Event
Event::listen(function (Login $event) use ($agent, $guard, $table) {
DB::table($table)
->insert(
$this->insertData($guard, $agent, 'login'),
);
});
if (config('user-monitoring.authentication_monitoring.on_login', false)) {
Event::listen(function (Login $event) use ($agent, $guard, $table) {
DB::table($table)
->insert(
$this->insertData($guard, $agent, 'login'),
);
});
}

// Logout Event
Event::listen(function (Logout $event) use ($agent, $guard, $table) {
DB::table($table)
->insert(
$this->insertData($guard, $agent, 'logout'),
);
});
if (config('user-monitoring.authentication_monitoring.on_logout', false)) {
Event::listen(function (Logout $event) use ($agent, $guard, $table) {
DB::table($table)
->insert(
$this->insertData($guard, $agent, 'logout'),
);
});
}
}

/**
Expand All @@ -56,4 +60,4 @@ private function insertData(string $guard, Agent $agent, string $actionType): ar
'updated_at' => now(),
];
}
}
}

0 comments on commit 7ba89b3

Please sign in to comment.