-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31b0a6a
commit 575f5e6
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Voh\KmSocialite; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Laravel\Socialite\Facades\Socialite; | ||
|
||
/** | ||
* Trait LoginUsers | ||
* @package Voh\KmSocialite | ||
*/ | ||
trait LoginUsers | ||
{ | ||
/** | ||
* Where to redirect users after login. | ||
* | ||
* @var string | ||
*/ | ||
protected $redirectTo = '/'; | ||
|
||
/** | ||
* Create a new controller instance. | ||
* | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('guest')->except('logout'); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function oauth() | ||
{ | ||
return Socialite::driver('km')->redirect(); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function login() | ||
{ | ||
/** @var \Laravel\Socialite\Two\User $rawUser */ | ||
$rawUser = Socialite::driver('km')->user(); | ||
|
||
$user = $this->performLogin($rawUser); | ||
|
||
Auth::login($user); | ||
|
||
return redirect(session('url.intended', $this->redirectTo)); | ||
} | ||
|
||
/** | ||
* Log the user out of the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function logout(Request $request) | ||
{ | ||
Auth::guard()->logout(); | ||
|
||
$request->session()->flush(); | ||
|
||
$request->session()->regenerate(); | ||
|
||
return redirect('/'); | ||
} | ||
} |