create user login activities

This commit is contained in:
Geriano
2022-07-29 20:14:58 +07:00
parent 0d77e4ba33
commit 96b732cb5f
7 changed files with 498 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Listeners;
use App\Models\Login;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use hisorange\BrowserDetect\Facade as Browser;
class SaveUserLoginIpBrowserAndPlatform
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
Login::create([
'user_id' => $event->user->id,
'ip_address' => request()->ip(),
'browser' => Browser::browserName(),
'platform' => Browser::platformName(),
]);
}
}

26
app/Models/Login.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Login extends Model
{
use HasFactory;
/**
* @var string
*/
protected $table = 'login_activities';
/**
* @var string[]
*/
protected $fillable = [
'user_id',
'ip_address',
'browser',
'platform',
];
}

View File

@@ -2,6 +2,7 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Auth\Events\Login;
use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@@ -18,6 +19,10 @@ class EventServiceProvider extends ServiceProvider
Registered::class => [ Registered::class => [
SendEmailVerificationNotification::class, SendEmailVerificationNotification::class,
], ],
Login::class => [
\App\Listeners\SaveUserLoginIpBrowserAndPlatform::class,
],
]; ];
/** /**

View File

@@ -8,6 +8,7 @@
"php": "^8.0.2", "php": "^8.0.2",
"beyondcode/laravel-websockets": "^1.13", "beyondcode/laravel-websockets": "^1.13",
"guzzlehttp/guzzle": "^7.2", "guzzlehttp/guzzle": "^7.2",
"hisorange/browser-detect": "^4.5",
"inertiajs/inertia-laravel": "^0.5.2", "inertiajs/inertia-laravel": "^0.5.2",
"laravel/framework": "^9.19", "laravel/framework": "^9.19",
"laravel/jetstream": "^2.9", "laravel/jetstream": "^2.9",

392
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "5b20717dc62d13de3322e30e99c69a90", "content-hash": "efd75a557d90e076b495182d7ac040aa",
"packages": [ "packages": [
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
@@ -265,6 +265,82 @@
}, },
"time": "2021-12-14T00:20:41+00:00" "time": "2021-12-14T00:20:41+00:00"
}, },
{
"name": "composer/ca-bundle",
"version": "1.3.3",
"source": {
"type": "git",
"url": "https://github.com/composer/ca-bundle.git",
"reference": "30897edbfb15e784fe55587b4f73ceefd3c4d98c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/30897edbfb15e784fe55587b4f73ceefd3c4d98c",
"reference": "30897edbfb15e784fe55587b4f73ceefd3c4d98c",
"shasum": ""
},
"require": {
"ext-openssl": "*",
"ext-pcre": "*",
"php": "^5.3.2 || ^7.0 || ^8.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.55",
"psr/log": "^1.0",
"symfony/phpunit-bridge": "^4.2 || ^5",
"symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\CaBundle\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.",
"keywords": [
"cabundle",
"cacert",
"certificate",
"ssl",
"tls"
],
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/ca-bundle/issues",
"source": "https://github.com/composer/ca-bundle/tree/1.3.3"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2022-07-20T07:14:26+00:00"
},
{ {
"name": "dasprid/enum", "name": "dasprid/enum",
"version": "1.0.3", "version": "1.0.3",
@@ -1295,6 +1371,81 @@
], ],
"time": "2022-06-20T21:43:11+00:00" "time": "2022-06-20T21:43:11+00:00"
}, },
{
"name": "hisorange/browser-detect",
"version": "4.5.2",
"source": {
"type": "git",
"url": "https://github.com/hisorange/browser-detect.git",
"reference": "701b1f15be45118f126266166f6beea351296452"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hisorange/browser-detect/zipball/701b1f15be45118f126266166f6beea351296452",
"reference": "701b1f15be45118f126266166f6beea351296452",
"shasum": ""
},
"require": {
"jaybizzle/crawler-detect": "~1.2",
"league/pipeline": "^1.0",
"matomo/device-detector": "^4.0 || ^5.0 || ^6.0",
"mobiledetect/mobiledetectlib": "~2.8",
"php": "^7.2 || ^8.0",
"ua-parser/uap-php": "~3.9"
},
"require-dev": {
"orchestra/testbench": "~4.0 || ~5.0 || ~6.0 || ~7.0",
"php-coveralls/php-coveralls": "~1.0 || ~2.0",
"phpstan/phpstan": "^0.12.11",
"phpunit/phpunit": "~5.0 || ~6.0 || ~7.0 || ~8.0 || ~9.0",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"hisorange\\BrowserDetect\\ServiceProvider"
],
"aliases": {
"Browser": "hisorange\\BrowserDetect\\Facade"
}
}
},
"autoload": {
"psr-4": {
"hisorange\\BrowserDetect\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Varga Zsolt (hisorange)",
"email": "hello@hisorange.me"
}
],
"description": "Browser & Mobile detection package for Laravel.",
"homepage": "https://github.com/hisorange/browser-detect",
"keywords": [
"analyse",
"browser",
"detect",
"hisorange",
"laravel",
"mobile",
"php",
"tablet",
"user agent",
"user-agent"
],
"support": {
"issues": "https://github.com/hisorange/browser-detect/issues",
"source": "https://github.com/hisorange/browser-detect/tree/4.5.2"
},
"time": "2022-07-12T10:31:47+00:00"
},
{ {
"name": "inertiajs/inertia-laravel", "name": "inertiajs/inertia-laravel",
"version": "v0.5.4", "version": "v0.5.4",
@@ -2333,6 +2484,132 @@
], ],
"time": "2022-04-17T13:12:02+00:00" "time": "2022-04-17T13:12:02+00:00"
}, },
{
"name": "league/pipeline",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/pipeline.git",
"reference": "aa14b0e3133121f8be39e9a3b6ddd011fc5bb9a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/pipeline/zipball/aa14b0e3133121f8be39e9a3b6ddd011fc5bb9a8",
"reference": "aa14b0e3133121f8be39e9a3b6ddd011fc5bb9a8",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"leanphp/phpspec-code-coverage": "^4.2",
"phpspec/phpspec": "^4.3"
},
"type": "library",
"autoload": {
"psr-4": {
"League\\Pipeline\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frank de Jonge",
"email": "info@frenky.net",
"role": "Author"
},
{
"name": "Woody Gilk",
"email": "woody.gilk@gmail.com",
"role": "Maintainer"
}
],
"description": "A plug and play pipeline implementation.",
"keywords": [
"composition",
"design pattern",
"pattern",
"pipeline",
"sequential"
],
"support": {
"issues": "https://github.com/thephpleague/pipeline/issues",
"source": "https://github.com/thephpleague/pipeline/tree/master"
},
"time": "2018-06-05T21:06:51+00:00"
},
{
"name": "matomo/device-detector",
"version": "6.0.2",
"source": {
"type": "git",
"url": "https://github.com/matomo-org/device-detector.git",
"reference": "c01910dde14c95708019513ea0ee36c5a174fd4c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/c01910dde14c95708019513ea0ee36c5a174fd4c",
"reference": "c01910dde14c95708019513ea0ee36c5a174fd4c",
"shasum": ""
},
"require": {
"mustangostang/spyc": "*",
"php": "^7.2|^8.0"
},
"replace": {
"piwik/device-detector": "self.version"
},
"require-dev": {
"matthiasmullie/scrapbook": "^1.4.7",
"mayflower/mo4-coding-standard": "^v8.0.0",
"phpstan/phpstan": "^0.12.52",
"phpunit/phpunit": "^8.5.8",
"psr/cache": "^1.0.1",
"psr/simple-cache": "^1.0.1",
"symfony/yaml": "^5.1.7"
},
"suggest": {
"doctrine/cache": "Can directly be used for caching purpose",
"ext-yaml": "Necessary for using the Pecl YAML parser"
},
"type": "library",
"autoload": {
"psr-4": {
"DeviceDetector\\": ""
},
"exclude-from-classmap": [
"Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "The Matomo Team",
"email": "hello@matomo.org",
"homepage": "https://matomo.org/team/"
}
],
"description": "The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.",
"homepage": "https://matomo.org",
"keywords": [
"devicedetection",
"parser",
"useragent"
],
"support": {
"forum": "https://forum.matomo.org/",
"issues": "https://github.com/matomo-org/device-detector/issues",
"source": "https://github.com/matomo-org/matomo",
"wiki": "https://dev.matomo.org/"
},
"time": "2022-07-12T07:49:25+00:00"
},
{ {
"name": "mobiledetect/mobiledetectlib", "name": "mobiledetect/mobiledetectlib",
"version": "2.8.39", "version": "2.8.39",
@@ -2493,6 +2770,56 @@
], ],
"time": "2022-06-09T08:59:12+00:00" "time": "2022-06-09T08:59:12+00:00"
}, },
{
"name": "mustangostang/spyc",
"version": "0.6.3",
"source": {
"type": "git",
"url": "git@github.com:mustangostang/spyc.git",
"reference": "4627c838b16550b666d15aeae1e5289dd5b77da0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mustangostang/spyc/zipball/4627c838b16550b666d15aeae1e5289dd5b77da0",
"reference": "4627c838b16550b666d15aeae1e5289dd5b77da0",
"shasum": ""
},
"require": {
"php": ">=5.3.1"
},
"require-dev": {
"phpunit/phpunit": "4.3.*@dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.5.x-dev"
}
},
"autoload": {
"files": [
"Spyc.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "mustangostang",
"email": "vlad.andersen@gmail.com"
}
],
"description": "A simple YAML loader/dumper class for PHP",
"homepage": "https://github.com/mustangostang/spyc/",
"keywords": [
"spyc",
"yaml",
"yml"
],
"time": "2019-09-10T13:16:29+00:00"
},
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "2.59.1", "version": "2.59.1",
@@ -7091,6 +7418,69 @@
}, },
"time": "2021-12-08T09:12:39+00:00" "time": "2021-12-08T09:12:39+00:00"
}, },
{
"name": "ua-parser/uap-php",
"version": "v3.9.14",
"source": {
"type": "git",
"url": "https://github.com/ua-parser/uap-php.git",
"reference": "b796c5ea5df588e65aeb4e2c6cce3811dec4fed6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ua-parser/uap-php/zipball/b796c5ea5df588e65aeb4e2c6cce3811dec4fed6",
"reference": "b796c5ea5df588e65aeb4e2c6cce3811dec4fed6",
"shasum": ""
},
"require": {
"composer/ca-bundle": "^1.1",
"php": "^7.2 || ^8.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.33",
"phpunit/phpunit": "^8 || ^9",
"symfony/console": "^3.4 || ^4.2 || ^4.3 || ^5.0",
"symfony/filesystem": "^3.4 || ^4.2 || ^4.3 || ^5.0",
"symfony/finder": "^3.4 || ^4.2 || ^4.3 || ^5.0",
"symfony/yaml": "^3.4 || ^4.2 || ^4.3 || ^5.0",
"vimeo/psalm": "^3.12"
},
"suggest": {
"symfony/console": "Required for CLI usage - ^3.4 || ^4.3 || ^5.0",
"symfony/filesystem": "Required for CLI usage - ^3.4 || ^4.3 || ^5.0",
"symfony/finder": "Required for CLI usage - ^3.4 || ^4.3 || ^5.0",
"symfony/yaml": "Required for CLI usage - ^3.4 || ^4.3 || ^5.0"
},
"bin": [
"bin/uaparser"
],
"type": "library",
"autoload": {
"psr-4": {
"UAParser\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dave Olsen",
"email": "dmolsen@gmail.com"
},
{
"name": "Lars Strojny",
"email": "lars@strojny.net"
}
],
"description": "A multi-language port of Browserscope's user agent parser.",
"support": {
"issues": "https://github.com/ua-parser/uap-php/issues",
"source": "https://github.com/ua-parser/uap-php/tree/v3.9.14"
},
"time": "2020-10-02T23:36:20+00:00"
},
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",
"version": "v5.4.1", "version": "v5.4.1",

View File

@@ -197,6 +197,7 @@ return [
App\Providers\FortifyServiceProvider::class, App\Providers\FortifyServiceProvider::class,
App\Providers\JetstreamServiceProvider::class, App\Providers\JetstreamServiceProvider::class,
\hisorange\BrowserDetect\ServiceProvider::class,
], ],
/* /*

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('login_activities', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')
->constrained()
->cascadeOnDelete();
$table->ipAddress();
$table->string('browser');
$table->string('platform');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('login_activities');
}
};