PHP code example of siberfx / authentication-logger

1. Go to this page and download the library: Download siberfx/authentication-logger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

siberfx / authentication-logger example snippets


return [
    // The database table name
    // You can change this if the database keys get too long for your driver
    'table_name' => 'authentication_log',

    'notifications' => [
        'new-device' => [
            // Send the NewDevice notification
            'enabled' => env('NEW_DEVICE_NOTIFICATION', true),

            // Use torann/geoip to attempt to get a location
            'location' => true,

            // The Notification class to send
            'template' => \Siberfx\AuthenticationLogger\Notifications\NewDevice::class,
        ],
        'failed-login' => [
            // Send the FailedLogin notification
            'enabled' => env('FAILED_LOGIN_NOTIFICATION', false),

            // Use torann/geoip to attempt to get a location
            'location' => true,

            // The Notification class to send
            'template' => \Siberfx\AuthenticationLogger\Notifications\FailedLogin::class,
        ],
    ],

    // When the clean-up command is run, delete old logs greater than `purge` days
    // Don't schedule the clean-up command if you want to keep logs forever.
    'purge' => 60,
];

use Illuminate\Notifications\Notifiable;
use Siberfx\AuthenticationLogger\Traits\AuthenticationLoggable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable, AuthenticationLoggable;
}

User::find(1)->authentications;

User::find(1)->lastLoginAt();

User::find(1)->lastSuccessfulLoginAt();

User::find(1)->lastLoginIp();

User::find(1)->lastSuccessfulLoginIp();

auth()->user()->previousLoginAt();

auth()->user()->previousLoginIp();

public function notifyAuthenticationLogVia()
{
    return ['nexmo', 'mail', 'slack'];
}

'purge' => 60,

$schedule->command('model:prune')->daily();

use Illuminate\Support\ServiceProvider;
use Illuminate\Auth\Events\Failed;
use Illuminate\Auth\Events\Login;
use Illuminate\Auth\Events\Logout;
use Siberfx\AuthenticationLogger\Listeners\FailedLoginListener;
use Siberfx\AuthenticationLogger\Listeners\LoginListener;
use Siberfx\AuthenticationLogger\Listeners\LogoutListener;
use Siberfx\AuthenticationLogger\Listeners\OtherDeviceLogoutListener;


        $events->listen(Login::class, LoginListener::class);
        $events->listen(Failed::class, FailedLoginListener::class);
        $events->listen(Logout::class, LogoutListener::class);
        $events->listen(OtherDeviceLogout::class, OtherDeviceLogoutListener::class);
bash
php artisan vendor:publish --provider="Siberfx\AuthenticationLogger\AuthenticationLogServiceProviderger" --tag="authentication-log-migrations"
php artisan migrate
bash
php artisan vendor:publish --provider="Siberfx\AuthenticationLogger\AuthenticationLogServiceProviderger" --tag="authentication-log-views"
bash
php artisan vendor:publish --provider="Siberfx\AuthenticationLogger\AuthenticationLogServiceProviderger" --tag="authentication-log-config"

php artisan vendor:publish --provider="Torann\GeoIP\GeoIPServiceProvider" --tag=config