Created
December 8, 2016 10:49
-
-
Save kadnan/0dc01267d7a408359875c10da4f1bdb9 to your computer and use it in GitHub Desktop.
Register a Social user manually
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
<?php | |
namespace App\Http\Controllers\Auth; | |
use App\User; | |
use League\Flysystem\Exception; | |
use Validator; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Foundation\Auth\RegistersUsers; | |
use Socialite; | |
use Illuminate\Support\Facades\Auth; | |
class RegisterController extends Controller | |
{ | |
/* | |
|-------------------------------------------------------------------------- | |
| Register Controller | |
|-------------------------------------------------------------------------- | |
| | |
| This controller handles the registration of new users as well as their | |
| validation and creation. By default this controller uses a trait to | |
| provide this functionality without requiring any additional code. | |
| | |
*/ | |
use RegistersUsers; | |
/** | |
* Where to redirect users after login / registration. | |
* | |
* @var string | |
*/ | |
protected $redirectTo = '/home'; | |
/** | |
* Create a new controller instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->middleware('guest'); | |
//$this->middleware('auth'); | |
} | |
/** | |
* Get a validator for an incoming registration request. | |
* | |
* @param array $data | |
* @return \Illuminate\Contracts\Validation\Validator | |
*/ | |
protected function validator(array $data) | |
{ | |
return Validator::make($data, [ | |
'name' => 'required|max:255', | |
'email' => 'required|email|max:255|unique:users', | |
'password' => 'required|min:6|confirmed', | |
]); | |
} | |
/** | |
* Create a new user instance after a valid registration. | |
* | |
* @param array $data | |
* @return User | |
*/ | |
protected function create(array $data) | |
{ | |
return User::create([ | |
'name' => $data['name'], | |
'email' => $data['email'], | |
'password' => bcrypt($data['password']), | |
]); | |
} | |
public function redirectToProvider() | |
{ | |
return Socialite::driver('facebook')->redirect(); | |
} | |
/** | |
* Obtain the user information from GitHub. | |
* | |
* @return Response | |
*/ | |
public function handleProviderCallback() | |
{ | |
try { | |
$social_user = Socialite::driver('facebook')->user(); | |
} catch (Exception $e) { | |
return redirect('/'); | |
} | |
$user = User::where('social_id', $social_user->getId())->first(); | |
if (!$user) { | |
User::create([ | |
'social_id' => $social_user->getId(), | |
'name' => $social_user->getName(), | |
'email' => $social_user->getEmail(), | |
'social_type' => 'facebook', | |
]); | |
//auth()->login($user); | |
//Auth::loginUsingId(2, true); | |
//$this->guard()->login($user); | |
auth()->login($user); | |
Auth::login($user); | |
} | |
if ($this->guard()->check()) { | |
dd('User Logged IN'); | |
} else { | |
dd('Nog loggine'); | |
} | |
//return redirect('/home'); | |
//return $user->getEmail(); | |
// $user->token; | |
} | |
} |
Author
kadnan
commented
Dec 8, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment