2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2018-08-13 22:03:12 +01:00
|
|
|
use App\User;
|
2016-09-01 16:23:39 +01:00
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
2016-09-06 12:23:14 +01:00
|
|
|
use Illuminate\Http\Request;
|
2018-08-13 14:25:56 +01:00
|
|
|
use Socialite;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
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 / registration.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $redirectTo = '/';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('guest', ['except' => 'logout']);
|
|
|
|
}
|
2016-09-02 10:42:05 +01:00
|
|
|
|
2016-09-06 12:23:14 +01:00
|
|
|
protected function credentials(Request $request)
|
|
|
|
{
|
|
|
|
$result = $request->only($this->username(), 'password');
|
|
|
|
|
|
|
|
// Only allow activated users to login
|
|
|
|
$result['is_activated'] = true;
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
/**
|
|
|
|
* Show the application's login form.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-06 14:45:51 +01:00
|
|
|
public function showLoginForm(Request $request)
|
2016-09-02 10:42:05 +01:00
|
|
|
{
|
2017-03-23 04:29:29 +00:00
|
|
|
return Theme::render('auth.v2_unified', [
|
|
|
|
'active_tab' => 'login',
|
2016-09-06 14:45:51 +01:00
|
|
|
'info' => $request->session()->get('info')
|
|
|
|
]);
|
2016-09-02 10:42:05 +01:00
|
|
|
}
|
2018-08-13 14:25:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect the user to the Facebook authentication page.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function redirectToFacebook()
|
|
|
|
{
|
|
|
|
return Socialite::driver('facebook')->redirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain the user information from Facebook.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2018-08-13 22:03:12 +01:00
|
|
|
public function handleFacebookCallback(Request $request)
|
2018-08-13 14:25:56 +01:00
|
|
|
{
|
2018-08-13 22:03:12 +01:00
|
|
|
$facebookUser = Socialite::driver('facebook')->user();
|
|
|
|
$user = User::where('facebook_id', $facebookUser->id)->first();
|
2018-08-13 14:25:56 +01:00
|
|
|
|
2018-08-13 22:03:12 +01:00
|
|
|
if (is_null($user))
|
|
|
|
{
|
|
|
|
$request->getSession()->put('registerData', [
|
|
|
|
'name' => $facebookUser->name,
|
|
|
|
'email' => $facebookUser->email,
|
|
|
|
'facebook_id' => $facebookUser->id,
|
|
|
|
'is_activated' => true
|
|
|
|
]);
|
|
|
|
|
|
|
|
return redirect(route('register'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->guard()->login($user);
|
|
|
|
|
|
|
|
return redirect(route('home'));
|
2018-08-13 14:25:56 +01:00
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|