]> BookStack Code Mirror - bookstack/commitdiff
Updated flow to ensure /register/confirm route is used where needed
authorDan Brown <redacted>
Sat, 5 Sep 2020 16:26:48 +0000 (17:26 +0100)
committerDan Brown <redacted>
Sat, 5 Sep 2020 16:26:48 +0000 (17:26 +0100)
Was accidentally skipped during previous updates. Will now be used on
saml, ldap & standard registration where required.
Uses session to know if the email was just sent and, if so, show the
confirmation route.

app/Auth/Access/RegistrationService.php
app/Http/Middleware/Authenticate.php
tests/Auth/AuthTest.php
tests/Auth/LdapTest.php
tests/Auth/Saml2Test.php

index 00ad630be23dd2cba644e679870d924c44dc721e..b85f7ffd83c24a0aa84b97997ee75f41735fc3b6 100644 (file)
@@ -74,6 +74,7 @@ class RegistrationService
 
             try {
                 $this->emailConfirmationService->sendConfirmation($newUser);
+                session()->flash('sent-email-confirmation', true);
             } catch (Exception $e) {
                 $message = trans('auth.email_confirm_send_error');
                 throw new UserRegistrationException($message, '/register/confirm');
index 9a8affa8842fbe7e0a944462f5ee24770d752a79..df8c44d351cc92784bc8adaec1f642ea0c1719a0 100644 (file)
@@ -44,6 +44,10 @@ class Authenticate
             ], 401);
         }
 
+        if (session()->get('sent-email-confirmation') === true) {
+            return redirect('/register/confirm');
+        }
+
         return redirect('/register/confirm/awaiting');
     }
 }
index 92dd22ac47265be32b19817e5ef17e0482b95b36..e2b1e0cd66edcbae814bec9f055da290c8a0375d 100644 (file)
@@ -170,6 +170,11 @@ class AuthTest extends BrowserKitTest
             ->seePageIs('/register/confirm')
             ->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => false]);
 
+        $this->visit('/')
+            ->seePageIs('/register/confirm/awaiting');
+
+        auth()->logout();
+
         $this->visit('/')->seePageIs('/login')
             ->type($user->email, '#email')
             ->type($user->password, '#password')
@@ -202,6 +207,10 @@ class AuthTest extends BrowserKitTest
             ->seePageIs('/register/confirm')
             ->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => false]);
 
+        $this->visit('/')
+            ->seePageIs('/register/confirm/awaiting');
+
+        auth()->logout();
         $this->visit('/')->seePageIs('/login')
             ->type($user->email, '#email')
             ->type($user->password, '#password')
index 02b33ecd68687a41f3139276049b0b6cc3db1f26..3cb39ca2c59c63a8315a76c44ebbaed1881bbfe2 100644 (file)
@@ -620,7 +620,7 @@ class LdapTest extends BrowserKitTest
                 ]
             ]]);
 
-        $this->mockUserLogin()->seePageIs('/register/confirm/awaiting');
+        $this->mockUserLogin()->seePageIs('/register/confirm');
         $this->seeInDatabase('users', [
             'email' => $user->email,
             'email_confirmed' => false,
index df0bb81c19a0602a4bcf64a7d49fd148a9932da2..7303d4bd889fb9a13493eeda76101dbe0440f7c1 100644 (file)
@@ -304,7 +304,9 @@ class Saml2Test extends TestCase
 
         $this->withPost(['SAMLResponse' => $this->acsPostData], function () use ($memberRole, $adminRole) {
             $acsPost = $this->followingRedirects()->post('/saml2/acs');
-            $acsPost->assertSee('Your email address has not yet been confirmed');
+
+            $this->assertEquals('http://localhost/register/confirm', url()->current());
+            $acsPost->assertSee('Please check your email and click the confirmation button to access BookStack.');
             $user = User::query()->where('external_auth_id', '=', 'user')->first();
 
             $userRoleIds = $user->roles()->pluck('id');