login controller
This commit is contained in:
@@ -28,15 +28,5 @@ class EsiScopeController extends Controller
|
||||
])->get();
|
||||
|
||||
return view('scopes.select')->with('scopes', $scopes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the provider
|
||||
*
|
||||
* @return Socialite
|
||||
*/
|
||||
public function redirectToProvider(Request $request) {
|
||||
return Socialite::driver('eveonline')->setScopes($request->scopes)->redirect();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,38 +3,96 @@
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
//Internal Library
|
||||
use App\Library\Login\LoginHelper;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
protected $redirectto = '/dashboard';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except('logout');
|
||||
$this->middleware('auth')->only('logout');
|
||||
public function __construct() {
|
||||
$this->middleware('guest')->except(['logout',
|
||||
'handleProviderCallback',
|
||||
'redirectToProvider']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function logout() {
|
||||
Auth::logout();
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to provider's website
|
||||
*
|
||||
* @return param
|
||||
*/
|
||||
public function redirectToEveonline() {
|
||||
return Socialite::driver('eveonline')->scopes(['publicData'])->redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new controller instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handleEveonlineCallback() {
|
||||
try {
|
||||
$user = Socialite::driver('eveonline')->user();
|
||||
$findUser = User::where('character_id', $user->character_id)->first();
|
||||
|
||||
if($findUser) {
|
||||
Auth::login($finduser);
|
||||
return redirect()->intended('home');
|
||||
} else {
|
||||
$newUser = User::updateOrCreate(['character_id' => $user->character_id], [
|
||||
'character_name' => $user->character_name,
|
||||
'character_id' => $user->character_id,
|
||||
'token' => $user->token,
|
||||
'refresh_token' => $user->refresh_token,
|
||||
'expiresIn' => $user->expiresIn,
|
||||
'user_jwt_token' => $user->user,
|
||||
]);
|
||||
|
||||
Auth::login($newUser);
|
||||
|
||||
return redirect()->intended('home');
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
dd($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get token from callback
|
||||
* Redirect to the dashboard if logging in successfully.
|
||||
*
|
||||
* @return redirect()
|
||||
*/
|
||||
public function handleProviderCallback(Socialite $social) {
|
||||
//Get the sso user from the socialite driver
|
||||
$ssoUser = $social->driver('eveonline')->user();
|
||||
|
||||
$scpSession = session()->pull('scopes');
|
||||
|
||||
$user = LoginHelper::createOrGetUser($ssoUser);
|
||||
auth()->login($user, true);
|
||||
return redirect()->to('/dashboard')->with('success', 'Successfully Logged In.');
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
namespace App\Models\Auth;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@@ -20,8 +20,6 @@ class User extends Authenticatable
|
||||
protected $fillable = [
|
||||
'character_id',
|
||||
'character_name',
|
||||
'email',
|
||||
'password',
|
||||
'character_owner_hash',
|
||||
];
|
||||
|
||||
@@ -31,20 +29,7 @@ class User extends Authenticatable
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user