jslmariano / basic-authentication-log
Laravel 认证日志提供 Laravel 的认证日志记录和通知功能。
Requires
- php: >=7.0
- illuminate/auth: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/bus: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/console: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/contracts: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/database: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/http: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/notifications: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/support: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
Requires (Dev)
- orchestra/testbench: ^3.5|^4.0|^5.0
- phpunit/phpunit: ^6.0|^7.0|^8.0
Suggests
- guzzlehttp/guzzle: Required to use the Slack transport (~6.0)
- nexmo/client: Required to use the Nexmo transport (~1.0).
This package is not auto-updated.
Last update: 2024-09-21 01:08:26 UTC
README
安装
Laravel 认证日志需要 Laravel 5.5 或更高版本,以及 PHP 7.0+。
您可以使用 Composer 将 Laravel 认证日志安装到您的 Laravel 项目中
composer require jslmariano/basic-authentication-log
配置
安装 Laravel 认证日志后,使用 vendor:publish
Artisan 命令发布其配置、迁移和视图
php artisan vendor:publish --provider="Jslmariano\AuthenticationLog\AuthenticationLogServiceProvider"
接下来,您需要迁移数据库。Laravel 认证日志迁移将创建应用程序存储认证日志所需的数据表
php artisan migrate
最后,将 AuthenticationLogable
和 Notifiable
特性添加到您的认证模型中(默认为 App\User
模型)。这些特性提供了各种方法,允许您获取常见的认证日志数据,例如最后登录时间、最后登录 IP 地址,并设置通知渠道,以便在从新设备登录时通知用户
use Illuminate\Notifications\Notifiable; use Jslmariano\AuthenticationLog\AuthenticationLogable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable, AuthenticationLogable; }
基本用法
获取用户的所有认证日志
User::find(1)->authentications;
获取用户的最后登录信息
User::find(1)->lastLoginAt(); User::find(1)->lastLoginIp();
获取用户的先前登录时间及 IP 地址(忽略当前登录)
auth()->user()->previousLoginAt(); auth()->user()->previousLoginIp();
通知从新设备登录
通知可以通过 mail
、nexmo
和 slack
渠道发送。默认通过电子邮件通知。
您可以通过定义 notifyAuthenticationLogVia
方法来决定通知应通过哪些渠道发送
/** * The Authentication Log notifications delivery channels. * * @return array */ public function notifyAuthenticationLogVia() { return ['nexmo', 'mail', 'slack']; }
当然,您可以通过在 config/authentication-log.php
配置文件中将 notify
选项设置为 false
来禁用通知
'notify' => env('AUTHENTICATION_LOG_NOTIFY', false),
清除旧日志
您可以使用 authentication-log:clear
Artisan 命令清除旧的认证日志记录
php artisan authentication-log:clear
将删除在您的 config/authentication-log.php
中的 older
选项指定的天数之前创建的记录
'older' => 365,
贡献
感谢您考虑为 Laravel 认证日志做出贡献。
许可证
Laravel 认证日志是开源软件,许可协议为 MIT 协议。