Code Duplication    Length = 7-10 lines in 4 locations

includes/Pages/UserAuth/MultiFactor/PageMultiFactor.php 4 locations

@@ 81-87 (lines=7) @@
78
                    SessionAlert::success('Enabled YubiKey OTP.');
79
80
                    $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
81
                    if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
82
                        $scratchProvider->setCredential($currentUser, 2, null);
83
                        $tokens = $scratchProvider->getTokens();
84
                        $this->assign('tokens', $tokens);
85
                        $this->setTemplate('mfa/regenScratchTokens.tpl');
86
                        return;
87
                    }
88
                }
89
                catch (ApplicationLogicException $ex) {
90
                    SessionAlert::error('Error enabling YubiKey OTP: ' . $ex->getMessage());
@@ 181-187 (lines=7) @@
178
                        SessionAlert::success('Enabled TOTP.');
179
180
                        $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
181
                        if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
182
                            $scratchProvider->setCredential($currentUser, 2, null);
183
                            $tokens = $scratchProvider->getTokens();
184
                            $this->assign('tokens', $tokens);
185
                            $this->setTemplate('mfa/regenScratchTokens.tpl');
186
                            return;
187
                        }
188
                    }
189
                    else {
190
                        $otpCredentialProvider->deleteCredential($currentUser);
@@ 306-312 (lines=7) @@
303
                    SessionAlert::success('Enabled TOTP.');
304
305
                    $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
306
                    if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
307
                        $scratchProvider->setCredential($currentUser, 2, null);
308
                        $tokens = $scratchProvider->getTokens();
309
                        $this->assign('tokens', $tokens);
310
                        $this->setTemplate('mfa/regenScratchTokens.tpl');
311
                        return;
312
                    }
313
314
                    $this->redirect('multiFactor');
315
                    return;
@@ 368-377 (lines=10) @@
365
366
            $result = $passwordCredentialProvider->authenticate($currentUser, $password);
367
368
            if ($result) {
369
                $otpCredentialProvider->setCredential($currentUser, 2, null);
370
                $tokens = $otpCredentialProvider->getTokens();
371
                $this->assign('tokens', $tokens);
372
                $this->setTemplate('mfa/regenScratchTokens.tpl');
373
            }
374
            else {
375
                SessionAlert::error('Error refreshing scratch tokens - invalid credentials.');
376
                $this->redirect('multiFactor');
377
            }
378
        }
379
        else {
380
            $this->assignCSRFToken();