Completed
Push — master ( 422cb4...8ed555 )
by Renato
02:42
created

AuthController::redirectToProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
namespace GitScrum\Http\Controllers\Auth;
9
10
use GitScrum\Http\Requests\AuthRequest;
11
use GitScrum\Models\User;
12
use GitScrum\Classes\UserClass;
13
use GitScrum\Http\Controllers\Controller;
14
use Carbon\Carbon;
15
use Socialite;
16
use Auth;
17
18
class AuthController extends Controller
19
{
20
    public function __construct()
21
    {
22
       $this->middleware('guest')->except('logout');
23
    }
24
25
    public function login()
26
    {
27
        return view('auth.login');
28
    }
29
30
    public function logout()
31
    {
32
        Auth::logout();
33
34
        return redirect()->route('home');
35
    }
36
37
    public function doLogin(AuthRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
    }
40
41
    public function register()
42
    {
43
    }
44
45
    public function doRegister()
46
    {
47
    }
48
49
    public function redirectToProvider()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
50
    {
51
        return Socialite::driver('github')->scopes(['repo', 'notifications', 'read:org'])->redirect();
52
    }
53
54
    public function handleProviderCallback()
55
    {
56
        $user = Socialite::driver('github')->user();
57
        $data = [
58
            'github_id' => $user->id,
59
            'username' => $user->nickname,
60
            'name' => $user->name,
61
            'token' => $user->token,
62
            'avatar' => $user->user['avatar_url'],
63
            'html_url' => $user->user['html_url'],
64
            'bio' => $user->user['bio'],
65
            'since' => Carbon::parse($user->user['created_at'])->toDateTimeString(),
66
            'location' => $user->user['location'],
67
            'blog' => $user->user['blog'],
68
            'email' => $user->email,
69
        ];
70
        $UserClass = new UserClass();
71
        Auth::loginUsingId($UserClass->save($data)->id);
72
73
        return redirect()->route('user.dashboard');
74
    }
75
}
76