1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Torralbodavid\DuckFunkCore\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Routing\Controller; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
use Laravel\Socialite\Facades\Socialite; |
9
|
|
|
use Torralbodavid\DuckFunkCore\Models\Arcturus\User; |
10
|
|
|
use Torralbodavid\DuckFunkCore\Models\Arcturus\UserSettings; |
11
|
|
|
|
12
|
|
|
class AuthController extends Controller |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Redirect the user to the GitHub authentication page. |
16
|
|
|
* |
17
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
18
|
|
|
*/ |
19
|
|
|
public function redirectToProvider() |
20
|
|
|
{ |
21
|
|
|
return Socialite::with('facebook')->redirect(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Obtain the user information from Facebook. |
26
|
|
|
* |
27
|
|
|
* @return \Illuminate\Http\RedirectResponse |
28
|
|
|
*/ |
29
|
|
|
public function handleProviderCallback() |
30
|
|
|
{ |
31
|
|
|
$user = Socialite::driver('facebook')->user(); |
32
|
|
|
|
33
|
|
|
$user = User::firstOrCreate( |
34
|
|
|
['mail' => $user->getEmail()], |
35
|
|
|
[ |
36
|
|
|
'username' => User::randomNickname(), |
37
|
|
|
'real_name' => $user->getName(), |
38
|
|
|
'mail' => $user->getEmail(), |
39
|
|
|
'account_created' => Carbon::now()->getTimestamp(), |
40
|
|
|
'ip_register' => request()->ip(), |
41
|
|
|
'ip_current' => request()->ip(), |
42
|
|
|
]); |
43
|
|
|
|
44
|
|
|
\auth()->login($user); |
45
|
|
|
return redirect()->intended('hotel'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|