-
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
Showing
5 changed files
with
219 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Foundation\Auth\AuthenticatesUsers; | ||
use Socialite; | ||
use App\User; | ||
use Illuminate\Support\Facades\Auth; | ||
class GoogleController 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'; | ||
|
||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('guest')->except('logout'); | ||
} | ||
|
||
/** | ||
* Redirect the user to the GitHub authentication page. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function redirectToProvider() | ||
{ | ||
return Socialite::driver('google')->redirect(); | ||
} | ||
|
||
/** | ||
* Obtain the user information from GitHub. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function handleProviderCallback() | ||
{ | ||
$userSocial = Socialite::driver('google')->user(); | ||
|
||
|
||
//check if user exists and log user in | ||
|
||
$user = User::where('email', $userSocial->email)->first(); | ||
if($user){ | ||
if(Auth::loginUsingId($user->id)){ | ||
return redirect()->route('home'); | ||
} | ||
} | ||
|
||
//else sign the user up | ||
$userSignup = User::create([ | ||
'name' => $userSocial->name, | ||
'email' => $userSocial->email, | ||
'password' => bcrypt('1234'), | ||
'avatar'=> $userSocial->avatar, | ||
'github_profile'=> $userSocial->user['url'], | ||
'gender'=> $userSocial->user['gender'] | ||
]); | ||
|
||
|
||
//finally log the user in | ||
if($userSignup){ | ||
if(Auth::loginUsingId($userSignup->id)){ | ||
return redirect()->route('home'); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
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,91 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Auth; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Foundation\Auth\AuthenticatesUsers; | ||
use Socialite; | ||
use App\User; | ||
use Illuminate\Support\Facades\Auth; | ||
class LinkedinController 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'; | ||
|
||
/** | ||
* Create a new controller instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('guest')->except('logout'); | ||
} | ||
|
||
/** | ||
* Redirect the user to the GitHub authentication page. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function redirectToProvider() | ||
{ | ||
return Socialite::driver('linkedin')->redirect(); | ||
} | ||
|
||
/** | ||
* Obtain the user information from GitHub. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function handleProviderCallback() | ||
{ | ||
$userSocial = Socialite::driver('linkedin')->user(); | ||
|
||
|
||
//check if user exists and log user in | ||
|
||
$user = User::where('email', $userSocial->email)->first(); | ||
if($user){ | ||
if(Auth::loginUsingId($user->id)){ | ||
return redirect()->route('home'); | ||
} | ||
} | ||
|
||
//else sign the user up | ||
$userSignup = User::create([ | ||
'name' => $userSocial->name, | ||
'email' => $userSocial->email, | ||
'password' => bcrypt('1234'), | ||
'avatar'=> $userSocial->avatar, | ||
'github_profile'=> $userSocial->user['link'] | ||
]); | ||
|
||
|
||
//finally log the user in | ||
if($userSignup){ | ||
if(Auth::loginUsingId($userSignup->id)){ | ||
return redirect()->route('home'); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
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
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