diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index d593a11..24b0f9b 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Auth; +use Illuminate\Http\Request; use Random; use LaravelFans\UiSocialite\Socialite\Controllers\SocialiteLoginController; @@ -18,6 +19,8 @@ class LoginController extends SocialiteLoginController | */ + private $redirectToForLogout = '/'; + /** * Create a new controller instance. * @@ -60,4 +63,30 @@ public function redirectTo() } return $uri; } + + /** + * Log the user out of the application. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function logout(Request $request) + { + if (session('gw_address') && session('gw_port')) { + $this->redirectToForLogout = 'http://' . session('gw_address') . ':' . session('gw_port') + . '/wifidog/auth?logout=1&token=' . $request->user()->api_token; + } + return parent::logout($request); + } + + /** + * The user has logged out of the application. + * + * @param \Illuminate\Http\Request $request + * @return mixed + */ + protected function loggedOut(Request $request) + { + return redirect($this->redirectToForLogout); + } } diff --git a/tests/Feature/LoginControllerTest.php b/tests/Feature/LoginControllerTest.php index 009ffe4..9b20be6 100644 --- a/tests/Feature/LoginControllerTest.php +++ b/tests/Feature/LoginControllerTest.php @@ -100,4 +100,28 @@ public function testRedirectIfAuthenticated() ->get('/login'); $response->assertRedirect('/home'); } + + public function testLogout() + { + $user = factory(User::class)->create(); + + $gw_address = $this->faker->ipv4; + $gw_port = $this->faker->numberBetween(1025, 9999); + $response = $this->actingAs($user) + ->withSession([ + 'gw_address' => $gw_address, + 'gw_port' => $gw_port, + ])->post('/logout'); + $response->assertRedirect('http://' . $gw_address . ':' . $gw_port . '/wifidog/auth?logout=1&token=' + . $user->api_token); + } + + public function testLogoutWithoutWifidog() + { + $user = factory(User::class)->create(); + + $response = $this->actingAs($user) + ->post('/logout'); + $response->assertRedirect('/'); + } }