Skip to content

Commit 25790fd

Browse files
committed
Merge branch 'sec_26_03_2' into development
2 parents 1763ac5 + 5763d26 commit 25790fd

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

app/Access/Controllers/RegisterController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public function getRegister()
4848
public function postRegister(Request $request)
4949
{
5050
$this->registrationService->ensureRegistrationAllowed();
51-
$this->validator($request->all())->validate();
52-
$userData = $request->all();
51+
$userData = $this->validator($request->all())->validate();
5352

5453
try {
5554
$user = $this->registrationService->registerUser($userData);

app/Access/RegistrationService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function registerUser(array $userData, ?SocialAccount $socialAccount = nu
8383
// Email restriction
8484
$this->ensureEmailDomainAllowed($userEmail);
8585

86-
// Ensure user does not already exist
86+
// Ensure the user does not already exist
8787
$alreadyUser = !is_null($this->userRepo->getByEmail($userEmail));
8888
if ($alreadyUser) {
8989
throw new UserRegistrationException(trans('errors.error_user_exists_different_creds', ['email' => $userEmail]), '/login');
@@ -99,15 +99,15 @@ public function registerUser(array $userData, ?SocialAccount $socialAccount = nu
9999
$newUser = $this->userRepo->createWithoutActivity($userData, $emailConfirmed);
100100
$newUser->attachDefaultRole();
101101

102-
// Assign social account if given
102+
// Assign a social account if given
103103
if ($socialAccount) {
104104
$newUser->socialAccounts()->save($socialAccount);
105105
}
106106

107107
Activity::add(ActivityType::AUTH_REGISTER, $socialAccount ?? $newUser);
108108
Theme::dispatch(ThemeEvents::AUTH_REGISTER, $authSystem, $newUser);
109109

110-
// Start email confirmation flow if required
110+
// Start the email confirmation flow if required
111111
if ($this->emailConfirmationService->confirmationRequired() && !$emailConfirmed) {
112112
$newUser->save();
113113

tests/Auth/RegistrationTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,30 @@ public function test_registration_validation()
188188
$resp->assertSee('The password must be at least 8 characters.');
189189
}
190190

191+
public function test_registration_input_filtered_to_validated_input()
192+
{
193+
$this->setSettings(['registration-enabled' => 'true']);
194+
$roleIds = Role::all()->pluck('id')->toArray();
195+
196+
$resp = $this->post('/register', [
197+
'name' => 'Barry',
198+
'email' => 'barry@example.com',
199+
'password' => 'superpassword',
200+
'password_confirmation' => 'superpassword',
201+
'external_auth_id' => 'ext5691284',
202+
'roles' => $roleIds,
203+
]);
204+
205+
$resp->assertRedirect('/');
206+
207+
/** @var User $user */
208+
$user = auth()->user();
209+
$this->assertNotNull($user);
210+
$this->assertFalse($user->isGuest());
211+
$this->assertEmpty($user->external_auth_id);
212+
$this->assertEquals(0, $user->roles()->count());
213+
}
214+
191215
public function test_registration_simple_honeypot_active()
192216
{
193217
$this->setSettings(['registration-enabled' => 'true']);

0 commit comments

Comments
 (0)