Skip to content

Commit

Permalink
feat: wifidog#67 wifidog logout
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkcup committed Apr 20, 2021
1 parent a359af8 commit 3c15fef
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Random;
use LaravelFans\UiSocialite\Socialite\Controllers\SocialiteLoginController;

Expand All @@ -18,6 +19,8 @@ class LoginController extends SocialiteLoginController
|
*/

private $redirectToForLogout = '/';

/**
* Create a new controller instance.
*
Expand Down Expand Up @@ -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);
}
}
24 changes: 24 additions & 0 deletions tests/Feature/LoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
}
}

0 comments on commit 3c15fef

Please sign in to comment.