Skip to content

Commit 7ba89b3

Browse files
authored
Merge pull request #7 from binafy/add-disable-for-authentication-monitoring
[0.x] Add disable configuration for authentication monitoring
2 parents b88b9d7 + 3988f8e commit 7ba89b3

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

config/user-monitoring.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,11 @@
6464
* If you want to delete authentications-monitoring rows when the user is deleted from the users table you can set true or false.
6565
*/
6666
'delete_user_record_when_user_delete' => true,
67+
68+
/*
69+
* You can set true/false for monitor login or logout.
70+
*/
71+
'on_login' => true,
72+
'on_logout' => true,
6773
],
6874
];

src/Providers/LaravelUserMonitoringEventServiceProvider.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@ public function boot()
1818
$table = config('user-monitoring.authentication_monitoring.table');
1919

2020
// Login Event
21-
Event::listen(function (Login $event) use ($agent, $guard, $table) {
22-
DB::table($table)
23-
->insert(
24-
$this->insertData($guard, $agent, 'login'),
25-
);
26-
});
21+
if (config('user-monitoring.authentication_monitoring.on_login', false)) {
22+
Event::listen(function (Login $event) use ($agent, $guard, $table) {
23+
DB::table($table)
24+
->insert(
25+
$this->insertData($guard, $agent, 'login'),
26+
);
27+
});
28+
}
2729

2830
// Logout Event
29-
Event::listen(function (Logout $event) use ($agent, $guard, $table) {
30-
DB::table($table)
31-
->insert(
32-
$this->insertData($guard, $agent, 'logout'),
33-
);
34-
});
31+
if (config('user-monitoring.authentication_monitoring.on_logout', false)) {
32+
Event::listen(function (Logout $event) use ($agent, $guard, $table) {
33+
DB::table($table)
34+
->insert(
35+
$this->insertData($guard, $agent, 'logout'),
36+
);
37+
});
38+
}
3539
}
3640

3741
/**
@@ -56,4 +60,4 @@ private function insertData(string $guard, Agent $agent, string $actionType): ar
5660
'updated_at' => now(),
5761
];
5862
}
59-
}
63+
}

0 commit comments

Comments
 (0)