1 | <?php |
||||||
2 | |||||||
3 | namespace Yadahan\AuthenticationLog\Listeners; |
||||||
4 | |||||||
5 | use Illuminate\Auth\Events\Login; |
||||||
6 | use Illuminate\Http\Request; |
||||||
7 | use Illuminate\Support\Carbon; |
||||||
8 | use Yadahan\AuthenticationLog\AuthenticationLog; |
||||||
9 | use Yadahan\AuthenticationLog\Notifications\NewDevice; |
||||||
10 | |||||||
11 | class LogSuccessfulLogin |
||||||
12 | { |
||||||
13 | /** |
||||||
14 | * The request. |
||||||
15 | * |
||||||
16 | * @var \Illuminate\Http\Request |
||||||
17 | */ |
||||||
18 | public $request; |
||||||
19 | |||||||
20 | /** |
||||||
21 | * Create the event listener. |
||||||
22 | * |
||||||
23 | * @param \Illuminate\Http\Request $request |
||||||
24 | * @return void |
||||||
25 | */ |
||||||
26 | public function __construct(Request $request) |
||||||
27 | { |
||||||
28 | $this->request = $request; |
||||||
29 | } |
||||||
30 | |||||||
31 | /** |
||||||
32 | * Handle the event. |
||||||
33 | * |
||||||
34 | * @param Login $event |
||||||
35 | * @return void |
||||||
36 | */ |
||||||
37 | public function handle(Login $event) |
||||||
38 | { |
||||||
39 | $user = $event->user; |
||||||
40 | $ip = $this->request->ip(); |
||||||
41 | $userAgent = $this->request->userAgent(); |
||||||
42 | $known = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first(); |
||||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
43 | $newUser = Carbon::parse($user->{$user->getCreatedAtColumn()})->diffInMinutes(Carbon::now()) < 1; |
||||||
44 | |||||||
45 | $authenticationLog = new AuthenticationLog([ |
||||||
46 | 'ip_address' => $ip, |
||||||
47 | 'user_agent' => $userAgent, |
||||||
48 | 'login_at' => Carbon::now(), |
||||||
49 | ]); |
||||||
50 | |||||||
51 | $user->authentications()->save($authenticationLog); |
||||||
52 | |||||||
53 | if (! $known && ! $newUser && config('authentication-log.notify')) { |
||||||
54 | $user->notify(new NewDevice($authenticationLog)); |
||||||
0 ignored issues
–
show
The method
notify() does not exist on Illuminate\Contracts\Auth\Authenticatable . It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
55 | } |
||||||
56 | } |
||||||
57 | } |
||||||
58 |