Redirect to sign-up if already logged in

This commit is contained in:
weeman 2023-08-30 17:39:16 +02:00 committed by Igor Scheller
parent a2a57ec852
commit 4267a76adb
2 changed files with 25 additions and 0 deletions

View File

@ -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('/');
}

View File

@ -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
*/