Server IP : / Your IP : 10.244.4.16 [ Web Server : nginx/1.25.3 System : Linux escuela-portal-app-54f56585bc-kst6g 5.15.0-1084-azure #93-Ubuntu SMP Sat Mar 15 14:12:29 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.2.13 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /proc/448/cwd/app/vendor/laravel/jetstream/src/Http/Livewire/ |
Upload File : |
<?php namespace Laravel\Jetstream\Http\Livewire; use Illuminate\Contracts\Auth\StatefulGuard; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\ValidationException; use Jenssegers\Agent\Agent; use Livewire\Component; class LogoutOtherBrowserSessionsForm extends Component { /** * Indicates if logout is being confirmed. * * @var bool */ public $confirmingLogout = false; /** * The user's current password. * * @var string */ public $password = ''; /** * Confirm that the user would like to log out from other browser sessions. * * @return void */ public function confirmLogout() { $this->password = ''; $this->dispatchBrowserEvent('confirming-logout-other-browser-sessions'); $this->confirmingLogout = true; } /** * Log out from other browser sessions. * * @param \Illuminate\Contracts\Auth\StatefulGuard $guard * @return void */ public function logoutOtherBrowserSessions(StatefulGuard $guard) { if (config('session.driver') !== 'database') { return; } $this->resetErrorBag(); if (! Hash::check($this->password, Auth::user()->password)) { throw ValidationException::withMessages([ 'password' => [__('This password does not match our records.')], ]); } $guard->logoutOtherDevices($this->password); $this->deleteOtherSessionRecords(); request()->session()->put([ 'password_hash_'.Auth::getDefaultDriver() => Auth::user()->getAuthPassword(), ]); $this->confirmingLogout = false; $this->emit('loggedOut'); } /** * Delete the other browser session records from storage. * * @return void */ protected function deleteOtherSessionRecords() { if (config('session.driver') !== 'database') { return; } DB::connection(config('session.connection'))->table(config('session.table', 'sessions')) ->where('user_id', Auth::user()->getAuthIdentifier()) ->where('id', '!=', request()->session()->getId()) ->delete(); } /** * Get the current sessions. * * @return \Illuminate\Support\Collection */ public function getSessionsProperty() { if (config('session.driver') !== 'database') { return collect(); } return collect( DB::connection(config('session.connection'))->table(config('session.table', 'sessions')) ->where('user_id', Auth::user()->getAuthIdentifier()) ->orderBy('last_activity', 'desc') ->get() )->map(function ($session) { return (object) [ 'agent' => $this->createAgent($session), 'ip_address' => $session->ip_address, 'is_current_device' => $session->id === request()->session()->getId(), 'last_active' => Carbon::createFromTimestamp($session->last_activity)->diffForHumans(), ]; }); } /** * Create a new agent instance from the given session. * * @param mixed $session * @return \Jenssegers\Agent\Agent */ protected function createAgent($session) { return tap(new Agent, function ($agent) use ($session) { $agent->setUserAgent($session->user_agent); }); } /** * Render the component. * * @return \Illuminate\View\View */ public function render() { return view('profile.logout-other-browser-sessions-form'); } }