Failed Conditions
Push — master ( e752cb...275fdb )
by Michael
10:48
created
includes/Pages/UserAuth/PagePreferences.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,8 +46,7 @@
 block discarded – undo
46 46
             SessionAlert::success("Preferences updated!");
47 47
 
48 48
             $this->redirect('');
49
-        }
50
-        else {
49
+        } else {
51 50
             $this->assignCSRFToken();
52 51
             $this->setTemplate('preferences/prefs.tpl');
53 52
             $this->assign("enforceOAuth", $enforceOAuth);
Please login to merge, or discard this patch.
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -16,98 +16,98 @@
 block discarded – undo
16 16
 
17 17
 class PagePreferences extends InternalPageBase
18 18
 {
19
-    /**
20
-     * Main function for this page, when no specific actions are called.
21
-     * @return void
22
-     */
23
-    protected function main()
24
-    {
25
-        $this->setHtmlTitle('Preferences');
26
-
27
-        $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth();
28
-        $database = $this->getDatabase();
29
-        $user = User::getCurrent($database);
30
-
31
-        // Dual mode
32
-        if (WebRequest::wasPosted()) {
33
-            $this->validateCSRFToken();
34
-            $user->setWelcomeSig(WebRequest::postString('sig'));
35
-            $user->setEmailSig(WebRequest::postString('emailsig'));
36
-            $user->setAbortPref(WebRequest::postBoolean('abortpref') ? 1 : 0);
37
-            $this->setCreationMode($user);
38
-
39
-            $newSkin = WebRequest::postString('skintype');
40
-            if ($newSkin === 'main' || $newSkin === 'alt' || $newSkin === 'auto') {
41
-                $user->setSkin($newSkin);
42
-            }
43
-
44
-            $email = WebRequest::postEmail('email');
45
-            if ($email !== null) {
46
-                $user->setEmail($email);
47
-            }
48
-
49
-            $user->save();
50
-            SessionAlert::success("Preferences updated!");
51
-
52
-            $this->redirect('');
53
-        }
54
-        else {
55
-            $this->assignCSRFToken();
56
-            $this->setTemplate('preferences/prefs.tpl');
57
-            $this->assign("enforceOAuth", $enforceOAuth);
58
-
59
-            $this->assign('canManualCreate',
60
-                $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'));
61
-            $this->assign('canOauthCreate',
62
-                $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'));
63
-            $this->assign('canBotCreate',
64
-                $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'));
65
-
66
-            $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
67
-                $this->getSiteConfiguration());
68
-            $this->assign('oauth', $oauth);
69
-
70
-            $identity = null;
71
-            if ($oauth->isFullyLinked()) {
72
-                $identity = $oauth->getIdentity();
73
-            }
74
-
75
-            $this->assign('identity', $identity);
76
-            $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime());
77
-        }
78
-    }
79
-
80
-    protected function refreshOAuth()
81
-    {
82
-        if (!WebRequest::wasPosted()) {
83
-            $this->redirect('preferences');
84
-
85
-            return;
86
-        }
87
-
88
-        $database = $this->getDatabase();
89
-        $oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(),
90
-            $this->getSiteConfiguration());
91
-        if ($oauth->isFullyLinked()) {
92
-            $oauth->refreshIdentity();
93
-        }
94
-
95
-        $this->redirect('preferences');
96
-
97
-        return;
98
-    }
99
-
100
-    /**
101
-     * @param User $user
102
-     */
103
-    protected function setCreationMode(User $user)
104
-    {
105
-        // if the user is selecting a creation mode that they are not allowed, do nothing.
106
-        // this has the side effect of allowing them to keep a selected mode that either has been changed for them,
107
-        // or that they have kept from when they previously had certain access.
108
-        $creationMode = WebRequest::postInt('creationmode');
109
-        if ($this->barrierTest($creationMode, $user, 'RequestCreation')) {
110
-            $user->setCreationMode($creationMode);
111
-        }
112
-    }
19
+	/**
20
+	 * Main function for this page, when no specific actions are called.
21
+	 * @return void
22
+	 */
23
+	protected function main()
24
+	{
25
+		$this->setHtmlTitle('Preferences');
26
+
27
+		$enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth();
28
+		$database = $this->getDatabase();
29
+		$user = User::getCurrent($database);
30
+
31
+		// Dual mode
32
+		if (WebRequest::wasPosted()) {
33
+			$this->validateCSRFToken();
34
+			$user->setWelcomeSig(WebRequest::postString('sig'));
35
+			$user->setEmailSig(WebRequest::postString('emailsig'));
36
+			$user->setAbortPref(WebRequest::postBoolean('abortpref') ? 1 : 0);
37
+			$this->setCreationMode($user);
38
+
39
+			$newSkin = WebRequest::postString('skintype');
40
+			if ($newSkin === 'main' || $newSkin === 'alt' || $newSkin === 'auto') {
41
+				$user->setSkin($newSkin);
42
+			}
43
+
44
+			$email = WebRequest::postEmail('email');
45
+			if ($email !== null) {
46
+				$user->setEmail($email);
47
+			}
48
+
49
+			$user->save();
50
+			SessionAlert::success("Preferences updated!");
51
+
52
+			$this->redirect('');
53
+		}
54
+		else {
55
+			$this->assignCSRFToken();
56
+			$this->setTemplate('preferences/prefs.tpl');
57
+			$this->assign("enforceOAuth", $enforceOAuth);
58
+
59
+			$this->assign('canManualCreate',
60
+				$this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'));
61
+			$this->assign('canOauthCreate',
62
+				$this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'));
63
+			$this->assign('canBotCreate',
64
+				$this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'));
65
+
66
+			$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
67
+				$this->getSiteConfiguration());
68
+			$this->assign('oauth', $oauth);
69
+
70
+			$identity = null;
71
+			if ($oauth->isFullyLinked()) {
72
+				$identity = $oauth->getIdentity();
73
+			}
74
+
75
+			$this->assign('identity', $identity);
76
+			$this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime());
77
+		}
78
+	}
79
+
80
+	protected function refreshOAuth()
81
+	{
82
+		if (!WebRequest::wasPosted()) {
83
+			$this->redirect('preferences');
84
+
85
+			return;
86
+		}
87
+
88
+		$database = $this->getDatabase();
89
+		$oauth = new OAuthUserHelper(User::getCurrent($database), $database, $this->getOAuthProtocolHelper(),
90
+			$this->getSiteConfiguration());
91
+		if ($oauth->isFullyLinked()) {
92
+			$oauth->refreshIdentity();
93
+		}
94
+
95
+		$this->redirect('preferences');
96
+
97
+		return;
98
+	}
99
+
100
+	/**
101
+	 * @param User $user
102
+	 */
103
+	protected function setCreationMode(User $user)
104
+	{
105
+		// if the user is selecting a creation mode that they are not allowed, do nothing.
106
+		// this has the side effect of allowing them to keep a selected mode that either has been changed for them,
107
+		// or that they have kept from when they previously had certain access.
108
+		$creationMode = WebRequest::postInt('creationmode');
109
+		if ($this->barrierTest($creationMode, $user, 'RequestCreation')) {
110
+			$user->setCreationMode($creationMode);
111
+		}
112
+	}
113 113
 }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/MultiFactor/PageMultiFactor.php 3 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
                     SessionAlert::success('Enabled YubiKey OTP.');
82 82
 
83 83
                     $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
84
-                    if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
84
+                    if ($scratchProvider->getRemaining($currentUser->getId()) < 3) {
85 85
                         $scratchProvider->setCredential($currentUser, 2, null);
86 86
                         $tokens = $scratchProvider->getTokens();
87 87
                         $this->assign('tokens', $tokens);
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
                         SessionAlert::success('Enabled TOTP.');
182 182
 
183 183
                         $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
184
-                        if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
184
+                        if ($scratchProvider->getRemaining($currentUser->getId()) < 3) {
185 185
                             $scratchProvider->setCredential($currentUser, 2, null);
186 186
                             $tokens = $scratchProvider->getTokens();
187 187
                             $this->assign('tokens', $tokens);
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 
262 262
                     list($data, $reqs) = $otpCredentialProvider->getRegistrationData();
263 263
 
264
-                    $u2fRequest =json_encode($data);
264
+                    $u2fRequest = json_encode($data);
265 265
                     $u2fSigns = json_encode($reqs);
266 266
 
267 267
                     $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js');
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                     SessionAlert::success('Enabled U2F.');
311 311
 
312 312
                     $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
313
-                    if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
313
+                    if ($scratchProvider->getRemaining($currentUser->getId()) < 3) {
314 314
                         $scratchProvider->setCredential($currentUser, 2, null);
315 315
                         $tokens = $scratchProvider->getTokens();
316 316
                         $this->assign('tokens', $tokens);
Please login to merge, or discard this patch.
Braces   +17 added lines, -28 removed lines patch added patch discarded remove patch
@@ -94,13 +94,11 @@  discard block
 block discarded – undo
94 94
                 }
95 95
 
96 96
                 $this->redirect('multiFactor');
97
-            }
98
-            else {
97
+            } else {
99 98
                 SessionAlert::error('Error enabling YubiKey OTP - invalid credentials.');
100 99
                 $this->redirect('multiFactor');
101 100
             }
102
-        }
103
-        else {
101
+        } else {
104 102
             if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
105 103
                 // user is not enrolled, we shouldn't have got here.
106 104
                 throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
@@ -162,8 +160,7 @@  discard block
 block discarded – undo
162 160
                     $this->setTemplate('mfa/enableTotpEnroll.tpl');
163 161
 
164 162
                     return;
165
-                }
166
-                else {
163
+                } else {
167 164
                     SessionAlert::error('Error enabling TOTP - invalid credentials.');
168 165
                     $this->redirect('multiFactor');
169 166
 
@@ -188,8 +185,7 @@  discard block
 block discarded – undo
188 185
                             $this->setTemplate('mfa/regenScratchTokens.tpl');
189 186
                             return;
190 187
                         }
191
-                    }
192
-                    else {
188
+                    } else {
193 189
                         $otpCredentialProvider->deleteCredential($currentUser);
194 190
                         SessionAlert::error('Error enabling TOTP: invalid token provided');
195 191
                     }
@@ -197,8 +193,7 @@  discard block
 block discarded – undo
197 193
 
198 194
                     $this->redirect('multiFactor');
199 195
                     return;
200
-                }
201
-                else {
196
+                } else {
202 197
                     SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.');
203 198
                     $this->redirect('multiFactor');
204 199
 
@@ -208,8 +203,7 @@  discard block
 block discarded – undo
208 203
 
209 204
             // urgh, dunno what happened, but it's not something expected.
210 205
             throw new ApplicationLogicException();
211
-        }
212
-        else {
206
+        } else {
213 207
             if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
214 208
                 // user is not enrolled, we shouldn't have got here.
215 209
                 throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
@@ -236,7 +230,8 @@  discard block
 block discarded – undo
236 230
         $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType);
237 231
     }
238 232
 
239
-    protected function enableU2F() {
233
+    protected function enableU2F()
234
+    {
240 235
         $database = $this->getDatabase();
241 236
         $currentUser = User::getCurrent($database);
242 237
 
@@ -289,8 +284,7 @@  discard block
 block discarded – undo
289 284
                     $this->setTemplate('mfa/enableU2FEnroll.tpl');
290 285
 
291 286
                     return;
292
-                }
293
-                else {
287
+                } else {
294 288
                     SessionAlert::error('Error enabling TOTP - invalid credentials.');
295 289
                     $this->redirect('multiFactor');
296 290
 
@@ -320,8 +314,7 @@  discard block
 block discarded – undo
320 314
 
321 315
                     $this->redirect('multiFactor');
322 316
                     return;
323
-                }
324
-                else {
317
+                } else {
325 318
                     SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.');
326 319
                     $this->redirect('multiFactor');
327 320
 
@@ -331,8 +324,7 @@  discard block
 block discarded – undo
331 324
 
332 325
             // urgh, dunno what happened, but it's not something expected.
333 326
             throw new ApplicationLogicException();
334
-        }
335
-        else {
327
+        } else {
336 328
             if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
337 329
                 // user is not enrolled, we shouldn't have got here.
338 330
                 throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
@@ -347,7 +339,8 @@  discard block
 block discarded – undo
347 339
         }
348 340
     }
349 341
 
350
-    protected function disableU2F() {
342
+    protected function disableU2F()
343
+    {
351 344
         $database = $this->getDatabase();
352 345
         $currentUser = User::getCurrent($database);
353 346
 
@@ -381,13 +374,11 @@  discard block
 block discarded – undo
381 374
                 $tokens = $otpCredentialProvider->getTokens();
382 375
                 $this->assign('tokens', $tokens);
383 376
                 $this->setTemplate('mfa/regenScratchTokens.tpl');
384
-            }
385
-            else {
377
+            } else {
386 378
                 SessionAlert::error('Error refreshing scratch tokens - invalid credentials.');
387 379
                 $this->redirect('multiFactor');
388 380
             }
389
-        }
390
-        else {
381
+        } else {
391 382
             $this->assignCSRFToken();
392 383
 
393 384
             $this->assign('alertmessage', 'To regenerate your emergency scratch tokens, please prove you are who you say you are by providing the information below. Note that continuing will invalidate all remaining scratch tokens, and provide a set of new ones.');
@@ -425,13 +416,11 @@  discard block
 block discarded – undo
425 416
                 $otpCredentialProvider->deleteCredential($currentUser);
426 417
                 SessionAlert::success('Disabled ' . $factorType . '.');
427 418
                 $this->redirect('multiFactor');
428
-            }
429
-            else {
419
+            } else {
430 420
                 SessionAlert::error('Error disabling ' . $factorType . ' - invalid credentials.');
431 421
                 $this->redirect('multiFactor');
432 422
             }
433
-        }
434
-        else {
423
+        } else {
435 424
             if (!$otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
436 425
                 // user is not enrolled, we shouldn't have got here.
437 426
                 throw new ApplicationLogicException('User is not enrolled in the selected MFA mechanism');
Please login to merge, or discard this patch.
Indentation   +389 added lines, -389 removed lines patch added patch discarded remove patch
@@ -27,249 +27,249 @@  discard block
 block discarded – undo
27 27
 
28 28
 class PageMultiFactor extends InternalPageBase
29 29
 {
30
-    /**
31
-     * Main function for this page, when no specific actions are called.
32
-     * @return void
33
-     */
34
-    protected function main()
35
-    {
36
-        $database = $this->getDatabase();
37
-        $currentUser = User::getCurrent($database);
38
-
39
-        $yubikeyOtpCredentialProvider = new YubikeyOtpCredentialProvider($database, $this->getSiteConfiguration(),
40
-            $this->getHttpHelper());
41
-        $this->assign('yubikeyOtpIdentity', $yubikeyOtpCredentialProvider->getYubikeyData($currentUser->getId()));
42
-        $this->assign('yubikeyOtpEnrolled', $yubikeyOtpCredentialProvider->userIsEnrolled($currentUser->getId()));
43
-
44
-        $totpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration());
45
-        $this->assign('totpEnrolled', $totpCredentialProvider->userIsEnrolled($currentUser->getId()));
46
-
47
-        $u2fCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration());
48
-        $this->assign('u2fEnrolled', $u2fCredentialProvider->userIsEnrolled($currentUser->getId()));
49
-
50
-        $scratchCredentialProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
51
-        $this->assign('scratchEnrolled', $scratchCredentialProvider->userIsEnrolled($currentUser->getId()));
52
-        $this->assign('scratchRemaining', $scratchCredentialProvider->getRemaining($currentUser->getId()));
53
-
54
-        $this->assign('allowedTotp', $this->barrierTest('enableTotp', $currentUser));
55
-        $this->assign('allowedYubikey', $this->barrierTest('enableYubikeyOtp', $currentUser));
56
-        $this->assign('allowedU2f', $this->barrierTest('enableU2F', $currentUser));
57
-
58
-        $this->setTemplate('mfa/mfa.tpl');
59
-    }
60
-
61
-    protected function enableYubikeyOtp()
62
-    {
63
-        $database = $this->getDatabase();
64
-        $currentUser = User::getCurrent($database);
65
-
66
-        $otpCredentialProvider = new YubikeyOtpCredentialProvider($database,
67
-            $this->getSiteConfiguration(), $this->getHttpHelper());
68
-
69
-        if (WebRequest::wasPosted()) {
70
-            $this->validateCSRFToken();
71
-
72
-            $passwordCredentialProvider = new PasswordCredentialProvider($database,
73
-                $this->getSiteConfiguration());
74
-
75
-            $password = WebRequest::postString('password');
76
-            $otp = WebRequest::postString('otp');
77
-
78
-            $result = $passwordCredentialProvider->authenticate($currentUser, $password);
79
-
80
-            if ($result) {
81
-                try {
82
-                    $otpCredentialProvider->setCredential($currentUser, 2, $otp);
83
-                    SessionAlert::success('Enabled YubiKey OTP.');
84
-
85
-                    $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
86
-                    if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
87
-                        $scratchProvider->setCredential($currentUser, 2, null);
88
-                        $tokens = $scratchProvider->getTokens();
89
-                        $this->assign('tokens', $tokens);
90
-                        $this->setTemplate('mfa/regenScratchTokens.tpl');
91
-                        return;
92
-                    }
93
-                }
94
-                catch (ApplicationLogicException $ex) {
95
-                    SessionAlert::error('Error enabling YubiKey OTP: ' . $ex->getMessage());
96
-                }
97
-
98
-                $this->redirect('multiFactor');
99
-            }
100
-            else {
101
-                SessionAlert::error('Error enabling YubiKey OTP - invalid credentials.');
102
-                $this->redirect('multiFactor');
103
-            }
104
-        }
105
-        else {
106
-            if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
107
-                // user is not enrolled, we shouldn't have got here.
108
-                throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
109
-            }
110
-
111
-            $this->assignCSRFToken();
112
-            $this->setTemplate('mfa/enableYubikey.tpl');
113
-        }
114
-    }
115
-
116
-    protected function disableYubikeyOtp()
117
-    {
118
-        $database = $this->getDatabase();
119
-        $currentUser = User::getCurrent($database);
120
-
121
-        $otpCredentialProvider = new YubikeyOtpCredentialProvider($database,
122
-            $this->getSiteConfiguration(), $this->getHttpHelper());
123
-
124
-        $factorType = 'YubiKey OTP';
125
-
126
-        $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType);
127
-    }
128
-
129
-    protected function enableTotp()
130
-    {
131
-        $database = $this->getDatabase();
132
-        $currentUser = User::getCurrent($database);
133
-
134
-        $otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration());
135
-
136
-        if (WebRequest::wasPosted()) {
137
-            $this->validateCSRFToken();
138
-
139
-            // used for routing only, not security
140
-            $stage = WebRequest::postString('stage');
141
-
142
-            if ($stage === "auth") {
143
-                $password = WebRequest::postString('password');
144
-
145
-                $passwordCredentialProvider = new PasswordCredentialProvider($database,
146
-                    $this->getSiteConfiguration());
147
-                $result = $passwordCredentialProvider->authenticate($currentUser, $password);
148
-
149
-                if ($result) {
150
-                    $otpCredentialProvider->setCredential($currentUser, 2, null);
151
-
152
-                    $provisioningUrl = $otpCredentialProvider->getProvisioningUrl($currentUser);
153
-
154
-                    $renderer = new ImageRenderer(
155
-                        new RendererStyle(256),
156
-                        new SvgImageBackEnd()
157
-                    );
158
-
159
-                    $writer = new Writer($renderer);
160
-                    $svg = $writer->writeString($provisioningUrl);
161
-
162
-                    $this->assign('svg', $svg);
163
-                    $this->assign('secret', $otpCredentialProvider->getSecret($currentUser));
164
-
165
-                    $this->assignCSRFToken();
166
-                    $this->setTemplate('mfa/enableTotpEnroll.tpl');
167
-
168
-                    return;
169
-                }
170
-                else {
171
-                    SessionAlert::error('Error enabling TOTP - invalid credentials.');
172
-                    $this->redirect('multiFactor');
173
-
174
-                    return;
175
-                }
176
-            }
177
-
178
-            if ($stage === "enroll") {
179
-                // we *must* have a defined credential already here,
180
-                if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) {
181
-                    $otp = WebRequest::postString('otp');
182
-                    $result = $otpCredentialProvider->verifyEnable($currentUser, $otp);
183
-
184
-                    if ($result) {
185
-                        SessionAlert::success('Enabled TOTP.');
186
-
187
-                        $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
188
-                        if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
189
-                            $scratchProvider->setCredential($currentUser, 2, null);
190
-                            $tokens = $scratchProvider->getTokens();
191
-                            $this->assign('tokens', $tokens);
192
-                            $this->setTemplate('mfa/regenScratchTokens.tpl');
193
-                            return;
194
-                        }
195
-                    }
196
-                    else {
197
-                        $otpCredentialProvider->deleteCredential($currentUser);
198
-                        SessionAlert::error('Error enabling TOTP: invalid token provided');
199
-                    }
200
-
201
-
202
-                    $this->redirect('multiFactor');
203
-                    return;
204
-                }
205
-                else {
206
-                    SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.');
207
-                    $this->redirect('multiFactor');
30
+	/**
31
+	 * Main function for this page, when no specific actions are called.
32
+	 * @return void
33
+	 */
34
+	protected function main()
35
+	{
36
+		$database = $this->getDatabase();
37
+		$currentUser = User::getCurrent($database);
38
+
39
+		$yubikeyOtpCredentialProvider = new YubikeyOtpCredentialProvider($database, $this->getSiteConfiguration(),
40
+			$this->getHttpHelper());
41
+		$this->assign('yubikeyOtpIdentity', $yubikeyOtpCredentialProvider->getYubikeyData($currentUser->getId()));
42
+		$this->assign('yubikeyOtpEnrolled', $yubikeyOtpCredentialProvider->userIsEnrolled($currentUser->getId()));
43
+
44
+		$totpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration());
45
+		$this->assign('totpEnrolled', $totpCredentialProvider->userIsEnrolled($currentUser->getId()));
46
+
47
+		$u2fCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration());
48
+		$this->assign('u2fEnrolled', $u2fCredentialProvider->userIsEnrolled($currentUser->getId()));
49
+
50
+		$scratchCredentialProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
51
+		$this->assign('scratchEnrolled', $scratchCredentialProvider->userIsEnrolled($currentUser->getId()));
52
+		$this->assign('scratchRemaining', $scratchCredentialProvider->getRemaining($currentUser->getId()));
53
+
54
+		$this->assign('allowedTotp', $this->barrierTest('enableTotp', $currentUser));
55
+		$this->assign('allowedYubikey', $this->barrierTest('enableYubikeyOtp', $currentUser));
56
+		$this->assign('allowedU2f', $this->barrierTest('enableU2F', $currentUser));
57
+
58
+		$this->setTemplate('mfa/mfa.tpl');
59
+	}
60
+
61
+	protected function enableYubikeyOtp()
62
+	{
63
+		$database = $this->getDatabase();
64
+		$currentUser = User::getCurrent($database);
65
+
66
+		$otpCredentialProvider = new YubikeyOtpCredentialProvider($database,
67
+			$this->getSiteConfiguration(), $this->getHttpHelper());
68
+
69
+		if (WebRequest::wasPosted()) {
70
+			$this->validateCSRFToken();
71
+
72
+			$passwordCredentialProvider = new PasswordCredentialProvider($database,
73
+				$this->getSiteConfiguration());
74
+
75
+			$password = WebRequest::postString('password');
76
+			$otp = WebRequest::postString('otp');
77
+
78
+			$result = $passwordCredentialProvider->authenticate($currentUser, $password);
79
+
80
+			if ($result) {
81
+				try {
82
+					$otpCredentialProvider->setCredential($currentUser, 2, $otp);
83
+					SessionAlert::success('Enabled YubiKey OTP.');
84
+
85
+					$scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
86
+					if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
87
+						$scratchProvider->setCredential($currentUser, 2, null);
88
+						$tokens = $scratchProvider->getTokens();
89
+						$this->assign('tokens', $tokens);
90
+						$this->setTemplate('mfa/regenScratchTokens.tpl');
91
+						return;
92
+					}
93
+				}
94
+				catch (ApplicationLogicException $ex) {
95
+					SessionAlert::error('Error enabling YubiKey OTP: ' . $ex->getMessage());
96
+				}
97
+
98
+				$this->redirect('multiFactor');
99
+			}
100
+			else {
101
+				SessionAlert::error('Error enabling YubiKey OTP - invalid credentials.');
102
+				$this->redirect('multiFactor');
103
+			}
104
+		}
105
+		else {
106
+			if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
107
+				// user is not enrolled, we shouldn't have got here.
108
+				throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
109
+			}
110
+
111
+			$this->assignCSRFToken();
112
+			$this->setTemplate('mfa/enableYubikey.tpl');
113
+		}
114
+	}
115
+
116
+	protected function disableYubikeyOtp()
117
+	{
118
+		$database = $this->getDatabase();
119
+		$currentUser = User::getCurrent($database);
120
+
121
+		$otpCredentialProvider = new YubikeyOtpCredentialProvider($database,
122
+			$this->getSiteConfiguration(), $this->getHttpHelper());
123
+
124
+		$factorType = 'YubiKey OTP';
125
+
126
+		$this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType);
127
+	}
208 128
 
209
-                    return;
210
-                }
211
-            }
129
+	protected function enableTotp()
130
+	{
131
+		$database = $this->getDatabase();
132
+		$currentUser = User::getCurrent($database);
133
+
134
+		$otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration());
135
+
136
+		if (WebRequest::wasPosted()) {
137
+			$this->validateCSRFToken();
138
+
139
+			// used for routing only, not security
140
+			$stage = WebRequest::postString('stage');
141
+
142
+			if ($stage === "auth") {
143
+				$password = WebRequest::postString('password');
144
+
145
+				$passwordCredentialProvider = new PasswordCredentialProvider($database,
146
+					$this->getSiteConfiguration());
147
+				$result = $passwordCredentialProvider->authenticate($currentUser, $password);
148
+
149
+				if ($result) {
150
+					$otpCredentialProvider->setCredential($currentUser, 2, null);
151
+
152
+					$provisioningUrl = $otpCredentialProvider->getProvisioningUrl($currentUser);
153
+
154
+					$renderer = new ImageRenderer(
155
+						new RendererStyle(256),
156
+						new SvgImageBackEnd()
157
+					);
158
+
159
+					$writer = new Writer($renderer);
160
+					$svg = $writer->writeString($provisioningUrl);
161
+
162
+					$this->assign('svg', $svg);
163
+					$this->assign('secret', $otpCredentialProvider->getSecret($currentUser));
164
+
165
+					$this->assignCSRFToken();
166
+					$this->setTemplate('mfa/enableTotpEnroll.tpl');
167
+
168
+					return;
169
+				}
170
+				else {
171
+					SessionAlert::error('Error enabling TOTP - invalid credentials.');
172
+					$this->redirect('multiFactor');
173
+
174
+					return;
175
+				}
176
+			}
177
+
178
+			if ($stage === "enroll") {
179
+				// we *must* have a defined credential already here,
180
+				if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) {
181
+					$otp = WebRequest::postString('otp');
182
+					$result = $otpCredentialProvider->verifyEnable($currentUser, $otp);
183
+
184
+					if ($result) {
185
+						SessionAlert::success('Enabled TOTP.');
186
+
187
+						$scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
188
+						if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
189
+							$scratchProvider->setCredential($currentUser, 2, null);
190
+							$tokens = $scratchProvider->getTokens();
191
+							$this->assign('tokens', $tokens);
192
+							$this->setTemplate('mfa/regenScratchTokens.tpl');
193
+							return;
194
+						}
195
+					}
196
+					else {
197
+						$otpCredentialProvider->deleteCredential($currentUser);
198
+						SessionAlert::error('Error enabling TOTP: invalid token provided');
199
+					}
200
+
201
+
202
+					$this->redirect('multiFactor');
203
+					return;
204
+				}
205
+				else {
206
+					SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.');
207
+					$this->redirect('multiFactor');
208
+
209
+					return;
210
+				}
211
+			}
212
+
213
+			// urgh, dunno what happened, but it's not something expected.
214
+			throw new ApplicationLogicException();
215
+		}
216
+		else {
217
+			if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
218
+				// user is not enrolled, we shouldn't have got here.
219
+				throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
220
+			}
221
+
222
+			$this->assignCSRFToken();
223
+
224
+			$this->assign('alertmessage', 'To enable your multi-factor credentials, please prove you are who you say you are by providing the information below.');
225
+			$this->assign('alertheader', 'Provide credentials');
226
+			$this->assign('continueText', 'Verify password');
227
+			$this->setTemplate('mfa/enableAuth.tpl');
228
+		}
229
+	}
230
+
231
+	protected function disableTotp()
232
+	{
233
+		$database = $this->getDatabase();
234
+		$currentUser = User::getCurrent($database);
235
+
236
+		$otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration());
237
+
238
+		$factorType = 'TOTP';
212 239
 
213
-            // urgh, dunno what happened, but it's not something expected.
214
-            throw new ApplicationLogicException();
215
-        }
216
-        else {
217
-            if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
218
-                // user is not enrolled, we shouldn't have got here.
219
-                throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
220
-            }
240
+		$this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType);
241
+	}
221 242
 
222
-            $this->assignCSRFToken();
243
+	protected function enableU2F() {
244
+		$database = $this->getDatabase();
245
+		$currentUser = User::getCurrent($database);
223 246
 
224
-            $this->assign('alertmessage', 'To enable your multi-factor credentials, please prove you are who you say you are by providing the information below.');
225
-            $this->assign('alertheader', 'Provide credentials');
226
-            $this->assign('continueText', 'Verify password');
227
-            $this->setTemplate('mfa/enableAuth.tpl');
228
-        }
229
-    }
247
+		$otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration());
230 248
 
231
-    protected function disableTotp()
232
-    {
233
-        $database = $this->getDatabase();
234
-        $currentUser = User::getCurrent($database);
249
+		if (WebRequest::wasPosted()) {
250
+			$this->validateCSRFToken();
235 251
 
236
-        $otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration());
252
+			// used for routing only, not security
253
+			$stage = WebRequest::postString('stage');
237 254
 
238
-        $factorType = 'TOTP';
255
+			if ($stage === "auth") {
256
+				$password = WebRequest::postString('password');
239 257
 
240
-        $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType);
241
-    }
258
+				$passwordCredentialProvider = new PasswordCredentialProvider($database,
259
+					$this->getSiteConfiguration());
260
+				$result = $passwordCredentialProvider->authenticate($currentUser, $password);
242 261
 
243
-    protected function enableU2F() {
244
-        $database = $this->getDatabase();
245
-        $currentUser = User::getCurrent($database);
262
+				if ($result) {
263
+					$otpCredentialProvider->setCredential($currentUser, 2, null);
264
+					$this->assignCSRFToken();
246 265
 
247
-        $otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration());
266
+					list($data, $reqs) = $otpCredentialProvider->getRegistrationData();
248 267
 
249
-        if (WebRequest::wasPosted()) {
250
-            $this->validateCSRFToken();
268
+					$u2fRequest =json_encode($data);
269
+					$u2fSigns = json_encode($reqs);
251 270
 
252
-            // used for routing only, not security
253
-            $stage = WebRequest::postString('stage');
254
-
255
-            if ($stage === "auth") {
256
-                $password = WebRequest::postString('password');
257
-
258
-                $passwordCredentialProvider = new PasswordCredentialProvider($database,
259
-                    $this->getSiteConfiguration());
260
-                $result = $passwordCredentialProvider->authenticate($currentUser, $password);
261
-
262
-                if ($result) {
263
-                    $otpCredentialProvider->setCredential($currentUser, 2, null);
264
-                    $this->assignCSRFToken();
265
-
266
-                    list($data, $reqs) = $otpCredentialProvider->getRegistrationData();
267
-
268
-                    $u2fRequest =json_encode($data);
269
-                    $u2fSigns = json_encode($reqs);
270
-
271
-                    $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js');
272
-                    $this->setTailScript($this->getCspManager()->getNonce(), <<<JS
271
+					$this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js');
272
+					$this->setTailScript($this->getCspManager()->getNonce(), <<<JS
273 273
 var request = ${u2fRequest};
274 274
 var signs = ${u2fSigns};
275 275
 
@@ -288,162 +288,162 @@  discard block
 block discarded – undo
288 288
 	form.submit();
289 289
 });
290 290
 JS
291
-                    );
292
-
293
-                    $this->setTemplate('mfa/enableU2FEnroll.tpl');
294
-
295
-                    return;
296
-                }
297
-                else {
298
-                    SessionAlert::error('Error enabling TOTP - invalid credentials.');
299
-                    $this->redirect('multiFactor');
300
-
301
-                    return;
302
-                }
303
-            }
304
-
305
-            if ($stage === "enroll") {
306
-                // we *must* have a defined credential already here,
307
-                if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) {
308
-
309
-                    $request = json_decode(WebRequest::postString('u2fRequest'));
310
-                    $u2fData = json_decode(WebRequest::postString('u2fData'));
311
-
312
-                    $otpCredentialProvider->enable($currentUser, $request, $u2fData);
313
-
314
-                    SessionAlert::success('Enabled U2F.');
315
-
316
-                    $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
317
-                    if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
318
-                        $scratchProvider->setCredential($currentUser, 2, null);
319
-                        $tokens = $scratchProvider->getTokens();
320
-                        $this->assign('tokens', $tokens);
321
-                        $this->setTemplate('mfa/regenScratchTokens.tpl');
322
-                        return;
323
-                    }
324
-
325
-                    $this->redirect('multiFactor');
326
-                    return;
327
-                }
328
-                else {
329
-                    SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.');
330
-                    $this->redirect('multiFactor');
331
-
332
-                    return;
333
-                }
334
-            }
335
-
336
-            // urgh, dunno what happened, but it's not something expected.
337
-            throw new ApplicationLogicException();
338
-        }
339
-        else {
340
-            if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
341
-                // user is not enrolled, we shouldn't have got here.
342
-                throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
343
-            }
344
-
345
-            $this->assignCSRFToken();
346
-
347
-            $this->assign('alertmessage', 'To enable your multi-factor credentials, please prove you are who you say you are by providing the information below.');
348
-            $this->assign('alertheader', 'Provide credentials');
349
-            $this->assign('continueText', 'Verify password');
350
-            $this->setTemplate('mfa/enableAuth.tpl');
351
-        }
352
-    }
353
-
354
-    protected function disableU2F() {
355
-        $database = $this->getDatabase();
356
-        $currentUser = User::getCurrent($database);
357
-
358
-        $otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration());
359
-
360
-        $factorType = 'U2F';
361
-
362
-        $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType);
363
-    }
364
-
365
-    protected function scratch()
366
-    {
367
-        $database = $this->getDatabase();
368
-        $currentUser = User::getCurrent($database);
369
-
370
-        if (WebRequest::wasPosted()) {
371
-            $this->validateCSRFToken();
372
-
373
-            $passwordCredentialProvider = new PasswordCredentialProvider($database,
374
-                $this->getSiteConfiguration());
375
-
376
-            $otpCredentialProvider = new ScratchTokenCredentialProvider($database,
377
-                $this->getSiteConfiguration());
378
-
379
-            $password = WebRequest::postString('password');
380
-
381
-            $result = $passwordCredentialProvider->authenticate($currentUser, $password);
382
-
383
-            if ($result) {
384
-                $otpCredentialProvider->setCredential($currentUser, 2, null);
385
-                $tokens = $otpCredentialProvider->getTokens();
386
-                $this->assign('tokens', $tokens);
387
-                $this->setTemplate('mfa/regenScratchTokens.tpl');
388
-            }
389
-            else {
390
-                SessionAlert::error('Error refreshing scratch tokens - invalid credentials.');
391
-                $this->redirect('multiFactor');
392
-            }
393
-        }
394
-        else {
395
-            $this->assignCSRFToken();
396
-
397
-            $this->assign('alertmessage', 'To regenerate your emergency scratch tokens, please prove you are who you say you are by providing the information below. Note that continuing will invalidate all remaining scratch tokens, and provide a set of new ones.');
398
-            $this->assign('alertheader', 'Re-generate scratch tokens');
399
-            $this->assign('continueText', 'Regenerate Scratch Tokens');
400
-
401
-            $this->setTemplate('mfa/enableAuth.tpl');
402
-        }
403
-    }
404
-
405
-    /**
406
-     * @param PdoDatabase         $database
407
-     * @param User                $currentUser
408
-     * @param ICredentialProvider $otpCredentialProvider
409
-     * @param string              $factorType
410
-     *
411
-     * @throws ApplicationLogicException
412
-     */
413
-    private function deleteCredential(
414
-        PdoDatabase $database,
415
-        User $currentUser,
416
-        ICredentialProvider $otpCredentialProvider,
417
-        $factorType
418
-    ) {
419
-        if (WebRequest::wasPosted()) {
420
-            $passwordCredentialProvider = new PasswordCredentialProvider($database,
421
-                $this->getSiteConfiguration());
422
-
423
-            $this->validateCSRFToken();
424
-
425
-            $password = WebRequest::postString('password');
426
-            $result = $passwordCredentialProvider->authenticate($currentUser, $password);
427
-
428
-            if ($result) {
429
-                $otpCredentialProvider->deleteCredential($currentUser);
430
-                SessionAlert::success('Disabled ' . $factorType . '.');
431
-                $this->redirect('multiFactor');
432
-            }
433
-            else {
434
-                SessionAlert::error('Error disabling ' . $factorType . ' - invalid credentials.');
435
-                $this->redirect('multiFactor');
436
-            }
437
-        }
438
-        else {
439
-            if (!$otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
440
-                // user is not enrolled, we shouldn't have got here.
441
-                throw new ApplicationLogicException('User is not enrolled in the selected MFA mechanism');
442
-            }
443
-
444
-            $this->assignCSRFToken();
445
-            $this->assign('otpType', $factorType);
446
-            $this->setTemplate('mfa/disableOtp.tpl');
447
-        }
448
-    }
291
+					);
292
+
293
+					$this->setTemplate('mfa/enableU2FEnroll.tpl');
294
+
295
+					return;
296
+				}
297
+				else {
298
+					SessionAlert::error('Error enabling TOTP - invalid credentials.');
299
+					$this->redirect('multiFactor');
300
+
301
+					return;
302
+				}
303
+			}
304
+
305
+			if ($stage === "enroll") {
306
+				// we *must* have a defined credential already here,
307
+				if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) {
308
+
309
+					$request = json_decode(WebRequest::postString('u2fRequest'));
310
+					$u2fData = json_decode(WebRequest::postString('u2fData'));
311
+
312
+					$otpCredentialProvider->enable($currentUser, $request, $u2fData);
313
+
314
+					SessionAlert::success('Enabled U2F.');
315
+
316
+					$scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration());
317
+					if($scratchProvider->getRemaining($currentUser->getId()) < 3) {
318
+						$scratchProvider->setCredential($currentUser, 2, null);
319
+						$tokens = $scratchProvider->getTokens();
320
+						$this->assign('tokens', $tokens);
321
+						$this->setTemplate('mfa/regenScratchTokens.tpl');
322
+						return;
323
+					}
324
+
325
+					$this->redirect('multiFactor');
326
+					return;
327
+				}
328
+				else {
329
+					SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.');
330
+					$this->redirect('multiFactor');
331
+
332
+					return;
333
+				}
334
+			}
335
+
336
+			// urgh, dunno what happened, but it's not something expected.
337
+			throw new ApplicationLogicException();
338
+		}
339
+		else {
340
+			if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
341
+				// user is not enrolled, we shouldn't have got here.
342
+				throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism');
343
+			}
344
+
345
+			$this->assignCSRFToken();
346
+
347
+			$this->assign('alertmessage', 'To enable your multi-factor credentials, please prove you are who you say you are by providing the information below.');
348
+			$this->assign('alertheader', 'Provide credentials');
349
+			$this->assign('continueText', 'Verify password');
350
+			$this->setTemplate('mfa/enableAuth.tpl');
351
+		}
352
+	}
353
+
354
+	protected function disableU2F() {
355
+		$database = $this->getDatabase();
356
+		$currentUser = User::getCurrent($database);
357
+
358
+		$otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration());
359
+
360
+		$factorType = 'U2F';
361
+
362
+		$this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType);
363
+	}
364
+
365
+	protected function scratch()
366
+	{
367
+		$database = $this->getDatabase();
368
+		$currentUser = User::getCurrent($database);
369
+
370
+		if (WebRequest::wasPosted()) {
371
+			$this->validateCSRFToken();
372
+
373
+			$passwordCredentialProvider = new PasswordCredentialProvider($database,
374
+				$this->getSiteConfiguration());
375
+
376
+			$otpCredentialProvider = new ScratchTokenCredentialProvider($database,
377
+				$this->getSiteConfiguration());
378
+
379
+			$password = WebRequest::postString('password');
380
+
381
+			$result = $passwordCredentialProvider->authenticate($currentUser, $password);
382
+
383
+			if ($result) {
384
+				$otpCredentialProvider->setCredential($currentUser, 2, null);
385
+				$tokens = $otpCredentialProvider->getTokens();
386
+				$this->assign('tokens', $tokens);
387
+				$this->setTemplate('mfa/regenScratchTokens.tpl');
388
+			}
389
+			else {
390
+				SessionAlert::error('Error refreshing scratch tokens - invalid credentials.');
391
+				$this->redirect('multiFactor');
392
+			}
393
+		}
394
+		else {
395
+			$this->assignCSRFToken();
396
+
397
+			$this->assign('alertmessage', 'To regenerate your emergency scratch tokens, please prove you are who you say you are by providing the information below. Note that continuing will invalidate all remaining scratch tokens, and provide a set of new ones.');
398
+			$this->assign('alertheader', 'Re-generate scratch tokens');
399
+			$this->assign('continueText', 'Regenerate Scratch Tokens');
400
+
401
+			$this->setTemplate('mfa/enableAuth.tpl');
402
+		}
403
+	}
404
+
405
+	/**
406
+	 * @param PdoDatabase         $database
407
+	 * @param User                $currentUser
408
+	 * @param ICredentialProvider $otpCredentialProvider
409
+	 * @param string              $factorType
410
+	 *
411
+	 * @throws ApplicationLogicException
412
+	 */
413
+	private function deleteCredential(
414
+		PdoDatabase $database,
415
+		User $currentUser,
416
+		ICredentialProvider $otpCredentialProvider,
417
+		$factorType
418
+	) {
419
+		if (WebRequest::wasPosted()) {
420
+			$passwordCredentialProvider = new PasswordCredentialProvider($database,
421
+				$this->getSiteConfiguration());
422
+
423
+			$this->validateCSRFToken();
424
+
425
+			$password = WebRequest::postString('password');
426
+			$result = $passwordCredentialProvider->authenticate($currentUser, $password);
427
+
428
+			if ($result) {
429
+				$otpCredentialProvider->deleteCredential($currentUser);
430
+				SessionAlert::success('Disabled ' . $factorType . '.');
431
+				$this->redirect('multiFactor');
432
+			}
433
+			else {
434
+				SessionAlert::error('Error disabling ' . $factorType . ' - invalid credentials.');
435
+				$this->redirect('multiFactor');
436
+			}
437
+		}
438
+		else {
439
+			if (!$otpCredentialProvider->userIsEnrolled($currentUser->getId())) {
440
+				// user is not enrolled, we shouldn't have got here.
441
+				throw new ApplicationLogicException('User is not enrolled in the selected MFA mechanism');
442
+			}
443
+
444
+			$this->assignCSRFToken();
445
+			$this->assign('otpType', $factorType);
446
+			$this->setTemplate('mfa/disableOtp.tpl');
447
+		}
448
+	}
449 449
 }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageOAuth.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -22,81 +22,81 @@
 block discarded – undo
22 22
 
23 23
 class PageOAuth extends InternalPageBase
24 24
 {
25
-    /**
26
-     * Attach entry point
27
-     *
28
-     * must be posted, or will redirect to preferences
29
-     */
30
-    protected function attach()
31
-    {
32
-        if (!WebRequest::wasPosted()) {
33
-            $this->redirect('preferences');
34
-
35
-            return;
36
-        }
37
-
38
-        $database = $this->getDatabase();
39
-
40
-        $this->validateCSRFToken();
41
-
42
-        $oauthProtocolHelper = $this->getOAuthProtocolHelper();
43
-        $user = User::getCurrent($database);
44
-        $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
45
-
46
-        try {
47
-            $authoriseUrl = $oauth->getRequestToken();
48
-            $this->redirectUrl($authoriseUrl);
49
-        }
50
-        catch (CurlException $ex) {
51
-            throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
52
-        }
53
-    }
54
-
55
-    /**
56
-     * Detach account entry point
57
-     * @throws Exception
58
-     */
59
-    protected function detach()
60
-    {
61
-        if ($this->getSiteConfiguration()->getEnforceOAuth()) {
62
-            throw new AccessDeniedException($this->getSecurityManager());
63
-        }
64
-
65
-        $database = $this->getDatabase();
66
-        $user = User::getCurrent($database);
67
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
68
-
69
-        try {
70
-            $oauth->refreshIdentity();
71
-        }
72
-        catch (CurlException $ex) {
73
-            // do nothing. The user's already revoked this access anyway.
74
-        }
75
-        catch (OAuthException $ex) {
76
-            // do nothing. The user's already revoked this access anyway.
77
-        }
78
-        catch (OptimisticLockFailedException $e) {
79
-            // do nothing. The user's already revoked this access anyway.
80
-        }
81
-
82
-        $oauth->detach();
83
-
84
-        // TODO: figure out why we need to force logout after a detach.
85
-        $user->setForcelogout(true);
86
-        $user->save();
87
-
88
-        // force the user to log out
89
-        Session::destroy();
90
-
91
-        $this->redirect('login');
92
-    }
93
-
94
-    /**
95
-     * Main function for this page, when no specific actions are called.
96
-     * @return void
97
-     */
98
-    protected function main()
99
-    {
100
-        $this->redirect('preferences');
101
-    }
25
+	/**
26
+	 * Attach entry point
27
+	 *
28
+	 * must be posted, or will redirect to preferences
29
+	 */
30
+	protected function attach()
31
+	{
32
+		if (!WebRequest::wasPosted()) {
33
+			$this->redirect('preferences');
34
+
35
+			return;
36
+		}
37
+
38
+		$database = $this->getDatabase();
39
+
40
+		$this->validateCSRFToken();
41
+
42
+		$oauthProtocolHelper = $this->getOAuthProtocolHelper();
43
+		$user = User::getCurrent($database);
44
+		$oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
45
+
46
+		try {
47
+			$authoriseUrl = $oauth->getRequestToken();
48
+			$this->redirectUrl($authoriseUrl);
49
+		}
50
+		catch (CurlException $ex) {
51
+			throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
52
+		}
53
+	}
54
+
55
+	/**
56
+	 * Detach account entry point
57
+	 * @throws Exception
58
+	 */
59
+	protected function detach()
60
+	{
61
+		if ($this->getSiteConfiguration()->getEnforceOAuth()) {
62
+			throw new AccessDeniedException($this->getSecurityManager());
63
+		}
64
+
65
+		$database = $this->getDatabase();
66
+		$user = User::getCurrent($database);
67
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
68
+
69
+		try {
70
+			$oauth->refreshIdentity();
71
+		}
72
+		catch (CurlException $ex) {
73
+			// do nothing. The user's already revoked this access anyway.
74
+		}
75
+		catch (OAuthException $ex) {
76
+			// do nothing. The user's already revoked this access anyway.
77
+		}
78
+		catch (OptimisticLockFailedException $e) {
79
+			// do nothing. The user's already revoked this access anyway.
80
+		}
81
+
82
+		$oauth->detach();
83
+
84
+		// TODO: figure out why we need to force logout after a detach.
85
+		$user->setForcelogout(true);
86
+		$user->save();
87
+
88
+		// force the user to log out
89
+		Session::destroy();
90
+
91
+		$this->redirect('login');
92
+	}
93
+
94
+	/**
95
+	 * Main function for this page, when no specific actions are called.
96
+	 * @return void
97
+	 */
98
+	protected function main()
99
+	{
100
+		$this->redirect('preferences');
101
+	}
102 102
 }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageLogout.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -14,22 +14,22 @@
 block discarded – undo
14 14
 
15 15
 class PageLogout extends InternalPageBase
16 16
 {
17
-    /**
18
-     * Main function for this page, when no specific actions are called.
19
-     */
20
-    protected function main()
21
-    {
22
-        if(WebRequest::wasPosted()) {
23
-            Session::destroy();
24
-            $this->redirect("login");
25
-            return;
26
-        }
17
+	/**
18
+	 * Main function for this page, when no specific actions are called.
19
+	 */
20
+	protected function main()
21
+	{
22
+		if(WebRequest::wasPosted()) {
23
+			Session::destroy();
24
+			$this->redirect("login");
25
+			return;
26
+		}
27 27
 
28
-        $this->redirect();
29
-    }
28
+		$this->redirect();
29
+	}
30 30
 
31
-    protected function isProtectedPage()
32
-    {
33
-        return false;
34
-    }
31
+	protected function isProtectedPage()
32
+	{
33
+		return false;
34
+	}
35 35
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      */
20 20
     protected function main()
21 21
     {
22
-        if(WebRequest::wasPosted()) {
22
+        if (WebRequest::wasPosted()) {
23 23
             Session::destroy();
24 24
             $this->redirect("login");
25 25
             return;
Please login to merge, or discard this patch.
includes/Pages/PageLog.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -17,62 +17,62 @@
 block discarded – undo
17 17
 
18 18
 class PageLog extends PagedInternalPageBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     */
23
-    protected function main()
24
-    {
25
-        $this->setHtmlTitle('Logs');
26
-
27
-        $filterUser = WebRequest::getString('filterUser');
28
-        $filterAction = WebRequest::getString('filterAction');
29
-        $filterObjectType = WebRequest::getString('filterObjectType');
30
-        $filterObjectId = WebRequest::getInt('filterObjectId');
31
-
32
-        $database = $this->getDatabase();
33
-
34
-        if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
35
-            $filterObjectType = null;
36
-        }
37
-
38
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
39
-
40
-        $logSearch = LogSearchHelper::get($database);
41
-
42
-        if ($filterUser !== null) {
43
-            $userObj = User::getByUsername($filterUser, $database);
44
-            if ($userObj !== false) {
45
-                $logSearch->byUser($userObj->getId());
46
-            } else {
47
-                $logSearch->byUser(-1);
48
-            }
49
-        }
50
-        if ($filterAction !== null) {
51
-            $logSearch->byAction($filterAction);
52
-        }
53
-        if ($filterObjectType !== null) {
54
-            $logSearch->byObjectType($filterObjectType);
55
-        }
56
-        if ($filterObjectId !== null) {
57
-            $logSearch->byObjectId($filterObjectId);
58
-        }
59
-
60
-        $this->setSearchHelper($logSearch);
61
-        $this->setupLimits();
62
-
63
-        /** @var Log[] $logs */
64
-        $logs = $logSearch->getRecordCount($count)->fetch();
65
-
66
-        list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
67
-
68
-        $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
69
-
70
-        $this->assign("logs", $logData);
71
-        $this->assign("users", $users);
72
-
73
-        $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
74
-        $this->assign('allObjectTypes', LogHelper::getObjectTypes());
75
-
76
-        $this->setTemplate("logs/main.tpl");
77
-    }
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 */
23
+	protected function main()
24
+	{
25
+		$this->setHtmlTitle('Logs');
26
+
27
+		$filterUser = WebRequest::getString('filterUser');
28
+		$filterAction = WebRequest::getString('filterAction');
29
+		$filterObjectType = WebRequest::getString('filterObjectType');
30
+		$filterObjectId = WebRequest::getInt('filterObjectId');
31
+
32
+		$database = $this->getDatabase();
33
+
34
+		if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
35
+			$filterObjectType = null;
36
+		}
37
+
38
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
39
+
40
+		$logSearch = LogSearchHelper::get($database);
41
+
42
+		if ($filterUser !== null) {
43
+			$userObj = User::getByUsername($filterUser, $database);
44
+			if ($userObj !== false) {
45
+				$logSearch->byUser($userObj->getId());
46
+			} else {
47
+				$logSearch->byUser(-1);
48
+			}
49
+		}
50
+		if ($filterAction !== null) {
51
+			$logSearch->byAction($filterAction);
52
+		}
53
+		if ($filterObjectType !== null) {
54
+			$logSearch->byObjectType($filterObjectType);
55
+		}
56
+		if ($filterObjectId !== null) {
57
+			$logSearch->byObjectId($filterObjectId);
58
+		}
59
+
60
+		$this->setSearchHelper($logSearch);
61
+		$this->setupLimits();
62
+
63
+		/** @var Log[] $logs */
64
+		$logs = $logSearch->getRecordCount($count)->fetch();
65
+
66
+		list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
67
+
68
+		$this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
69
+
70
+		$this->assign("logs", $logData);
71
+		$this->assign("users", $users);
72
+
73
+		$this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
74
+		$this->assign('allObjectTypes', LogHelper::getObjectTypes());
75
+
76
+		$this->setTemplate("logs/main.tpl");
77
+	}
78 78
 }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterOption.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,18 +12,18 @@
 block discarded – undo
12 12
 
13 13
 class PageRegisterOption extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $this->assign('allowRegistration', $this->getSiteConfiguration()->isRegistrationAllowed());
22
-        $this->setTemplate('registration/option.tpl');
23
-    }
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$this->assign('allowRegistration', $this->getSiteConfiguration()->isRegistrationAllowed());
22
+		$this->setTemplate('registration/option.tpl');
23
+	}
24 24
 
25
-    protected function isProtectedPage()
26
-    {
27
-        return false;
28
-    }
25
+	protected function isProtectedPage()
26
+	{
27
+		return false;
28
+	}
29 29
 }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterBase.php 3 patches
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -22,222 +22,222 @@
 block discarded – undo
22 22
 
23 23
 abstract class PageRegisterBase extends InternalPageBase
24 24
 {
25
-    /**
26
-     * Main function for this page, when no specific actions are called.
27
-     * @throws AccessDeniedException
28
-     * @throws ApplicationLogicException
29
-     * @throws Exception
30
-     */
31
-    protected function main()
32
-    {
33
-        $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup();
34
-        if (! $this->getSiteConfiguration()->isRegistrationAllowed()) {
35
-           throw new AccessDeniedException();
36
-        }
37
-
38
-        // Dual-mode page
39
-        if (WebRequest::wasPosted()) {
40
-            $this->validateCSRFToken();
41
-
42
-            try {
43
-                $this->handlePost($useOAuthSignup);
44
-            }
45
-            catch (ApplicationLogicException $ex) {
46
-                SessionAlert::error($ex->getMessage());
47
-
48
-                $this->getDatabase()->rollBack();
49
-
50
-                $this->assignCSRFToken();
51
-                $this->assign("useOAuthSignup", $useOAuthSignup);
52
-                $this->applyErrorValues();
53
-                $this->setTemplate($this->getRegistrationTemplate());
54
-                $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js");
55
-            }
56
-        }
57
-        else {
58
-            $this->assignCSRFToken();
59
-            $this->assign("useOAuthSignup", $useOAuthSignup);
60
-            $this->setTemplate($this->getRegistrationTemplate());
61
-            $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js");
62
-        }
63
-    }
64
-
65
-    protected abstract function getRegistrationTemplate();
66
-
67
-    protected function isProtectedPage()
68
-    {
69
-        return false;
70
-    }
71
-
72
-    /**
73
-     * @param string $emailAddress
74
-     *
75
-     * @throws ApplicationLogicException
76
-     */
77
-    protected function validateUniqueEmail($emailAddress)
78
-    {
79
-        $query = 'SELECT COUNT(id) FROM user WHERE email = :email';
80
-        $statement = $this->getDatabase()->prepare($query);
81
-        $statement->execute(array(':email' => $emailAddress));
82
-
83
-        if ($statement->fetchColumn() > 0) {
84
-            throw new ApplicationLogicException('That email address is already in use on this system.');
85
-        }
86
-
87
-        $statement->closeCursor();
88
-    }
89
-
90
-    /**
91
-     * @param $emailAddress
92
-     * @param $password
93
-     * @param $username
94
-     * @param $useOAuthSignup
95
-     * @param $confirmationId
96
-     * @param $onwikiUsername
97
-     *
98
-     * @throws ApplicationLogicException
99
-     */
100
-    protected function validateRequest(
101
-        $emailAddress,
102
-        $password,
103
-        $username,
104
-        $useOAuthSignup,
105
-        $confirmationId,
106
-        $onwikiUsername
107
-    ) {
108
-        if (!WebRequest::postBoolean('guidelines')) {
109
-            throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.');
110
-        }
111
-
112
-        $this->validateGeneralInformation($emailAddress, $password, $username);
113
-        $this->validateUniqueEmail($emailAddress);
114
-        $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername);
115
-    }
116
-
117
-    /**
118
-     * @param $useOAuthSignup
119
-     * @param $confirmationId
120
-     * @param $onwikiUsername
121
-     *
122
-     * @throws ApplicationLogicException
123
-     */
124
-    protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername)
125
-    {
126
-        if (!$useOAuthSignup) {
127
-            if ($confirmationId === null || $confirmationId <= 0) {
128
-                throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.');
129
-            }
130
-
131
-            if ($onwikiUsername === null) {
132
-                throw new ApplicationLogicException('Please specify your on-wiki username.');
133
-            }
134
-        }
135
-    }
136
-
137
-    /**
138
-     * @param $emailAddress
139
-     * @param $password
140
-     * @param $username
141
-     *
142
-     * @throws ApplicationLogicException
143
-     */
144
-    protected function validateGeneralInformation($emailAddress, $password, $username)
145
-    {
146
-        if ($emailAddress === null) {
147
-            throw new ApplicationLogicException('Your email address appears to be invalid!');
148
-        }
149
-
150
-        if ($password !== WebRequest::postString('pass2')) {
151
-            throw new ApplicationLogicException('Your passwords did not match, please try again.');
152
-        }
153
-
154
-        if (User::getByUsername($username, $this->getDatabase()) !== false) {
155
-            throw new ApplicationLogicException('That username is already in use on this system.');
156
-        }
157
-    }
158
-
159
-    /**
160
-     * @param $useOAuthSignup
161
-     *
162
-     * @throws ApplicationLogicException
163
-     * @throws Exception
164
-     */
165
-    protected function handlePost($useOAuthSignup)
166
-    {
167
-        // Get the data
168
-        $emailAddress = WebRequest::postEmail('email');
169
-        $password = WebRequest::postString('pass');
170
-        $username = WebRequest::postString('name');
171
-
172
-        // Only set if OAuth is disabled
173
-        $confirmationId = WebRequest::postInt('conf_revid');
174
-        $onwikiUsername = WebRequest::postString('wname');
175
-
176
-        // Do some validation
177
-        $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId,
178
-            $onwikiUsername);
179
-
180
-        $database = $this->getDatabase();
181
-
182
-        $user = new User();
183
-        $user->setDatabase($database);
184
-
185
-        $user->setUsername($username);
186
-        $user->setEmail($emailAddress);
187
-
188
-        if (!$useOAuthSignup) {
189
-            $user->setOnWikiName($onwikiUsername);
190
-            $user->setConfirmationDiff($confirmationId);
191
-        }
192
-
193
-        $user->save();
194
-
195
-        $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration());
196
-        $passwordCredentialProvider->setCredential($user, 1, $password);
197
-
198
-        $defaultRole = $this->getDefaultRole();
199
-
200
-        $role = new UserRole();
201
-        $role->setDatabase($database);
202
-        $role->setUser($user->getId());
203
-        $role->setRole($defaultRole);
204
-        $role->save();
205
-
206
-        // Log now to get the signup date.
207
-        Logger::newUser($database, $user);
208
-        Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array());
209
-
210
-        if ($useOAuthSignup) {
211
-            $oauthProtocolHelper = $this->getOAuthProtocolHelper();
212
-            $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
213
-
214
-            $authoriseUrl = $oauth->getRequestToken();
215
-            WebRequest::setOAuthPartialLogin($user);
216
-            $this->redirectUrl($authoriseUrl);
217
-        }
218
-        else {
219
-            // only notify if we're not using the oauth signup.
220
-            $this->getNotificationHelper()->userNew($user);
221
-            WebRequest::setLoggedInUser($user);
222
-            $this->redirect('preferences');
223
-        }
224
-    }
225
-
226
-    protected abstract function getDefaultRole();
227
-
228
-    /**
229
-     * Entry point for registration complete
230
-     * @throws Exception
231
-     */
232
-    protected function done()
233
-    {
234
-        $this->setTemplate('registration/alert-registrationcomplete.tpl');
235
-    }
236
-
237
-    protected function applyErrorValues()
238
-    {
239
-        $this->assign('tplUsername', WebRequest::postString('name'));
240
-        $this->assign('tplEmail', WebRequest::postString('email'));
241
-        $this->assign('tplWikipediaUsername', WebRequest::postString('wname'));
242
-        $this->assign('tplConfRevId', WebRequest::postInt('conf_revid'));
243
-    }}
25
+	/**
26
+	 * Main function for this page, when no specific actions are called.
27
+	 * @throws AccessDeniedException
28
+	 * @throws ApplicationLogicException
29
+	 * @throws Exception
30
+	 */
31
+	protected function main()
32
+	{
33
+		$useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup();
34
+		if (! $this->getSiteConfiguration()->isRegistrationAllowed()) {
35
+		   throw new AccessDeniedException();
36
+		}
37
+
38
+		// Dual-mode page
39
+		if (WebRequest::wasPosted()) {
40
+			$this->validateCSRFToken();
41
+
42
+			try {
43
+				$this->handlePost($useOAuthSignup);
44
+			}
45
+			catch (ApplicationLogicException $ex) {
46
+				SessionAlert::error($ex->getMessage());
47
+
48
+				$this->getDatabase()->rollBack();
49
+
50
+				$this->assignCSRFToken();
51
+				$this->assign("useOAuthSignup", $useOAuthSignup);
52
+				$this->applyErrorValues();
53
+				$this->setTemplate($this->getRegistrationTemplate());
54
+				$this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js");
55
+			}
56
+		}
57
+		else {
58
+			$this->assignCSRFToken();
59
+			$this->assign("useOAuthSignup", $useOAuthSignup);
60
+			$this->setTemplate($this->getRegistrationTemplate());
61
+			$this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js");
62
+		}
63
+	}
64
+
65
+	protected abstract function getRegistrationTemplate();
66
+
67
+	protected function isProtectedPage()
68
+	{
69
+		return false;
70
+	}
71
+
72
+	/**
73
+	 * @param string $emailAddress
74
+	 *
75
+	 * @throws ApplicationLogicException
76
+	 */
77
+	protected function validateUniqueEmail($emailAddress)
78
+	{
79
+		$query = 'SELECT COUNT(id) FROM user WHERE email = :email';
80
+		$statement = $this->getDatabase()->prepare($query);
81
+		$statement->execute(array(':email' => $emailAddress));
82
+
83
+		if ($statement->fetchColumn() > 0) {
84
+			throw new ApplicationLogicException('That email address is already in use on this system.');
85
+		}
86
+
87
+		$statement->closeCursor();
88
+	}
89
+
90
+	/**
91
+	 * @param $emailAddress
92
+	 * @param $password
93
+	 * @param $username
94
+	 * @param $useOAuthSignup
95
+	 * @param $confirmationId
96
+	 * @param $onwikiUsername
97
+	 *
98
+	 * @throws ApplicationLogicException
99
+	 */
100
+	protected function validateRequest(
101
+		$emailAddress,
102
+		$password,
103
+		$username,
104
+		$useOAuthSignup,
105
+		$confirmationId,
106
+		$onwikiUsername
107
+	) {
108
+		if (!WebRequest::postBoolean('guidelines')) {
109
+			throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.');
110
+		}
111
+
112
+		$this->validateGeneralInformation($emailAddress, $password, $username);
113
+		$this->validateUniqueEmail($emailAddress);
114
+		$this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername);
115
+	}
116
+
117
+	/**
118
+	 * @param $useOAuthSignup
119
+	 * @param $confirmationId
120
+	 * @param $onwikiUsername
121
+	 *
122
+	 * @throws ApplicationLogicException
123
+	 */
124
+	protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername)
125
+	{
126
+		if (!$useOAuthSignup) {
127
+			if ($confirmationId === null || $confirmationId <= 0) {
128
+				throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.');
129
+			}
130
+
131
+			if ($onwikiUsername === null) {
132
+				throw new ApplicationLogicException('Please specify your on-wiki username.');
133
+			}
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * @param $emailAddress
139
+	 * @param $password
140
+	 * @param $username
141
+	 *
142
+	 * @throws ApplicationLogicException
143
+	 */
144
+	protected function validateGeneralInformation($emailAddress, $password, $username)
145
+	{
146
+		if ($emailAddress === null) {
147
+			throw new ApplicationLogicException('Your email address appears to be invalid!');
148
+		}
149
+
150
+		if ($password !== WebRequest::postString('pass2')) {
151
+			throw new ApplicationLogicException('Your passwords did not match, please try again.');
152
+		}
153
+
154
+		if (User::getByUsername($username, $this->getDatabase()) !== false) {
155
+			throw new ApplicationLogicException('That username is already in use on this system.');
156
+		}
157
+	}
158
+
159
+	/**
160
+	 * @param $useOAuthSignup
161
+	 *
162
+	 * @throws ApplicationLogicException
163
+	 * @throws Exception
164
+	 */
165
+	protected function handlePost($useOAuthSignup)
166
+	{
167
+		// Get the data
168
+		$emailAddress = WebRequest::postEmail('email');
169
+		$password = WebRequest::postString('pass');
170
+		$username = WebRequest::postString('name');
171
+
172
+		// Only set if OAuth is disabled
173
+		$confirmationId = WebRequest::postInt('conf_revid');
174
+		$onwikiUsername = WebRequest::postString('wname');
175
+
176
+		// Do some validation
177
+		$this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId,
178
+			$onwikiUsername);
179
+
180
+		$database = $this->getDatabase();
181
+
182
+		$user = new User();
183
+		$user->setDatabase($database);
184
+
185
+		$user->setUsername($username);
186
+		$user->setEmail($emailAddress);
187
+
188
+		if (!$useOAuthSignup) {
189
+			$user->setOnWikiName($onwikiUsername);
190
+			$user->setConfirmationDiff($confirmationId);
191
+		}
192
+
193
+		$user->save();
194
+
195
+		$passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration());
196
+		$passwordCredentialProvider->setCredential($user, 1, $password);
197
+
198
+		$defaultRole = $this->getDefaultRole();
199
+
200
+		$role = new UserRole();
201
+		$role->setDatabase($database);
202
+		$role->setUser($user->getId());
203
+		$role->setRole($defaultRole);
204
+		$role->save();
205
+
206
+		// Log now to get the signup date.
207
+		Logger::newUser($database, $user);
208
+		Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array());
209
+
210
+		if ($useOAuthSignup) {
211
+			$oauthProtocolHelper = $this->getOAuthProtocolHelper();
212
+			$oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
213
+
214
+			$authoriseUrl = $oauth->getRequestToken();
215
+			WebRequest::setOAuthPartialLogin($user);
216
+			$this->redirectUrl($authoriseUrl);
217
+		}
218
+		else {
219
+			// only notify if we're not using the oauth signup.
220
+			$this->getNotificationHelper()->userNew($user);
221
+			WebRequest::setLoggedInUser($user);
222
+			$this->redirect('preferences');
223
+		}
224
+	}
225
+
226
+	protected abstract function getDefaultRole();
227
+
228
+	/**
229
+	 * Entry point for registration complete
230
+	 * @throws Exception
231
+	 */
232
+	protected function done()
233
+	{
234
+		$this->setTemplate('registration/alert-registrationcomplete.tpl');
235
+	}
236
+
237
+	protected function applyErrorValues()
238
+	{
239
+		$this->assign('tplUsername', WebRequest::postString('name'));
240
+		$this->assign('tplEmail', WebRequest::postString('email'));
241
+		$this->assign('tplWikipediaUsername', WebRequest::postString('wname'));
242
+		$this->assign('tplConfRevId', WebRequest::postInt('conf_revid'));
243
+	}}
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
     protected function main()
32 32
     {
33 33
         $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup();
34
-        if (! $this->getSiteConfiguration()->isRegistrationAllowed()) {
34
+        if (!$this->getSiteConfiguration()->isRegistrationAllowed()) {
35 35
            throw new AccessDeniedException();
36 36
         }
37 37
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,8 +53,7 @@  discard block
 block discarded – undo
53 53
                 $this->setTemplate($this->getRegistrationTemplate());
54 54
                 $this->addJs("/vendor/dropbox/zxcvbn/dist/zxcvbn.js");
55 55
             }
56
-        }
57
-        else {
56
+        } else {
58 57
             $this->assignCSRFToken();
59 58
             $this->assign("useOAuthSignup", $useOAuthSignup);
60 59
             $this->setTemplate($this->getRegistrationTemplate());
@@ -214,8 +213,7 @@  discard block
 block discarded – undo
214 213
             $authoriseUrl = $oauth->getRequestToken();
215 214
             WebRequest::setOAuthPartialLogin($user);
216 215
             $this->redirectUrl($authoriseUrl);
217
-        }
218
-        else {
216
+        } else {
219 217
             // only notify if we're not using the oauth signup.
220 218
             $this->getNotificationHelper()->userNew($user);
221 219
             WebRequest::setLoggedInUser($user);
Please login to merge, or discard this patch.
includes/Pages/PageJobQueue.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -26,241 +26,241 @@
 block discarded – undo
26 26
 
27 27
 class PageJobQueue extends PagedInternalPageBase
28 28
 {
29
-    /**
30
-     * Main function for this page, when no specific actions are called.
31
-     * @return void
32
-     */
33
-    protected function main()
34
-    {
35
-        $this->setHtmlTitle('Job Queue Management');
29
+	/**
30
+	 * Main function for this page, when no specific actions are called.
31
+	 * @return void
32
+	 */
33
+	protected function main()
34
+	{
35
+		$this->setHtmlTitle('Job Queue Management');
36 36
 
37
-        $this->prepareMaps();
37
+		$this->prepareMaps();
38 38
 
39
-        $database = $this->getDatabase();
39
+		$database = $this->getDatabase();
40 40
 
41
-        /** @var JobQueue[] $jobList */
42
-        $jobList = JobQueueSearchHelper::get($database)
43
-            ->statusIn(array('ready', 'waiting', 'running', 'failed'))
44
-            ->notAcknowledged()
45
-            ->fetch();
41
+		/** @var JobQueue[] $jobList */
42
+		$jobList = JobQueueSearchHelper::get($database)
43
+			->statusIn(array('ready', 'waiting', 'running', 'failed'))
44
+			->notAcknowledged()
45
+			->fetch();
46 46
 
47
-        $userIds = array();
48
-        $requestIds = array();
47
+		$userIds = array();
48
+		$requestIds = array();
49 49
 
50
-        foreach ($jobList as $job) {
51
-            $userIds[] = $job->getTriggerUserId();
52
-            $requestIds[] = $job->getRequest();
50
+		foreach ($jobList as $job) {
51
+			$userIds[] = $job->getTriggerUserId();
52
+			$requestIds[] = $job->getRequest();
53 53
 
54
-            $job->setDatabase($database);
55
-        }
54
+			$job->setDatabase($database);
55
+		}
56 56
 
57
-        $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
57
+		$this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
58 58
 
59
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
60
-        $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
59
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
60
+		$this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
61 61
 
62
-        $this->assign('joblist', $jobList);
63
-        $this->setTemplate('jobqueue/main.tpl');
64
-    }
62
+		$this->assign('joblist', $jobList);
63
+		$this->setTemplate('jobqueue/main.tpl');
64
+	}
65 65
 
66
-    protected function all()
67
-    {
68
-        $this->setHtmlTitle('All Jobs');
66
+	protected function all()
67
+	{
68
+		$this->setHtmlTitle('All Jobs');
69 69
 
70
-        $this->prepareMaps();
70
+		$this->prepareMaps();
71 71
 
72
-        $database = $this->getDatabase();
72
+		$database = $this->getDatabase();
73 73
 
74
-        $searchHelper = JobQueueSearchHelper::get($database);
75
-        $this->setSearchHelper($searchHelper);
76
-        $this->setupLimits();
74
+		$searchHelper = JobQueueSearchHelper::get($database);
75
+		$this->setSearchHelper($searchHelper);
76
+		$this->setupLimits();
77 77
 
78
-        $filterUser = WebRequest::getString('filterUser');
79
-        $filterTask = WebRequest::getString('filterTask');
80
-        $filterStatus = WebRequest::getString('filterStatus');
81
-        $filterRequest = WebRequest::getString('filterRequest');
78
+		$filterUser = WebRequest::getString('filterUser');
79
+		$filterTask = WebRequest::getString('filterTask');
80
+		$filterStatus = WebRequest::getString('filterStatus');
81
+		$filterRequest = WebRequest::getString('filterRequest');
82 82
 
83
-        if ($filterUser !== null) {
84
-            $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
85
-        }
83
+		if ($filterUser !== null) {
84
+			$searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
85
+		}
86 86
 
87
-        if ($filterTask !== null) {
88
-            $searchHelper->byTask($filterTask);
89
-        }
87
+		if ($filterTask !== null) {
88
+			$searchHelper->byTask($filterTask);
89
+		}
90 90
 
91
-        if ($filterStatus !== null) {
92
-            $searchHelper->byStatus($filterStatus);
93
-        }
91
+		if ($filterStatus !== null) {
92
+			$searchHelper->byStatus($filterStatus);
93
+		}
94 94
 
95
-        if ($filterRequest !== null) {
96
-            $searchHelper->byRequest($filterRequest);
97
-        }
95
+		if ($filterRequest !== null) {
96
+			$searchHelper->byRequest($filterRequest);
97
+		}
98 98
 
99
-        /** @var JobQueue[] $jobList */
100
-        $jobList = $searchHelper->getRecordCount($count)->fetch();
99
+		/** @var JobQueue[] $jobList */
100
+		$jobList = $searchHelper->getRecordCount($count)->fetch();
101 101
 
102
-        $this->setupPageData($count, array(
103
-            'filterUser' => $filterUser,
104
-            'filterTask' => $filterTask,
105
-            'filterStatus' => $filterStatus,
106
-            'filterRequest' => $filterRequest,
107
-        ));
102
+		$this->setupPageData($count, array(
103
+			'filterUser' => $filterUser,
104
+			'filterTask' => $filterTask,
105
+			'filterStatus' => $filterStatus,
106
+			'filterRequest' => $filterRequest,
107
+		));
108 108
 
109
-        $userIds = array();
110
-        $requestIds = array();
109
+		$userIds = array();
110
+		$requestIds = array();
111 111
 
112
-        foreach ($jobList as $job) {
113
-            $userIds[] = $job->getTriggerUserId();
114
-            $requestIds[] = $job->getRequest();
112
+		foreach ($jobList as $job) {
113
+			$userIds[] = $job->getTriggerUserId();
114
+			$requestIds[] = $job->getRequest();
115 115
 
116
-            $job->setDatabase($database);
117
-        }
116
+			$job->setDatabase($database);
117
+		}
118 118
 
119
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
120
-            return UserSearchHelper::get($database)->fetchColumn('username');
121
-        });
119
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
120
+			return UserSearchHelper::get($database)->fetchColumn('username');
121
+		});
122 122
 
123
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
124
-        $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
123
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
124
+		$this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
125 125
 
126
-        $this->assign('joblist', $jobList);
126
+		$this->assign('joblist', $jobList);
127 127
 
128
-        $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
128
+		$this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata");
129 129
 
130
-        $this->setTemplate('jobqueue/all.tpl');
131
-    }
130
+		$this->setTemplate('jobqueue/all.tpl');
131
+	}
132 132
 
133
-    protected function view()
134
-    {
135
-        $jobId = WebRequest::getInt('id');
136
-        $database = $this->getDatabase();
133
+	protected function view()
134
+	{
135
+		$jobId = WebRequest::getInt('id');
136
+		$database = $this->getDatabase();
137 137
 
138
-        if ($jobId === null) {
139
-            throw new ApplicationLogicException('No job specified');
140
-        }
138
+		if ($jobId === null) {
139
+			throw new ApplicationLogicException('No job specified');
140
+		}
141 141
 
142
-        /** @var JobQueue $job */
143
-        $job = JobQueue::getById($jobId, $database);
142
+		/** @var JobQueue $job */
143
+		$job = JobQueue::getById($jobId, $database);
144 144
 
145
-        if ($job === false) {
146
-            throw new ApplicationLogicException('Could not find requested job');
147
-        }
145
+		if ($job === false) {
146
+			throw new ApplicationLogicException('Could not find requested job');
147
+		}
148 148
 
149
-        $this->prepareMaps();
149
+		$this->prepareMaps();
150 150
 
151
-        $this->assign('user', User::getById($job->getTriggerUserId(), $database));
152
-        $this->assign('request', Request::getById($job->getRequest(), $database));
153
-        $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
154
-        $this->assign('parent', JobQueue::getById($job->getParent(), $database));
151
+		$this->assign('user', User::getById($job->getTriggerUserId(), $database));
152
+		$this->assign('request', Request::getById($job->getRequest(), $database));
153
+		$this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
154
+		$this->assign('parent', JobQueue::getById($job->getParent(), $database));
155 155
 
156
-        /** @var Log[] $logs */
157
-        $logs = LogSearchHelper::get($database)->byObjectType('JobQueue')
158
-            ->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
159
-        if ($logCount === 0) {
160
-            $this->assign('log', array());
161
-        }
162
-        else {
163
-            list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
156
+		/** @var Log[] $logs */
157
+		$logs = LogSearchHelper::get($database)->byObjectType('JobQueue')
158
+			->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
159
+		if ($logCount === 0) {
160
+			$this->assign('log', array());
161
+		}
162
+		else {
163
+			list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
164 164
 
165
-            $this->assign("log", $logData);
166
-            $this->assign("users", $users);
167
-        }
165
+			$this->assign("log", $logData);
166
+			$this->assign("users", $users);
167
+		}
168 168
 
169
-        $this->assignCSRFToken();
169
+		$this->assignCSRFToken();
170 170
 
171
-        $this->assign('job', $job);
171
+		$this->assign('job', $job);
172 172
 
173
-        $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
174
-        $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
173
+		$this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
174
+		$this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
175 175
 
176
-        $this->setHtmlTitle('Job #{$job->getId()|escape}');
177
-        $this->setTemplate('jobqueue/view.tpl');
178
-    }
176
+		$this->setHtmlTitle('Job #{$job->getId()|escape}');
177
+		$this->setTemplate('jobqueue/view.tpl');
178
+	}
179 179
 
180
-    protected function acknowledge()
181
-    {
182
-        if (!WebRequest::wasPosted()) {
183
-            throw new ApplicationLogicException('This page does not support GET methods.');
184
-        }
180
+	protected function acknowledge()
181
+	{
182
+		if (!WebRequest::wasPosted()) {
183
+			throw new ApplicationLogicException('This page does not support GET methods.');
184
+		}
185 185
 
186
-        $this->validateCSRFToken();
186
+		$this->validateCSRFToken();
187 187
 
188
-        $jobId = WebRequest::postInt('job');
189
-        $database = $this->getDatabase();
188
+		$jobId = WebRequest::postInt('job');
189
+		$database = $this->getDatabase();
190 190
 
191
-        if ($jobId === null) {
192
-            throw new ApplicationLogicException('No job specified');
193
-        }
191
+		if ($jobId === null) {
192
+			throw new ApplicationLogicException('No job specified');
193
+		}
194 194
 
195
-        /** @var JobQueue $job */
196
-        $job = JobQueue::getById($jobId, $database);
195
+		/** @var JobQueue $job */
196
+		$job = JobQueue::getById($jobId, $database);
197 197
 
198
-        if ($job === false) {
199
-            throw new ApplicationLogicException('Could not find requested job');
200
-        }
198
+		if ($job === false) {
199
+			throw new ApplicationLogicException('Could not find requested job');
200
+		}
201 201
 
202
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
203
-        $job->setAcknowledged(true);
204
-        $job->save();
202
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
203
+		$job->setAcknowledged(true);
204
+		$job->save();
205 205
 
206
-        Logger::backgroundJobAcknowledged($database, $job);
206
+		Logger::backgroundJobAcknowledged($database, $job);
207 207
 
208
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
209
-    }
208
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
209
+	}
210 210
 
211
-    protected function requeue()
212
-    {
213
-        if (!WebRequest::wasPosted()) {
214
-            throw new ApplicationLogicException('This page does not support GET methods.');
215
-        }
211
+	protected function requeue()
212
+	{
213
+		if (!WebRequest::wasPosted()) {
214
+			throw new ApplicationLogicException('This page does not support GET methods.');
215
+		}
216 216
 
217
-        $this->validateCSRFToken();
217
+		$this->validateCSRFToken();
218 218
 
219
-        $jobId = WebRequest::postInt('job');
220
-        $database = $this->getDatabase();
219
+		$jobId = WebRequest::postInt('job');
220
+		$database = $this->getDatabase();
221 221
 
222
-        if ($jobId === null) {
223
-            throw new ApplicationLogicException('No job specified');
224
-        }
222
+		if ($jobId === null) {
223
+			throw new ApplicationLogicException('No job specified');
224
+		}
225 225
 
226
-        /** @var JobQueue $job */
227
-        $job = JobQueue::getById($jobId, $database);
226
+		/** @var JobQueue $job */
227
+		$job = JobQueue::getById($jobId, $database);
228 228
 
229
-        if ($job === false) {
230
-            throw new ApplicationLogicException('Could not find requested job');
231
-        }
229
+		if ($job === false) {
230
+			throw new ApplicationLogicException('Could not find requested job');
231
+		}
232 232
 
233
-        $job->setStatus(JobQueue::STATUS_READY);
234
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
235
-        $job->setAcknowledged(null);
236
-        $job->setError(null);
237
-        $job->save();
238
-
239
-        /** @var Request $request */
240
-        $request = Request::getById($job->getRequest(), $database);
241
-        $request->setStatus(RequestStatus::JOBQUEUE);
242
-        $request->save();
233
+		$job->setStatus(JobQueue::STATUS_READY);
234
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
235
+		$job->setAcknowledged(null);
236
+		$job->setError(null);
237
+		$job->save();
238
+
239
+		/** @var Request $request */
240
+		$request = Request::getById($job->getRequest(), $database);
241
+		$request->setStatus(RequestStatus::JOBQUEUE);
242
+		$request->save();
243 243
 
244
-        Logger::enqueuedJobQueue($database, $request);
245
-        Logger::backgroundJobRequeued($database, $job);
246
-
247
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
248
-    }
249
-
250
-    protected function prepareMaps()
251
-    {
252
-        $taskNameMap = JobQueue::getTaskDescriptions();
253
-
254
-        $statusDecriptionMap = array(
255
-            JobQueue::STATUS_CANCELLED => 'The job was cancelled',
256
-            JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
257
-            JobQueue::STATUS_FAILED    => 'The job encountered an error',
258
-            JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
259
-            JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
260
-            JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
261
-            JobQueue::STATUS_HELD      => 'The job has manually held from processing',
262
-        );
263
-        $this->assign('taskNameMap', $taskNameMap);
264
-        $this->assign('statusDescriptionMap', $statusDecriptionMap);
265
-    }
244
+		Logger::enqueuedJobQueue($database, $request);
245
+		Logger::backgroundJobRequeued($database, $job);
246
+
247
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
248
+	}
249
+
250
+	protected function prepareMaps()
251
+	{
252
+		$taskNameMap = JobQueue::getTaskDescriptions();
253
+
254
+		$statusDecriptionMap = array(
255
+			JobQueue::STATUS_CANCELLED => 'The job was cancelled',
256
+			JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
257
+			JobQueue::STATUS_FAILED    => 'The job encountered an error',
258
+			JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
259
+			JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
260
+			JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
261
+			JobQueue::STATUS_HELD      => 'The job has manually held from processing',
262
+		);
263
+		$this->assign('taskNameMap', $taskNameMap);
264
+		$this->assign('statusDescriptionMap', $statusDecriptionMap);
265
+	}
266 266
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -116,7 +116,8 @@  discard block
 block discarded – undo
116 116
             $job->setDatabase($database);
117 117
         }
118 118
 
119
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
119
+        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database)
120
+        {
120 121
             return UserSearchHelper::get($database)->fetchColumn('username');
121 122
         });
122 123
 
@@ -158,8 +159,7 @@  discard block
 block discarded – undo
158 159
             ->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
159 160
         if ($logCount === 0) {
160 161
             $this->assign('log', array());
161
-        }
162
-        else {
162
+        } else {
163 163
             list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
164 164
 
165 165
             $this->assign("log", $logData);
Please login to merge, or discard this patch.
includes/API/IXmlApiAction.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@
 block discarded – undo
16 16
  */
17 17
 interface IXmlApiAction extends IRoutedTask, IApiAction
18 18
 {
19
-    /**
20
-     * Method that runs API action
21
-     *
22
-     * @param DOMElement $apiDocument
23
-     *
24
-     * @return DOMElement The modified API document
25
-     */
26
-    public function executeApiAction(DOMElement $apiDocument);
19
+	/**
20
+	 * Method that runs API action
21
+	 *
22
+	 * @param DOMElement $apiDocument
23
+	 *
24
+	 * @return DOMElement The modified API document
25
+	 */
26
+	public function executeApiAction(DOMElement $apiDocument);
27 27
 }
Please login to merge, or discard this patch.