AuthController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 7

2 Methods

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