From 4267a76adb6c9a794ca385a9c85dec7a94a72436 Mon Sep 17 00:00:00 2001 From: weeman Date: Wed, 30 Aug 2023 17:39:16 +0200 Subject: [PATCH] Redirect to sign-up if already logged in --- src/Controllers/SignUpController.php | 5 +++++ .../Unit/Controllers/SignUpControllerTest.php | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Controllers/SignUpController.php b/src/Controllers/SignUpController.php index b79011fe..51e34b2b 100644 --- a/src/Controllers/SignUpController.php +++ b/src/Controllers/SignUpController.php @@ -61,6 +61,11 @@ class SignUpController extends BaseController return $this->redirect->to('/oauth/' . $provider->provider); } + if ($this->auth->user()) { + // User is already logged in - that means a supporter has registered an angel. Return to register page. + return $this->redirect->to('/sign-up'); + } + return $this->redirect->to('/'); } diff --git a/tests/Unit/Controllers/SignUpControllerTest.php b/tests/Unit/Controllers/SignUpControllerTest.php index 23b34726..4b020e64 100644 --- a/tests/Unit/Controllers/SignUpControllerTest.php +++ b/tests/Unit/Controllers/SignUpControllerTest.php @@ -85,6 +85,26 @@ final class SignUpControllerTest extends ControllerTest $this->assertFalse($this->session->has('show_welcome')); } + /** + * @covers \Engelsystem\Controllers\SignUpController + */ + public function testSaveAlreadyLoggedIn(): void + { + $this->setPasswordRegistrationEnabledConfig(); + $request = $this->request->withParsedBody(['user' => 'data']); + + // Fake logged in user + $this->authenticator->method('user')->willReturn(new EngelsystemUser()); + + // Assert that the user is redirected to /sign-up again + $this->response + ->expects(self::once()) + ->method('redirectTo') + ->with('http://localhost/sign-up', 302); + + $this->subject->save($request); + } + /** * @covers \Engelsystem\Controllers\SignUpController */