mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-06-15 05:22:44 +01:00
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use Illuminate\Contracts\Auth\StatefulGuard;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Laravel\Fortify\Actions\ConfirmPassword;
|
|
|
|
class OtherBrowserSessionsController extends Controller
|
|
{
|
|
/**
|
|
* Log the user out of their other browser sessions across all devices.
|
|
*/
|
|
public function destroy(Request $request, StatefulGuard $guard): RedirectResponse
|
|
{
|
|
$password = (string) $request->string('password');
|
|
|
|
$confirmed = app(ConfirmPassword::class)($guard, $request->user(), $password);
|
|
|
|
if (! $confirmed) {
|
|
throw ValidationException::withMessages([
|
|
'password' => __('The password is incorrect.'),
|
|
]);
|
|
}
|
|
|
|
$guard->logoutOtherDevices($password);
|
|
|
|
$this->deleteOtherSessionRecords($request);
|
|
|
|
return back(303);
|
|
}
|
|
|
|
/**
|
|
* Delete the other browser session records from storage.
|
|
*/
|
|
protected function deleteOtherSessionRecords(Request $request): void
|
|
{
|
|
if (config('session.driver') !== 'database') {
|
|
return;
|
|
}
|
|
|
|
DB::connection(config('session.connection'))
|
|
->table(config('session.table', 'sessions'))
|
|
->where('user_id', $request->user()->getAuthIdentifier())
|
|
->where('id', '!=', $request->session()->getId())
|
|
->delete();
|
|
}
|
|
}
|