LoginController::logout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Foundation\Auth\AuthenticatesUsers;
7
use App\LoginUser;
8
use App\Exceptions\SocialAuthException;
9
10
class LoginController extends Controller
11
{
12
    /*
13
    |--------------------------------------------------------------------------
14
    | Login Controller
15
    |--------------------------------------------------------------------------
16
    |
17
    | This controller handles authenticating users for the application and
18
    | redirecting them to your home screen. The controller uses a trait
19
    | to conveniently provide its functionality to your applications.
20
    |
21
    */
22
23
    use AuthenticatesUsers;
24
25
    /**
26
     * Where to redirect users after login.
27
     *
28
     * @var string
29
     */
30
    protected $redirectTo = '/dashboard';
31
    
32
    protected $loginUser;
33
34
    /**
35
     * Create a new controller instance.
36
     *
37
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
38
     */
39 1
    public function __construct(LoginUser $loginUser)
40
    {
41 1
        $this->middleware('guest')->except('logout');
42 1
        $this->loginUser = $loginUser;
43 1
    }
44
    
45
    /**
46
     * Specific Route to Socialite's Login
47
     * 
48
     * @param type $provider
49
     * @return type
50
     */
51 1
    public function auth($provider)
52
    {
53 1
        return $this->loginUser->authenticate($provider);
54
    }
55
 
56 1
    public function callback($provider)
57
    {
58
        try {
59 1
            return $this->loginUser->login($provider);
60
        } catch (SocialAuthException $e) {
61
            return redirect()->route('login')
62
                ->with('flash-message', $e->getMessage());
63
        }
64
    }
65
 
66
    public function logout()
67
    {
68
       auth()->logout();
69
       return redirect()->to('/'); 
70
    }
71
}
72