Test Setup Failed
Push — master ( 346353...6c6952 )
by Adam
07:04 queued 04:19
created

LoginController::validator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use App\User;
7
use Chrisbjr\ApiGuard\Models\ApiKey;
8
use Illuminate\Foundation\Auth\AuthenticatesUsers;
9
use Validator;
10
11
class LoginController extends Controller
12
{
13
    /*
14
    |--------------------------------------------------------------------------
15
    | Registration & Login Controller
16
    |--------------------------------------------------------------------------
17
    |
18
    | This controller handles the registration of new users, as well as the
19
    | authentication of existing users. By default, this controller uses
20
    | a simple trait to add these behaviors. Why don't you explore it?
21
    |
22
    */
23
24
    use AuthenticatesUsers;
25
26
    /**
27
     * Where to redirect users after login / registration.
28
     *
29
     * @var string
30
     */
31
    protected $redirectTo = '/upload';
32
33
    /**
34
     * Create a new authentication controller instance.
35
     */
36
    public function __construct()
37
    {
38
        $this->middleware('guest')->except('logout');
39
    }
40
41
    /**
42
     * Get a validator for an incoming registration request.
43
     *
44
     * @param array $data
45
     *
46
     * @return \Illuminate\Contracts\Validation\Validator
47
     */
48
    protected function validator(array $data)
49
    {
50
        return Validator::make($data, [
51
            'name'     => 'required|max:255',
52
            'email'    => 'required|email|max:255|unique:users',
53
            'password' => 'required|confirmed|min:6',
54
        ]);
55
    }
56
57
    /**
58
     * Create a new user instance after a valid registration.
59
     *
60
     * @param array $data
61
     *
62
     * @return User
63
     */
64
    protected function create(array $data)
65
    {
66
        $user = User::create([
67
            'name'     => $data['name'],
68
            'email'    => $data['email'],
69
            'password' => bcrypt($data['password']),
70
        ]);
71
72
        $this->createUserApiKey($user);
73
74
        return $user;
75
    }
76
77
    /**
78
     * @param User $user
79
     *
80
     * @return mixed
81
     */
82
    private function createUserApiKey(User $user)
83
    {
84
        $apiKey = ApiKey::make($user->id);
85
        $user->apiKey()->save($apiKey);
86
    }
87
}
88