Created
October 22, 2020 10:11
-
-
Save opejovic/042591b5b5aa6ab32765a9bdd35ba541 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Listeners; | |
use App\Mail\UnknownLoginIp; | |
use Illuminate\Http\Request; | |
use Illuminate\Auth\Events\Login; | |
use Illuminate\Support\Facades\Mail; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
class CheckLoginIp | |
{ | |
/** | |
* The request instance. | |
* | |
* @var Illuminate\Http\Request | |
*/ | |
protected $request; | |
/** | |
* Create the event listener. | |
* | |
* @return void | |
*/ | |
public function __construct(Request $request) | |
{ | |
$this->request = $request; | |
} | |
/** | |
* Handle the event. | |
* | |
* @param Login $event | |
* @return void | |
*/ | |
public function handle(Login $event) | |
{ | |
$ip = $this->request->ip(); | |
$user = $event->user; | |
if ($user->knownIps()->contains($ip)) return; | |
$user->saveIp($ip); | |
Mail::to($user->email)->send(new UnknownLoginIp($user, $ip)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment