2022-03-10 13:20:23 -08:00
< ? php
namespace App\Console\Commands ;
use Illuminate\Console\Command ;
class KillAllSessions extends Command
{
/**
* The name and signature of the console command .
*
* @ var string
*/
2022-03-10 13:30:03 -08:00
protected $signature = 'snipeit:global-logout {--force : Skip the danger prompt; assuming you enter "y"} ' ;
2022-03-10 13:20:23 -08:00
/**
* The console command description .
*
* @ var string
*/
protected $description = 'This command will destroy all web sessions on disk and will force a re-login for all users.' ;
/**
* Create a new command instance .
*
* @ return void
*/
public function __construct ()
{
parent :: __construct ();
}
/**
* Execute the console command .
*
* @ return mixed
*/
public function handle ()
{
2022-03-10 13:30:03 -08:00
if ( ! $this -> option ( 'force' ) && ! $this -> confirm ( " **************************************************** \n THIS WILL FORCE A LOGIN FOR ALL LOGGED IN USERS. \n \n Are you SURE you wish to continue? " )) {
return $this -> error ( " Session loss not confirmed " );
}
2022-03-10 13:20:23 -08:00
2022-03-10 13:30:03 -08:00
$session_files = glob ( storage_path ( " framework/sessions/* " ));
2022-03-10 13:20:23 -08:00
2022-03-10 13:30:03 -08:00
$count = 0 ;
foreach ( $session_files as $file ) {
2022-03-10 13:20:23 -08:00
2022-03-10 13:30:03 -08:00
if ( is_file ( $file ))
unlink ( $file );
$count ++ ;
2022-03-10 13:20:23 -08:00
}
2022-03-10 13:30:03 -08:00
\DB :: table ( 'users' ) -> update ([ 'remember_token' => null ]);
$this -> info ( $count . ' sessions cleared!' );
2022-03-10 13:20:23 -08:00
}
}