-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathRegisterController.php
More file actions
143 lines (126 loc) · 4.13 KB
/
RegisterController.php
File metadata and controls
143 lines (126 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
namespace App\Http\Controllers\Auth;
use HMS\Entities\User;
use HMS\User\UserManager;
use HMS\User\ProfileManager;
use App\Http\Controllers\Controller;
use HMS\Repositories\InviteRepository;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Contracts\Validation\Factory as Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* @var UserManager
*/
private $userManager;
/**
* @var Validator
*/
private $validator;
/**
* @var ProfileManager
*/
protected $profileManager;
/**
* Create a new controller instance.
*
* @param Validator $validator
* @param UserManager $userManager
*/
public function __construct(Validator $validator,
UserManager $userManager, ProfileManager $profileManager)
{
$this->middleware('guest');
$this->validator = $validator;
$this->userManager = $userManager;
$this->profileManager = $profileManager;
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return $this->validator->make($data, [
'invite' => 'required|exists:HMS\Entities\Invite,inviteToken',
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'username' => 'required|max:255|unique:HMS\Entities\User|unique:HMS\Entities\BlacklistUsername',
'email' => 'required|email|max:255|unique:HMS\Entities\User',
'password' => 'required|min:' . User::MIN_PASSWORD_LENGTH . '|confirmed',
'address1' => 'required|max:100',
'address2' => 'nullable|max:100',
'address3' => 'nullable|max:100',
'addressCity' => 'required|max:100',
'addressCounty' => 'required|max:100',
'addressPostcode' => 'required|max:10',
'contactNumber' => 'required|max:50',
'dateOfBirth' => 'nullable|date_format:Y-m-d',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data called via RegistersUsers trait, passes in $request->all()
* @return User
*/
protected function create(array $data)
{
$user = $this->userManager->create(
$data['firstname'],
$data['lastname'],
$data['username'],
$data['email'],
$data['password']
);
$user = $this->profileManager->create(
$user,
$data['address1'],
$data['address2'],
$data['address3'],
$data['addressCity'],
$data['addressCounty'],
$data['addressPostcode'],
$data['contactNumber'],
$data['dateOfBirth']
);
return $user;
}
/**
* Show the application registration form.
* Overridden, we need to have a valid invite token.
*
* @return \Illuminate\Http\Response
*/
public function showRegistrationForm(InviteRepository $inviteRepository, $token)
{
$invite = $inviteRepository->findOneByInviteToken($token);
if (is_null($invite)) {
flash('Token not found. Please visit the space to register you interest in becoming a member.', 'warning');
return redirect('/');
}
return view('auth.register', [
'invite' => $invite->getInviteToken(),
'email' => $invite->getEmail(),
]);
}
}