|
1
|
|
|
<?php
|
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth;
|
|
4
|
|
|
|
|
5
|
|
|
use App\User;
|
|
6
|
|
|
use App\Email;
|
|
7
|
|
|
use App\Http\Controllers\Controller;
|
|
8
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
9
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
10
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
|
11
|
|
|
use Illuminate\Http\Request;
|
|
12
|
|
|
|
|
13
|
|
|
class RegisterController extends Controller {
|
|
14
|
|
|
/*
|
|
15
|
|
|
|--------------------------------------------------------------------------
|
|
16
|
|
|
| Register Controller
|
|
17
|
|
|
|--------------------------------------------------------------------------
|
|
18
|
|
|
|
|
|
19
|
|
|
| This controller handles the registration of new users as well as their
|
|
20
|
|
|
| validation and creation. By default this controller uses a trait to
|
|
21
|
|
|
| provide this functionality without requiring any additional code.
|
|
22
|
|
|
|
|
|
23
|
|
|
*/
|
|
24
|
|
|
|
|
25
|
|
|
use RegistersUsers;
|
|
26
|
|
|
|
|
27
|
|
|
/**
|
|
28
|
|
|
* Where to redirect users after registration.
|
|
29
|
|
|
*
|
|
30
|
|
|
* @var string
|
|
31
|
|
|
*/
|
|
32
|
|
|
protected $redirectTo = '/dashboard';
|
|
33
|
|
|
|
|
34
|
|
|
/**
|
|
35
|
|
|
* Create a new controller instance.
|
|
36
|
|
|
*
|
|
37
|
|
|
* @return void
|
|
|
|
|
|
|
38
|
|
|
*/
|
|
39
|
|
|
public function __construct() {
|
|
40
|
|
|
$this->middleware('guest');
|
|
41
|
|
|
}
|
|
42
|
|
|
|
|
43
|
|
|
/**
|
|
44
|
|
|
* Get a validator for an incoming registration request.
|
|
45
|
|
|
*
|
|
46
|
|
|
* @param array $data
|
|
47
|
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
48
|
|
|
*/
|
|
49
|
|
|
public function validator(array $data) {
|
|
50
|
|
|
return Validator::make($data, [
|
|
51
|
|
|
'name' => 'required|string|max:255',
|
|
52
|
|
|
'email' => 'required|string|email|max:255|unique:users',
|
|
53
|
|
|
'password' => 'required|string|min:6|confirmed',
|
|
54
|
|
|
]);
|
|
55
|
|
|
}
|
|
56
|
|
|
|
|
57
|
|
|
/**
|
|
58
|
|
|
* Create a new user instance after a valid registration.
|
|
59
|
|
|
*
|
|
60
|
|
|
* @param array $data
|
|
61
|
|
|
* @return \App\User
|
|
62
|
|
|
*/
|
|
63
|
1 |
|
public function create(array $data) {
|
|
64
|
|
|
//setup the email
|
|
65
|
1 |
|
$email = Email::firstOrNew(['email' => $data['email']]);
|
|
66
|
|
|
|
|
67
|
|
|
//grab main user
|
|
68
|
1 |
|
$user = User::firstOrNew(['id' => $email->user_id]);
|
|
69
|
|
|
|
|
70
|
|
|
// Verify if user is new. record all user data.
|
|
71
|
1 |
|
if (!$user->exists) {
|
|
72
|
|
|
|
|
73
|
1 |
|
$user->name = $data['name'];
|
|
74
|
1 |
|
$user->confirmed = 1;
|
|
75
|
1 |
|
$email->is_primary = 1;
|
|
76
|
|
|
|
|
77
|
|
|
// Create user data
|
|
78
|
1 |
|
$user->save();
|
|
79
|
|
|
|
|
80
|
|
|
// Associate email data
|
|
81
|
1 |
|
$user->emails()->save($email);
|
|
82
|
|
|
}
|
|
83
|
|
|
|
|
84
|
|
|
// Update user's local credentials
|
|
85
|
1 |
|
$user->email = $data['email'];
|
|
86
|
1 |
|
$user->password = Hash::make($data['password']);
|
|
87
|
|
|
|
|
88
|
1 |
|
$user->save();
|
|
89
|
|
|
|
|
90
|
1 |
|
return $user;
|
|
91
|
|
|
}
|
|
92
|
|
|
|
|
93
|
|
|
/**
|
|
94
|
|
|
* The user has been registered.
|
|
95
|
|
|
*
|
|
96
|
|
|
* @param \Illuminate\Http\Request $request
|
|
97
|
|
|
* @param mixed $user
|
|
98
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
99
|
|
|
*/
|
|
100
|
|
|
protected function registered(Request $request, $user)
|
|
|
|
|
|
|
101
|
|
|
{
|
|
102
|
|
|
// Alerts user creation
|
|
103
|
|
|
return redirect('dashboard')->with('status', __('You were registered.'));
|
|
104
|
|
|
}
|
|
105
|
|
|
|
|
106
|
|
|
}
|
|
107
|
|
|
|
Adding a
@returnannotation 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.