Logout other session with current user, when user athenticated again.
Last active
October 6, 2022 11:00
-
-
Save rozsazoltan/80b6d0766b39c54135b0831cd6acbc2e to your computer and use it in GitHub Desktop.
Logout other session with current user, when user athenticated again.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http; | |
use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
class Kernel extends HttpKernel | |
{ | |
// ... | |
/** | |
** Szükség van a \Illuminate\Session\Middleware\AuthenticateSession köztes szoftver deffiniálására | |
* - a munkameneteket azonosítja | |
*/ | |
protected $routeMiddleware = [ | |
// ... | |
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class, | |
// ... | |
]; | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\AuthenticatesUsers; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Auth; | |
class LoginController extends Controller | |
{ | |
/** | |
** Építsük be a Laravel alapértelmezett felhasználó hitelesítőjét a Controllerünkbe. | |
*/ | |
use AuthenticatesUsers; | |
/** | |
** Bejelentkezési kérelem feldolgozása | |
* - a függvény a "Illuminate\Foundation\Auth\AuthenticatesUsers" fájlból lett átkonvertálva, | |
* mivel a használni kívánt authenticated függvény védett, így erre is szükség van. | |
* - a függvényen módosítani nem kötelező, ha egyéni logikát alkalmazol, akkor azt itt teheted meg. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse | |
* | |
* @throws \Illuminate\Validation\ValidationException | |
*/ | |
public function login(Request $request) | |
{ | |
$this->validateLogin($request); | |
// If the class is using the ThrottlesLogins trait, we can automatically throttle | |
// the login attempts for this application. We'll key this by the username and | |
// the IP address of the client making these requests into this application. | |
if (method_exists($this, 'hasTooManyLoginAttempts') && | |
$this->hasTooManyLoginAttempts($request)) { | |
$this->fireLockoutEvent($request); | |
return $this->sendLockoutResponse($request); | |
} | |
if ($this->attemptLogin($request)) { | |
if ($request->hasSession()) { | |
$request->session()->put('auth.password_confirmed_at', time()); | |
} | |
return $this->sendLoginResponse($request); | |
} | |
// If the login attempt was unsuccessful we will increment the number of attempts | |
// to login and redirect the user back to the login form. Of course, when this | |
// user surpasses their maximum number of attempts they will get locked out. | |
$this->incrementLoginAttempts($request); | |
return $this->sendFailedLoginResponse($request); | |
} | |
/** | |
** Ha a felhasználó sikeresen bejelentkezett | |
* - a függvény a "Illuminate\Foundation\Auth\AuthenticatesUsers" fájlból lett átkonvertálva, | |
* mivel itt tudjuk megadni, hogy mi történjen a siekres bejelentkezést követően. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param mixed $user | |
* @return mixed | |
*/ | |
protected function authenticated(Request $request, $user) | |
{ | |
// Jelentkeztesd ki az összes többi munkamenetet, amely a jelenlegi felhasználói fiókot használja | |
// - szükség van a felhasználó jelszavára a művelet végrehajtásához. | |
Auth::logoutOtherDevices($request->password); | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ... | |
/** | |
** Győződjön meg róla, hogy minden útvonal, ahol hitelesítésre van szükség, lefuttatja az "auth.session" néven deklarált köztes szoftvert. | |
* - Például: | |
*/ | |
Route::group([ | |
'prefix' => 'admin', | |
'as' => 'admin.', | |
'middleware' => [ | |
'auth', | |
'auth.session', | |
// ... | |
], | |
], function () { | |
// ... | |
}); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment