|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use App\Events\RegisteredUser; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\User; |
|
8
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers; |
|
9
|
|
|
use Validator; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class RegisterController. |
|
13
|
|
|
*/ |
|
14
|
|
|
class RegisterController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/* |
|
17
|
|
|
|-------------------------------------------------------------------------- |
|
18
|
|
|
| Register Controller |
|
19
|
|
|
|-------------------------------------------------------------------------- |
|
20
|
|
|
| |
|
21
|
|
|
| This controller handles the registration of new users as well as their |
|
22
|
|
|
| validation and creation. By default this controller uses a trait to |
|
23
|
|
|
| provide this functionality without requiring any additional code. |
|
24
|
|
|
| |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
use RegistersUsers; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Show the application registration form. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Http\Response |
|
33
|
|
|
*/ |
|
34
|
|
|
public function showRegistrationForm() |
|
35
|
|
|
{ |
|
36
|
|
|
return view('adminlte::auth.register'); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Where to redirect users after login / registration. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $redirectTo = '/home'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create a new controller instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->middleware('guest'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get a validator for an incoming registration request. |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $data |
|
60
|
|
|
* |
|
61
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function validator(array $data) |
|
64
|
|
|
{ |
|
65
|
|
|
return Validator::make($data, [ |
|
66
|
|
|
'name' => 'required|max:255', |
|
67
|
|
|
'username' => 'sometimes|required|max:255|unique:users', |
|
68
|
|
|
'email' => 'required|email|max:255|unique:users', |
|
69
|
|
|
'password' => 'required|min:6|confirmed', |
|
70
|
|
|
'terms' => 'required', |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Create a new user instance after a valid registration. |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $data |
|
78
|
|
|
* |
|
79
|
|
|
* @return User |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function create(array $data) |
|
82
|
|
|
{ |
|
83
|
|
|
$fields = [ |
|
84
|
|
|
'name' => $data['name'], |
|
85
|
|
|
'email' => $data['email'], |
|
86
|
|
|
'password' => bcrypt($data['password']), |
|
87
|
|
|
]; |
|
88
|
|
|
if (config('auth.providers.users.field', 'email') === 'username' && isset($data['username'])) { |
|
89
|
|
|
$fields['username'] = $data['username']; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$user = User::create($fields); |
|
93
|
|
|
|
|
94
|
|
|
event(new RegisteredUser($user)); |
|
95
|
|
|
|
|
96
|
|
|
return $user; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|