定制 areia-lab/laravel-login-notifier 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

areia-lab/laravel-login-notifier

最新稳定版本:v1.0.1

Composer 安装命令:

composer require areia-lab/laravel-login-notifier

包简介

Laravel package to notify users of logins from new devices or IP addresses for enhanced security.

README 文档

README

Package: areia-lab/laravel-login-notifier

A Laravel package to monitor user logins, detect new devices or IP addresses, log device and location information, and notify users and admins of suspicious or new login activity.

Features

  • Detect logins from new devices or IP addresses.
  • Send email notifications to users on new logins.
  • Send alerts to admin for every login.
  • Log device, browser, platform, IP, and geo-location.
  • Fully configurable via a config file.
  • Supports queueable notifications for production.

Requirements

This package requires the following:

  • PHP ^8.1
  • Laravel ^10.0
  • jenssegers/agent ^2.6 – device & browser detection
  • stevebauman/location ^7.0 – IP geolocation lookup

Installation

composer require areia-lab/laravel-login-notifier

Publish the configuration and migration files:

php artisan vendor:publish --tag=login-notifier-config
php artisan vendor:publish --tag=login-notifier-migrations

php artisan migrate

The migrations will create the login_histories table to store login data.

Configuration

Edit the published config file config/login-notifier.php:

return [
    'notify_user' => env('LOGIN_NOTIFIER_NOTIFY_USER', true),

    // Email address to receive admin notifications
    'notify_admin' => env('LOGIN_NOTIFIER_NOTIFY_ADMIN', true),
    'admin_email' => env('LOGIN_NOTIFIER_ADMIN_EMAIL', 'admin@example.com'),

    'secure_url' => env('LOGIN_NOTIFIER_SECURE_URL', 'forgot-password'),
];

Usage

This package works automatically on every login. You don’t need to call anything manually.

use Illuminate\Support\Facades\Auth;

Auth::attempt(['email' => 'user@example.com', 'password' => 'password']);

The following happens automatically:

  1. Login is recorded in login_histories.
  2. New device/IP detection is performed.
  3. User notification is sent if enabled.
  4. Admin notification is sent if enabled.

Access Login Histories (Facade)

The package provides a facade for querying login histories:

use AreiaLab\LoginNotifier\Facades\LoginHistory;

// Get all login histories
$all = LoginHistory::getAllHistories();

// Get recent 10 logins
$recent = LoginHistory::getRecentHistories(10);

// Get all logins for a specific user
$userLogins = LoginHistory::getUserHistories($userId);

// Get last login of a user
$lastLogin = LoginHistory::getLastLoginForUser($userId);

// Get logins from new devices for a user
$newDeviceLogins = LoginHistory::getNewDeviceLoginsForUser($userId);

Notifications

UserLoginAlert

  • Sent to users on login from a new device or IP.
  • Includes: IP, device, browser, platform, location, timestamp.
  • Includes a call-to-action button to secure the account.

AdminLoginAlert

  • Sent to admin on every login.
  • Includes user login details: IP, device, browser, location, timestamp.
  • Provides a link to review user activity in the admin dashboard.

Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the repo.
  2. Create a feature branch.
  3. Submit a Pull Request.

License

MIT License. See LICENSE for details.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-15