From a2a57ec85278fba37e9ace9b4782491adeb29d9b Mon Sep 17 00:00:00 2001 From: msquare Date: Tue, 15 Aug 2023 12:32:31 +0200 Subject: [PATCH] prefill fields from oauth --- src/Controllers/OAuthController.php | 14 ++++------- .../Unit/Controllers/OAuthControllerTest.php | 23 +++++++------------ 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/Controllers/OAuthController.php b/src/Controllers/OAuthController.php index 87694146..0fb1bbe4 100644 --- a/src/Controllers/OAuthController.php +++ b/src/Controllers/OAuthController.php @@ -307,15 +307,11 @@ class OAuthController extends BaseController throw new HttpNotFound('oauth.not-found'); } - $this->session->set( - 'form_data', - [ - 'name' => $userdata->get($config['username']), - 'email' => $userdata->get($config['email']), - 'first_name' => $userdata->get($config['first_name']), - 'last_name' => $userdata->get($config['last_name']), - ], - ); + $this->session->set('form-data-username', $userdata->get($config['username'])); + $this->session->set('form-data-email', $userdata->get($config['email'])); + $this->session->set('form-data-first_name', $userdata->get($config['first_name'])); + $this->session->set('form-data-last_name', $userdata->get($config['last_name'])); + $this->session->set('oauth2_groups', $userdata->get($config['groups'], [])); $this->session->set('oauth2_connect_provider', $providerName); $this->session->set('oauth2_user_id', $providerUserIdentifier); diff --git a/tests/Unit/Controllers/OAuthControllerTest.php b/tests/Unit/Controllers/OAuthControllerTest.php index 75b4c4e1..01166113 100644 --- a/tests/Unit/Controllers/OAuthControllerTest.php +++ b/tests/Unit/Controllers/OAuthControllerTest.php @@ -459,15 +459,10 @@ class OAuthControllerTest extends TestCase $this->assertEquals(4242424242, $this->session->get('oauth2_expires_at')->unix()); $this->assertFalse($this->session->get('oauth2_enable_password')); $this->assertEquals(null, $this->session->get('oauth2_allow_registration')); - $this->assertEquals( - [ - 'name' => 'username', - 'email' => 'foo.bar@localhost', - 'first_name' => 'Foo', - 'last_name' => 'Bar', - ], - $this->session->get('form_data') - ); + $this->assertEquals($this->session->get('form-data-username'), 'username'); + $this->assertEquals($this->session->get('form-data-email'), 'foo.bar@localhost'); + $this->assertEquals($this->session->get('form-data-first_name'), 'Foo'); + $this->assertEquals($this->session->get('form-data-last_name'), 'Bar'); $this->config->set('registration_enabled', false); $this->expectException(HttpNotFound::class); @@ -544,12 +539,10 @@ class OAuthControllerTest extends TestCase $this->setExpects($controller, 'getProvider', ['testprovider'], $provider, $this->atLeastOnce()); $controller->index($request); - $this->assertEquals([ - 'email' => 'foo.bar@localhost', - 'name' => 'testuser', - 'first_name' => 'Test', - 'last_name' => 'Tester', - ], $this->session->get('form_data')); + $this->assertEquals($this->session->get('form-data-username'), 'testuser'); + $this->assertEquals($this->session->get('form-data-email'), 'foo.bar@localhost'); + $this->assertEquals($this->session->get('form-data-first_name'), 'Test'); + $this->assertEquals($this->session->get('form-data-last_name'), 'Tester'); }