Show a sign-in link instead of the form after email confirmation
CI / Tests (PHP 8.2) (pull_request) Successful in 41s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / No Debug Code (pull_request) Successful in 2s
CI / PHPStan (pull_request) Successful in 2m45s
CI / Coding Standards (pull_request) Successful in 2m55s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m35s
CI / Build Plugin Zip (pull_request) Skipped

Closes #67

When a student lands on the registration page from the confirmation
email (?us_confirmed=1), replace the registration form with the
confirmation message and a "Sign in to your account" link — the form
is useless at that point and re-submitting would only produce an
"account already exists" error. A confirmed-but-unapproved student can
already log in (the pending gate only withholds booking), so signing in
is the natural next step.

The link target follows the booking block's pattern: a loginPageId
block attribute (page picker in the editor sidebar) or login_page_id
shortcode attribute, falling back to wp_login_url(). The expired-link
notice keeps the form as before.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-07-18 17:53:38 -03:00
co-authored by Claude Fable 5
parent 8d79fbdb1f
commit 7b00811133
8 changed files with 111 additions and 9 deletions
+56
View File
@@ -57,9 +57,20 @@ class RegistrationPageTest extends TestCase
protected function tearDown(): void
{
$_POST = [];
$_GET = [];
parent::tearDown();
}
/** Stub everything render() needs on a logged-out GET request. */
private function stubRenderContext(): void
{
Functions\when('is_user_logged_in')->justReturn(false);
Functions\when('sanitize_key')->alias(static fn ($v) => strtolower((string) $v));
Functions\when('wp_login_url')->justReturn('http://home.test/wp-login.php');
Functions\when('wp_nonce_field')->justReturn('');
$this->ctx['settings']->shouldReceive('openRegistrationEnabled')->andReturn(true);
}
private function submit(?Invite $invite, bool $open): string
{
$method = new \ReflectionMethod(RegistrationPage::class, 'handleSubmit');
@@ -120,6 +131,51 @@ class RegistrationPageTest extends TestCase
self::assertNotSame('', $result);
}
public function testConfirmedEmailShowsSignInLinkInsteadOfForm(): void
{
$_GET = ['us_confirmed' => '1'];
$this->stubRenderContext();
$html = $this->ctx['page']->render([]);
self::assertStringContainsString('us-success', $html);
self::assertStringContainsString('http://home.test/wp-login.php', $html);
self::assertStringNotContainsString('<form', $html);
}
public function testConfirmedSignInLinkUsesConfiguredLoginPage(): void
{
$_GET = ['us_confirmed' => '1'];
$this->stubRenderContext();
Functions\expect('get_permalink')->once()->with(7)->andReturn('http://home.test/sign-in/');
$html = $this->ctx['page']->render(['login_page_id' => 7]);
self::assertStringContainsString('http://home.test/sign-in/', $html);
self::assertStringNotContainsString('wp-login.php', $html);
}
public function testRegistrationFormRendersWithoutConfirmationFlag(): void
{
$this->stubRenderContext();
$html = $this->ctx['page']->render([]);
self::assertStringContainsString('<form', $html);
self::assertStringNotContainsString('us-success', $html);
}
public function testExpiredConfirmationStillShowsForm(): void
{
$_GET = ['us_confirmed' => 'expired'];
$this->stubRenderContext();
$html = $this->ctx['page']->render([]);
self::assertStringContainsString('us-error', $html);
self::assertStringContainsString('<form', $html);
}
public function testRejectsWhenARequiredPolicyIsUnaccepted(): void
{
$_POST = [ 'password' => 'password123', 'display_name' => 'Ada', 'email' => '[email protected]' ];
+4 -1
View File
@@ -125,7 +125,10 @@ class BlockRegistrarTest extends TestCase
['bookingPageId', 'autoRedirect'],
array_keys($registered['us-scheduler/student-login']['attributes'])
);
self::assertSame([], $registered['us-scheduler/student-register']['attributes']);
self::assertSame(
['loginPageId'],
array_keys($registered['us-scheduler/student-register']['attributes'])
);
self::assertSame(
['offeringId'],
array_keys($registered['us-scheduler/group-classes']['attributes'])