From 96b732cb5f07ec9e11aee533b21a09c36c6d1181 Mon Sep 17 00:00:00 2001 From: Geriano Date: Fri, 29 Jul 2022 20:14:58 +0700 Subject: [PATCH] create user login activities --- .../SaveUserLoginIpBrowserAndPlatform.php | 37 ++ app/Models/Login.php | 26 ++ app/Providers/EventServiceProvider.php | 5 + composer.json | 1 + composer.lock | 392 +++++++++++++++++- config/app.php | 1 + .../2022_07_29_123750_create_logins_table.php | 37 ++ 7 files changed, 498 insertions(+), 1 deletion(-) create mode 100644 app/Listeners/SaveUserLoginIpBrowserAndPlatform.php create mode 100644 app/Models/Login.php create mode 100644 database/migrations/2022_07_29_123750_create_logins_table.php diff --git a/app/Listeners/SaveUserLoginIpBrowserAndPlatform.php b/app/Listeners/SaveUserLoginIpBrowserAndPlatform.php new file mode 100644 index 0000000..6ec1244 --- /dev/null +++ b/app/Listeners/SaveUserLoginIpBrowserAndPlatform.php @@ -0,0 +1,37 @@ + $event->user->id, + 'ip_address' => request()->ip(), + 'browser' => Browser::browserName(), + 'platform' => Browser::platformName(), + ]); + } +} diff --git a/app/Models/Login.php b/app/Models/Login.php new file mode 100644 index 0000000..1faa9b0 --- /dev/null +++ b/app/Models/Login.php @@ -0,0 +1,26 @@ + [ SendEmailVerificationNotification::class, ], + + Login::class => [ + \App\Listeners\SaveUserLoginIpBrowserAndPlatform::class, + ], ]; /** diff --git a/composer.json b/composer.json index 7462a78..79c12da 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "php": "^8.0.2", "beyondcode/laravel-websockets": "^1.13", "guzzlehttp/guzzle": "^7.2", + "hisorange/browser-detect": "^4.5", "inertiajs/inertia-laravel": "^0.5.2", "laravel/framework": "^9.19", "laravel/jetstream": "^2.9", diff --git a/composer.lock b/composer.lock index 264b6dc..b178cce 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5b20717dc62d13de3322e30e99c69a90", + "content-hash": "efd75a557d90e076b495182d7ac040aa", "packages": [ { "name": "bacon/bacon-qr-code", @@ -265,6 +265,82 @@ }, "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", "version": "1.0.3", @@ -1295,6 +1371,81 @@ ], "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", "version": "v0.5.4", @@ -2333,6 +2484,132 @@ ], "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", "version": "2.8.39", @@ -2493,6 +2770,56 @@ ], "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", "version": "2.59.1", @@ -7091,6 +7418,69 @@ }, "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", "version": "v5.4.1", diff --git a/config/app.php b/config/app.php index d12590f..6484af0 100644 --- a/config/app.php +++ b/config/app.php @@ -197,6 +197,7 @@ return [ App\Providers\FortifyServiceProvider::class, App\Providers\JetstreamServiceProvider::class, + \hisorange\BrowserDetect\ServiceProvider::class, ], /* diff --git a/database/migrations/2022_07_29_123750_create_logins_table.php b/database/migrations/2022_07_29_123750_create_logins_table.php new file mode 100644 index 0000000..0cb66ea --- /dev/null +++ b/database/migrations/2022_07_29_123750_create_logins_table.php @@ -0,0 +1,37 @@ +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'); + } +};