Conditions | 4 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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(); |
||
|
|||
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)); |
||
55 | } |
||
58 |