Add SessionHandler::changeUserAfterMultifactor()
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 5 Nov 2020 15:22:50 +0000 (16:22 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 16 Nov 2020 16:25:16 +0000 (17:25 +0100)
wcfsetup/install/files/lib/system/session/SessionHandler.class.php
wcfsetup/setup/db/install.sql

index 64e6269dfde70ab5095809252e285b9d0b00939a..e7b3392255fc5156cc4f4d13344244198e2c9f2d 100644 (file)
@@ -691,6 +691,29 @@ final class SessionHandler extends SingletonFactory {
                }
        }
        
+       /**
+        * If multifactor authentication is enabled for the given user then
+        * - the userID will be stored in the session variables, and
+        * - `true` is returned.
+        * Otherwise,
+        * - `changeUser()` will be called, and
+        * - `false` is returned.
+        * 
+        * If `true` is returned you should perform a redirect to `MultifactorAuthenticationForm`.
+        */
+       public function changeUserAfterMultifactor(User $user): bool {
+               if ($user->multifactorActive) {
+                       $this->register('__changeUserAfterMultifactor__', $user->userID);
+                       
+                       return true;
+               }
+               else {
+                       $this->changeUser($user);
+                       
+                       return false;
+               }
+       }
+       
        /**
         * Stores a new user object in this session, e.g. a user was guest because not
         * logged in, after the login his old session is used to store his full data.
index aeafdc53f78ad09ed383887fdd6a8fa14c2e39ce..a1ef45d6ba353807c3e53de14e08008a3d932157 100644 (file)
@@ -1450,6 +1450,7 @@ CREATE TABLE wcf1_user (
        email VARCHAR(191) NOT NULL DEFAULT '',
        password VARCHAR(255) NOT NULL DEFAULT 'invalid:',
        accessToken CHAR(40) NOT NULL DEFAULT '',
+       multifactorActive TINYINT(1) NOT NULL DEFAULT 0,
        languageID INT(10) NOT NULL DEFAULT 0,
        registrationDate INT(10) NOT NULL DEFAULT 0,
        styleID INT(10) NOT NULL DEFAULT 0,