mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Added login log
This commit is contained in:
parent
bf761946da
commit
0f85d6810b
46
app/Listeners/LogFailedLogin.php
Normal file
46
app/Listeners/LogFailedLogin.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Events\Failed;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use DB;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class LogFailedLogin
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Auth\Events\Failed $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(Failed $event)
|
||||||
|
{
|
||||||
|
$now = new Carbon();
|
||||||
|
try {
|
||||||
|
DB::table('login_attempts')->insert(
|
||||||
|
[
|
||||||
|
'username' => $event->credentials['username'],
|
||||||
|
'user_agent' => request()->header('User-Agent'),
|
||||||
|
'remote_ip' => request()->ip(),
|
||||||
|
'successful' => 0,
|
||||||
|
'created_at' => $now;
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\Log::debug($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
49
app/Listeners/LogSuccessfulLogin.php
Normal file
49
app/Listeners/LogSuccessfulLogin.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Events\Login;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use DB;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class LogSuccessfulLogin
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create the event listener.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param Login $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(Login $event)
|
||||||
|
{
|
||||||
|
$now = new Carbon();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
DB::table('login_attempts')->insert(
|
||||||
|
[
|
||||||
|
'username' => $event->user->username,
|
||||||
|
'user_agent' => request()->header('User-Agent'),
|
||||||
|
'remote_ip' => request()->ip(),
|
||||||
|
'successful' => 1,
|
||||||
|
'created_at' => $now
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\Log::debug($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,10 +13,16 @@ class EventServiceProvider extends ServiceProvider
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $listen = [
|
protected $listen = [
|
||||||
'App\Events\SomeEvent' => [
|
|
||||||
'App\Listeners\EventListener',
|
'Illuminate\Auth\Events\Login' => [
|
||||||
],
|
'App\Listeners\LogSuccessfulLogin',
|
||||||
];
|
],
|
||||||
|
|
||||||
|
'Illuminate\Auth\Events\Failed' => [
|
||||||
|
'App\Listeners\LogFailedLogin',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register any events for your application.
|
* Register any events for your application.
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateLoginAttemptsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('login_attempts', function (Blueprint $table) {
|
||||||
|
$table->increments('id');
|
||||||
|
$table->string('username')->nullable()->default(null);
|
||||||
|
$table->ipAddress('remote_ip')->nullable()->default(null);
|
||||||
|
$table->string('user_agent')->nullable()->default(null);
|
||||||
|
$table->boolean('successful')->nullable()->default(null);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('login_attempts');
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'activated_help_text' => 'This user can login',
|
||||||
|
'activated_disabled_help_text' => 'You cannot edit activation status for your own account.',
|
||||||
'assets_user' => 'Assets assigned to :name',
|
'assets_user' => 'Assets assigned to :name',
|
||||||
'bulk_update_warn' => 'You are about to edit the properties of :user_count users. Please note that you cannot change your own user attributes using this form, and must make edits to your own user individually.',
|
'bulk_update_warn' => 'You are about to edit the properties of :user_count users. Please note that you cannot change your own user attributes using this form, and must make edits to your own user individually.',
|
||||||
'bulk_update_help' => 'This form allows you to update multiple users at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged.',
|
'bulk_update_help' => 'This form allows you to update multiple users at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged.',
|
||||||
|
|
|
@ -51,7 +51,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label>
|
<label>
|
||||||
<input name="remember" type="checkbox" value="Remember Me">{{ trans('auth/general.remember_me') }}
|
<input name="remember" type="checkbox" value="1">{{ trans('auth/general.remember_me') }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
Loading…
Reference in a new issue