@@ -26,239 +26,239 @@ discard block |
||
26 | 26 | |
27 | 27 | class PageMultiFactor extends InternalPageBase |
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 | - $database = $this->getDatabase(); |
|
36 | - $currentUser = User::getCurrent($database); |
|
37 | - |
|
38 | - $yubikeyOtpCredentialProvider = new YubikeyOtpCredentialProvider($database, $this->getSiteConfiguration(), |
|
39 | - $this->getHttpHelper()); |
|
40 | - $this->assign('yubikeyOtpIdentity', $yubikeyOtpCredentialProvider->getYubikeyData($currentUser->getId())); |
|
41 | - $this->assign('yubikeyOtpEnrolled', $yubikeyOtpCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
42 | - |
|
43 | - $totpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration()); |
|
44 | - $this->assign('totpEnrolled', $totpCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
45 | - |
|
46 | - $u2fCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration()); |
|
47 | - $this->assign('u2fEnrolled', $u2fCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
48 | - |
|
49 | - $scratchCredentialProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
50 | - $this->assign('scratchEnrolled', $scratchCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
51 | - $this->assign('scratchRemaining', $scratchCredentialProvider->getRemaining($currentUser->getId())); |
|
52 | - |
|
53 | - $this->setTemplate('mfa/mfa.tpl'); |
|
54 | - } |
|
55 | - |
|
56 | - protected function enableYubikeyOtp() |
|
57 | - { |
|
58 | - $database = $this->getDatabase(); |
|
59 | - $currentUser = User::getCurrent($database); |
|
60 | - |
|
61 | - $otpCredentialProvider = new YubikeyOtpCredentialProvider($database, |
|
62 | - $this->getSiteConfiguration(), $this->getHttpHelper()); |
|
63 | - |
|
64 | - if (WebRequest::wasPosted()) { |
|
65 | - $this->validateCSRFToken(); |
|
66 | - |
|
67 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
68 | - $this->getSiteConfiguration()); |
|
69 | - |
|
70 | - $password = WebRequest::postString('password'); |
|
71 | - $otp = WebRequest::postString('otp'); |
|
72 | - |
|
73 | - $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
74 | - |
|
75 | - if ($result) { |
|
76 | - try { |
|
77 | - $otpCredentialProvider->setCredential($currentUser, 2, $otp); |
|
78 | - SessionAlert::success('Enabled YubiKey OTP.'); |
|
79 | - |
|
80 | - $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
81 | - if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
82 | - $scratchProvider->setCredential($currentUser, 2, null); |
|
83 | - $tokens = $scratchProvider->getTokens($currentUser->getId()); |
|
84 | - $this->assign('tokens', $tokens); |
|
85 | - $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
86 | - return; |
|
87 | - } |
|
88 | - } |
|
89 | - catch (ApplicationLogicException $ex) { |
|
90 | - SessionAlert::error('Error enabling YubiKey OTP: ' . $ex->getMessage()); |
|
91 | - } |
|
92 | - |
|
93 | - $this->redirect('multiFactor'); |
|
94 | - } |
|
95 | - else { |
|
96 | - SessionAlert::error('Error enabling YubiKey OTP - invalid credentials.'); |
|
97 | - $this->redirect('multiFactor'); |
|
98 | - } |
|
99 | - } |
|
100 | - else { |
|
101 | - if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
102 | - // user is not enrolled, we shouldn't have got here. |
|
103 | - throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism'); |
|
104 | - } |
|
105 | - |
|
106 | - $this->assignCSRFToken(); |
|
107 | - $this->setTemplate('mfa/enableYubikey.tpl'); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - protected function disableYubikeyOtp() |
|
112 | - { |
|
113 | - $database = $this->getDatabase(); |
|
114 | - $currentUser = User::getCurrent($database); |
|
115 | - |
|
116 | - $otpCredentialProvider = new YubikeyOtpCredentialProvider($database, |
|
117 | - $this->getSiteConfiguration(), $this->getHttpHelper()); |
|
118 | - |
|
119 | - $factorType = 'YubiKey OTP'; |
|
120 | - |
|
121 | - $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType); |
|
122 | - } |
|
123 | - |
|
124 | - protected function enableTotp() |
|
125 | - { |
|
126 | - $database = $this->getDatabase(); |
|
127 | - $currentUser = User::getCurrent($database); |
|
128 | - |
|
129 | - $otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration()); |
|
130 | - |
|
131 | - if (WebRequest::wasPosted()) { |
|
132 | - $this->validateCSRFToken(); |
|
133 | - |
|
134 | - // used for routing only, not security |
|
135 | - $stage = WebRequest::postString('stage'); |
|
136 | - |
|
137 | - if ($stage === "auth") { |
|
138 | - $password = WebRequest::postString('password'); |
|
139 | - |
|
140 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
141 | - $this->getSiteConfiguration()); |
|
142 | - $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
143 | - |
|
144 | - if ($result) { |
|
145 | - $otpCredentialProvider->setCredential($currentUser, 2, null); |
|
146 | - |
|
147 | - $provisioningUrl = $otpCredentialProvider->getProvisioningUrl($currentUser); |
|
148 | - |
|
149 | - $renderer = new Svg(); |
|
150 | - $renderer->setHeight(256); |
|
151 | - $renderer->setWidth(256); |
|
152 | - $writer = new Writer($renderer); |
|
153 | - $svg = $writer->writeString($provisioningUrl); |
|
154 | - |
|
155 | - $this->assign('svg', $svg); |
|
156 | - $this->assign('secret', $otpCredentialProvider->getSecret($currentUser)); |
|
157 | - |
|
158 | - $this->assignCSRFToken(); |
|
159 | - $this->setTemplate('mfa/enableTotpEnroll.tpl'); |
|
160 | - |
|
161 | - return; |
|
162 | - } |
|
163 | - else { |
|
164 | - SessionAlert::error('Error enabling TOTP - invalid credentials.'); |
|
165 | - $this->redirect('multiFactor'); |
|
166 | - |
|
167 | - return; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - if ($stage === "enroll") { |
|
172 | - // we *must* have a defined credential already here, |
|
173 | - if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) { |
|
174 | - $otp = WebRequest::postString('otp'); |
|
175 | - $result = $otpCredentialProvider->verifyEnable($currentUser, $otp); |
|
176 | - |
|
177 | - if ($result) { |
|
178 | - SessionAlert::success('Enabled TOTP.'); |
|
179 | - |
|
180 | - $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
181 | - if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
182 | - $scratchProvider->setCredential($currentUser, 2, null); |
|
183 | - $tokens = $scratchProvider->getTokens($currentUser->getId()); |
|
184 | - $this->assign('tokens', $tokens); |
|
185 | - $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
186 | - return; |
|
187 | - } |
|
188 | - } |
|
189 | - else { |
|
190 | - $otpCredentialProvider->deleteCredential($currentUser); |
|
191 | - SessionAlert::error('Error enabling TOTP: invalid token provided'); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - $this->redirect('multiFactor'); |
|
196 | - return; |
|
197 | - } |
|
198 | - else { |
|
199 | - SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.'); |
|
200 | - $this->redirect('multiFactor'); |
|
29 | + /** |
|
30 | + * Main function for this page, when no specific actions are called. |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + protected function main() |
|
34 | + { |
|
35 | + $database = $this->getDatabase(); |
|
36 | + $currentUser = User::getCurrent($database); |
|
37 | + |
|
38 | + $yubikeyOtpCredentialProvider = new YubikeyOtpCredentialProvider($database, $this->getSiteConfiguration(), |
|
39 | + $this->getHttpHelper()); |
|
40 | + $this->assign('yubikeyOtpIdentity', $yubikeyOtpCredentialProvider->getYubikeyData($currentUser->getId())); |
|
41 | + $this->assign('yubikeyOtpEnrolled', $yubikeyOtpCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
42 | + |
|
43 | + $totpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration()); |
|
44 | + $this->assign('totpEnrolled', $totpCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
45 | + |
|
46 | + $u2fCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration()); |
|
47 | + $this->assign('u2fEnrolled', $u2fCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
48 | + |
|
49 | + $scratchCredentialProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
50 | + $this->assign('scratchEnrolled', $scratchCredentialProvider->userIsEnrolled($currentUser->getId())); |
|
51 | + $this->assign('scratchRemaining', $scratchCredentialProvider->getRemaining($currentUser->getId())); |
|
52 | + |
|
53 | + $this->setTemplate('mfa/mfa.tpl'); |
|
54 | + } |
|
55 | + |
|
56 | + protected function enableYubikeyOtp() |
|
57 | + { |
|
58 | + $database = $this->getDatabase(); |
|
59 | + $currentUser = User::getCurrent($database); |
|
60 | + |
|
61 | + $otpCredentialProvider = new YubikeyOtpCredentialProvider($database, |
|
62 | + $this->getSiteConfiguration(), $this->getHttpHelper()); |
|
63 | + |
|
64 | + if (WebRequest::wasPosted()) { |
|
65 | + $this->validateCSRFToken(); |
|
66 | + |
|
67 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
68 | + $this->getSiteConfiguration()); |
|
69 | + |
|
70 | + $password = WebRequest::postString('password'); |
|
71 | + $otp = WebRequest::postString('otp'); |
|
72 | + |
|
73 | + $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
74 | + |
|
75 | + if ($result) { |
|
76 | + try { |
|
77 | + $otpCredentialProvider->setCredential($currentUser, 2, $otp); |
|
78 | + SessionAlert::success('Enabled YubiKey OTP.'); |
|
79 | + |
|
80 | + $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
81 | + if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
82 | + $scratchProvider->setCredential($currentUser, 2, null); |
|
83 | + $tokens = $scratchProvider->getTokens($currentUser->getId()); |
|
84 | + $this->assign('tokens', $tokens); |
|
85 | + $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
86 | + return; |
|
87 | + } |
|
88 | + } |
|
89 | + catch (ApplicationLogicException $ex) { |
|
90 | + SessionAlert::error('Error enabling YubiKey OTP: ' . $ex->getMessage()); |
|
91 | + } |
|
92 | + |
|
93 | + $this->redirect('multiFactor'); |
|
94 | + } |
|
95 | + else { |
|
96 | + SessionAlert::error('Error enabling YubiKey OTP - invalid credentials.'); |
|
97 | + $this->redirect('multiFactor'); |
|
98 | + } |
|
99 | + } |
|
100 | + else { |
|
101 | + if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
102 | + // user is not enrolled, we shouldn't have got here. |
|
103 | + throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism'); |
|
104 | + } |
|
105 | + |
|
106 | + $this->assignCSRFToken(); |
|
107 | + $this->setTemplate('mfa/enableYubikey.tpl'); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + protected function disableYubikeyOtp() |
|
112 | + { |
|
113 | + $database = $this->getDatabase(); |
|
114 | + $currentUser = User::getCurrent($database); |
|
201 | 115 | |
202 | - return; |
|
203 | - } |
|
204 | - } |
|
116 | + $otpCredentialProvider = new YubikeyOtpCredentialProvider($database, |
|
117 | + $this->getSiteConfiguration(), $this->getHttpHelper()); |
|
118 | + |
|
119 | + $factorType = 'YubiKey OTP'; |
|
120 | + |
|
121 | + $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType); |
|
122 | + } |
|
205 | 123 | |
206 | - // urgh, dunno what happened, but it's not something expected. |
|
207 | - throw new ApplicationLogicException(); |
|
208 | - } |
|
209 | - else { |
|
210 | - if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
211 | - // user is not enrolled, we shouldn't have got here. |
|
212 | - throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism'); |
|
213 | - } |
|
124 | + protected function enableTotp() |
|
125 | + { |
|
126 | + $database = $this->getDatabase(); |
|
127 | + $currentUser = User::getCurrent($database); |
|
128 | + |
|
129 | + $otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration()); |
|
130 | + |
|
131 | + if (WebRequest::wasPosted()) { |
|
132 | + $this->validateCSRFToken(); |
|
133 | + |
|
134 | + // used for routing only, not security |
|
135 | + $stage = WebRequest::postString('stage'); |
|
136 | + |
|
137 | + if ($stage === "auth") { |
|
138 | + $password = WebRequest::postString('password'); |
|
139 | + |
|
140 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
141 | + $this->getSiteConfiguration()); |
|
142 | + $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
143 | + |
|
144 | + if ($result) { |
|
145 | + $otpCredentialProvider->setCredential($currentUser, 2, null); |
|
146 | + |
|
147 | + $provisioningUrl = $otpCredentialProvider->getProvisioningUrl($currentUser); |
|
148 | + |
|
149 | + $renderer = new Svg(); |
|
150 | + $renderer->setHeight(256); |
|
151 | + $renderer->setWidth(256); |
|
152 | + $writer = new Writer($renderer); |
|
153 | + $svg = $writer->writeString($provisioningUrl); |
|
154 | + |
|
155 | + $this->assign('svg', $svg); |
|
156 | + $this->assign('secret', $otpCredentialProvider->getSecret($currentUser)); |
|
157 | + |
|
158 | + $this->assignCSRFToken(); |
|
159 | + $this->setTemplate('mfa/enableTotpEnroll.tpl'); |
|
160 | + |
|
161 | + return; |
|
162 | + } |
|
163 | + else { |
|
164 | + SessionAlert::error('Error enabling TOTP - invalid credentials.'); |
|
165 | + $this->redirect('multiFactor'); |
|
166 | + |
|
167 | + return; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + if ($stage === "enroll") { |
|
172 | + // we *must* have a defined credential already here, |
|
173 | + if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) { |
|
174 | + $otp = WebRequest::postString('otp'); |
|
175 | + $result = $otpCredentialProvider->verifyEnable($currentUser, $otp); |
|
176 | + |
|
177 | + if ($result) { |
|
178 | + SessionAlert::success('Enabled TOTP.'); |
|
179 | + |
|
180 | + $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
181 | + if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
182 | + $scratchProvider->setCredential($currentUser, 2, null); |
|
183 | + $tokens = $scratchProvider->getTokens($currentUser->getId()); |
|
184 | + $this->assign('tokens', $tokens); |
|
185 | + $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
186 | + return; |
|
187 | + } |
|
188 | + } |
|
189 | + else { |
|
190 | + $otpCredentialProvider->deleteCredential($currentUser); |
|
191 | + SessionAlert::error('Error enabling TOTP: invalid token provided'); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + $this->redirect('multiFactor'); |
|
196 | + return; |
|
197 | + } |
|
198 | + else { |
|
199 | + SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.'); |
|
200 | + $this->redirect('multiFactor'); |
|
201 | + |
|
202 | + return; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + // urgh, dunno what happened, but it's not something expected. |
|
207 | + throw new ApplicationLogicException(); |
|
208 | + } |
|
209 | + else { |
|
210 | + if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
211 | + // user is not enrolled, we shouldn't have got here. |
|
212 | + throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism'); |
|
213 | + } |
|
214 | + |
|
215 | + $this->assignCSRFToken(); |
|
216 | + $this->setTemplate('mfa/enableTotpAuth.tpl'); |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + protected function disableTotp() |
|
221 | + { |
|
222 | + $database = $this->getDatabase(); |
|
223 | + $currentUser = User::getCurrent($database); |
|
224 | + |
|
225 | + $otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration()); |
|
226 | + |
|
227 | + $factorType = 'TOTP'; |
|
228 | + |
|
229 | + $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType); |
|
230 | + } |
|
214 | 231 | |
215 | - $this->assignCSRFToken(); |
|
216 | - $this->setTemplate('mfa/enableTotpAuth.tpl'); |
|
217 | - } |
|
218 | - } |
|
232 | + protected function enableU2F() { |
|
233 | + $database = $this->getDatabase(); |
|
234 | + $currentUser = User::getCurrent($database); |
|
219 | 235 | |
220 | - protected function disableTotp() |
|
221 | - { |
|
222 | - $database = $this->getDatabase(); |
|
223 | - $currentUser = User::getCurrent($database); |
|
236 | + $otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration()); |
|
224 | 237 | |
225 | - $otpCredentialProvider = new TotpCredentialProvider($database, $this->getSiteConfiguration()); |
|
238 | + if (WebRequest::wasPosted()) { |
|
239 | + $this->validateCSRFToken(); |
|
226 | 240 | |
227 | - $factorType = 'TOTP'; |
|
241 | + // used for routing only, not security |
|
242 | + $stage = WebRequest::postString('stage'); |
|
228 | 243 | |
229 | - $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType); |
|
230 | - } |
|
244 | + if ($stage === "auth") { |
|
245 | + $password = WebRequest::postString('password'); |
|
231 | 246 | |
232 | - protected function enableU2F() { |
|
233 | - $database = $this->getDatabase(); |
|
234 | - $currentUser = User::getCurrent($database); |
|
247 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
248 | + $this->getSiteConfiguration()); |
|
249 | + $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
235 | 250 | |
236 | - $otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration()); |
|
237 | - |
|
238 | - if (WebRequest::wasPosted()) { |
|
239 | - $this->validateCSRFToken(); |
|
240 | - |
|
241 | - // used for routing only, not security |
|
242 | - $stage = WebRequest::postString('stage'); |
|
251 | + if ($result) { |
|
252 | + $otpCredentialProvider->setCredential($currentUser, 2, null); |
|
253 | + $this->assignCSRFToken(); |
|
243 | 254 | |
244 | - if ($stage === "auth") { |
|
245 | - $password = WebRequest::postString('password'); |
|
246 | - |
|
247 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
248 | - $this->getSiteConfiguration()); |
|
249 | - $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
250 | - |
|
251 | - if ($result) { |
|
252 | - $otpCredentialProvider->setCredential($currentUser, 2, null); |
|
253 | - $this->assignCSRFToken(); |
|
254 | - |
|
255 | - list($data, $reqs) = $otpCredentialProvider->getRegistrationData(); |
|
256 | - |
|
257 | - $u2fRequest =json_encode($data); |
|
258 | - $u2fSigns = json_encode($reqs); |
|
259 | - |
|
260 | - $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js'); |
|
261 | - $this->setTailScript(<<<JS |
|
255 | + list($data, $reqs) = $otpCredentialProvider->getRegistrationData(); |
|
256 | + |
|
257 | + $u2fRequest =json_encode($data); |
|
258 | + $u2fSigns = json_encode($reqs); |
|
259 | + |
|
260 | + $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js'); |
|
261 | + $this->setTailScript(<<<JS |
|
262 | 262 | var request = ${u2fRequest}; |
263 | 263 | var signs = ${u2fSigns}; |
264 | 264 | |
@@ -277,153 +277,153 @@ discard block |
||
277 | 277 | form.submit(); |
278 | 278 | }); |
279 | 279 | JS |
280 | - ); |
|
281 | - |
|
282 | - $this->setTemplate('mfa/enableU2FEnroll.tpl'); |
|
283 | - |
|
284 | - return; |
|
285 | - } |
|
286 | - else { |
|
287 | - SessionAlert::error('Error enabling TOTP - invalid credentials.'); |
|
288 | - $this->redirect('multiFactor'); |
|
289 | - |
|
290 | - return; |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - if ($stage === "enroll") { |
|
295 | - // we *must* have a defined credential already here, |
|
296 | - if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) { |
|
297 | - |
|
298 | - $request = json_decode(WebRequest::postString('u2fRequest')); |
|
299 | - $u2fData = json_decode(WebRequest::postString('u2fData')); |
|
300 | - |
|
301 | - $otpCredentialProvider->enable($currentUser, $request, $u2fData); |
|
302 | - |
|
303 | - SessionAlert::success('Enabled TOTP.'); |
|
304 | - |
|
305 | - $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
306 | - if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
307 | - $scratchProvider->setCredential($currentUser, 2, null); |
|
308 | - $tokens = $scratchProvider->getTokens($currentUser->getId()); |
|
309 | - $this->assign('tokens', $tokens); |
|
310 | - $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
311 | - return; |
|
312 | - } |
|
313 | - |
|
314 | - $this->redirect('multiFactor'); |
|
315 | - return; |
|
316 | - } |
|
317 | - else { |
|
318 | - SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.'); |
|
319 | - $this->redirect('multiFactor'); |
|
320 | - |
|
321 | - return; |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - // urgh, dunno what happened, but it's not something expected. |
|
326 | - throw new ApplicationLogicException(); |
|
327 | - } |
|
328 | - else { |
|
329 | - if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
330 | - // user is not enrolled, we shouldn't have got here. |
|
331 | - throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism'); |
|
332 | - } |
|
333 | - |
|
334 | - $this->assignCSRFToken(); |
|
335 | - $this->setTemplate('mfa/enableU2FAuth.tpl'); |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - protected function disableU2F() { |
|
340 | - $database = $this->getDatabase(); |
|
341 | - $currentUser = User::getCurrent($database); |
|
342 | - |
|
343 | - $otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration()); |
|
344 | - |
|
345 | - $factorType = 'U2F'; |
|
346 | - |
|
347 | - $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType); |
|
348 | - } |
|
349 | - |
|
350 | - protected function scratch() |
|
351 | - { |
|
352 | - $database = $this->getDatabase(); |
|
353 | - $currentUser = User::getCurrent($database); |
|
354 | - |
|
355 | - if (WebRequest::wasPosted()) { |
|
356 | - $this->validateCSRFToken(); |
|
357 | - |
|
358 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
359 | - $this->getSiteConfiguration()); |
|
360 | - |
|
361 | - $otpCredentialProvider = new ScratchTokenCredentialProvider($database, |
|
362 | - $this->getSiteConfiguration()); |
|
363 | - |
|
364 | - $password = WebRequest::postString('password'); |
|
365 | - |
|
366 | - $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
367 | - |
|
368 | - if ($result) { |
|
369 | - $otpCredentialProvider->setCredential($currentUser, 2, null); |
|
370 | - $tokens = $otpCredentialProvider->getTokens($currentUser->getId()); |
|
371 | - $this->assign('tokens', $tokens); |
|
372 | - $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
373 | - } |
|
374 | - else { |
|
375 | - SessionAlert::error('Error refreshing scratch tokens - invalid credentials.'); |
|
376 | - $this->redirect('multiFactor'); |
|
377 | - } |
|
378 | - } |
|
379 | - else { |
|
380 | - $this->assignCSRFToken(); |
|
381 | - $this->setTemplate('mfa/regenScratchAuth.tpl'); |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * @param PdoDatabase $database |
|
387 | - * @param User $currentUser |
|
388 | - * @param ICredentialProvider $otpCredentialProvider |
|
389 | - * @param string $factorType |
|
390 | - * |
|
391 | - * @throws ApplicationLogicException |
|
392 | - */ |
|
393 | - private function deleteCredential( |
|
394 | - PdoDatabase $database, |
|
395 | - User $currentUser, |
|
396 | - ICredentialProvider $otpCredentialProvider, |
|
397 | - $factorType |
|
398 | - ) { |
|
399 | - if (WebRequest::wasPosted()) { |
|
400 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
401 | - $this->getSiteConfiguration()); |
|
402 | - |
|
403 | - $this->validateCSRFToken(); |
|
404 | - |
|
405 | - $password = WebRequest::postString('password'); |
|
406 | - $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
407 | - |
|
408 | - if ($result) { |
|
409 | - $otpCredentialProvider->deleteCredential($currentUser); |
|
410 | - SessionAlert::success('Disabled ' . $factorType . '.'); |
|
411 | - $this->redirect('multiFactor'); |
|
412 | - } |
|
413 | - else { |
|
414 | - SessionAlert::error('Error disabling ' . $factorType . ' - invalid credentials.'); |
|
415 | - $this->redirect('multiFactor'); |
|
416 | - } |
|
417 | - } |
|
418 | - else { |
|
419 | - if (!$otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
420 | - // user is not enrolled, we shouldn't have got here. |
|
421 | - throw new ApplicationLogicException('User is not enrolled in the selected MFA mechanism'); |
|
422 | - } |
|
423 | - |
|
424 | - $this->assignCSRFToken(); |
|
425 | - $this->assign('otpType', $factorType); |
|
426 | - $this->setTemplate('mfa/disableOtp.tpl'); |
|
427 | - } |
|
428 | - } |
|
280 | + ); |
|
281 | + |
|
282 | + $this->setTemplate('mfa/enableU2FEnroll.tpl'); |
|
283 | + |
|
284 | + return; |
|
285 | + } |
|
286 | + else { |
|
287 | + SessionAlert::error('Error enabling TOTP - invalid credentials.'); |
|
288 | + $this->redirect('multiFactor'); |
|
289 | + |
|
290 | + return; |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + if ($stage === "enroll") { |
|
295 | + // we *must* have a defined credential already here, |
|
296 | + if ($otpCredentialProvider->isPartiallyEnrolled($currentUser)) { |
|
297 | + |
|
298 | + $request = json_decode(WebRequest::postString('u2fRequest')); |
|
299 | + $u2fData = json_decode(WebRequest::postString('u2fData')); |
|
300 | + |
|
301 | + $otpCredentialProvider->enable($currentUser, $request, $u2fData); |
|
302 | + |
|
303 | + SessionAlert::success('Enabled TOTP.'); |
|
304 | + |
|
305 | + $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
|
306 | + if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
307 | + $scratchProvider->setCredential($currentUser, 2, null); |
|
308 | + $tokens = $scratchProvider->getTokens($currentUser->getId()); |
|
309 | + $this->assign('tokens', $tokens); |
|
310 | + $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
311 | + return; |
|
312 | + } |
|
313 | + |
|
314 | + $this->redirect('multiFactor'); |
|
315 | + return; |
|
316 | + } |
|
317 | + else { |
|
318 | + SessionAlert::error('Error enabling TOTP - no enrollment found or enrollment expired.'); |
|
319 | + $this->redirect('multiFactor'); |
|
320 | + |
|
321 | + return; |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + // urgh, dunno what happened, but it's not something expected. |
|
326 | + throw new ApplicationLogicException(); |
|
327 | + } |
|
328 | + else { |
|
329 | + if ($otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
330 | + // user is not enrolled, we shouldn't have got here. |
|
331 | + throw new ApplicationLogicException('User is already enrolled in the selected MFA mechanism'); |
|
332 | + } |
|
333 | + |
|
334 | + $this->assignCSRFToken(); |
|
335 | + $this->setTemplate('mfa/enableU2FAuth.tpl'); |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + protected function disableU2F() { |
|
340 | + $database = $this->getDatabase(); |
|
341 | + $currentUser = User::getCurrent($database); |
|
342 | + |
|
343 | + $otpCredentialProvider = new U2FCredentialProvider($database, $this->getSiteConfiguration()); |
|
344 | + |
|
345 | + $factorType = 'U2F'; |
|
346 | + |
|
347 | + $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType); |
|
348 | + } |
|
349 | + |
|
350 | + protected function scratch() |
|
351 | + { |
|
352 | + $database = $this->getDatabase(); |
|
353 | + $currentUser = User::getCurrent($database); |
|
354 | + |
|
355 | + if (WebRequest::wasPosted()) { |
|
356 | + $this->validateCSRFToken(); |
|
357 | + |
|
358 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
359 | + $this->getSiteConfiguration()); |
|
360 | + |
|
361 | + $otpCredentialProvider = new ScratchTokenCredentialProvider($database, |
|
362 | + $this->getSiteConfiguration()); |
|
363 | + |
|
364 | + $password = WebRequest::postString('password'); |
|
365 | + |
|
366 | + $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
367 | + |
|
368 | + if ($result) { |
|
369 | + $otpCredentialProvider->setCredential($currentUser, 2, null); |
|
370 | + $tokens = $otpCredentialProvider->getTokens($currentUser->getId()); |
|
371 | + $this->assign('tokens', $tokens); |
|
372 | + $this->setTemplate('mfa/regenScratchTokens.tpl'); |
|
373 | + } |
|
374 | + else { |
|
375 | + SessionAlert::error('Error refreshing scratch tokens - invalid credentials.'); |
|
376 | + $this->redirect('multiFactor'); |
|
377 | + } |
|
378 | + } |
|
379 | + else { |
|
380 | + $this->assignCSRFToken(); |
|
381 | + $this->setTemplate('mfa/regenScratchAuth.tpl'); |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * @param PdoDatabase $database |
|
387 | + * @param User $currentUser |
|
388 | + * @param ICredentialProvider $otpCredentialProvider |
|
389 | + * @param string $factorType |
|
390 | + * |
|
391 | + * @throws ApplicationLogicException |
|
392 | + */ |
|
393 | + private function deleteCredential( |
|
394 | + PdoDatabase $database, |
|
395 | + User $currentUser, |
|
396 | + ICredentialProvider $otpCredentialProvider, |
|
397 | + $factorType |
|
398 | + ) { |
|
399 | + if (WebRequest::wasPosted()) { |
|
400 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, |
|
401 | + $this->getSiteConfiguration()); |
|
402 | + |
|
403 | + $this->validateCSRFToken(); |
|
404 | + |
|
405 | + $password = WebRequest::postString('password'); |
|
406 | + $result = $passwordCredentialProvider->authenticate($currentUser, $password); |
|
407 | + |
|
408 | + if ($result) { |
|
409 | + $otpCredentialProvider->deleteCredential($currentUser); |
|
410 | + SessionAlert::success('Disabled ' . $factorType . '.'); |
|
411 | + $this->redirect('multiFactor'); |
|
412 | + } |
|
413 | + else { |
|
414 | + SessionAlert::error('Error disabling ' . $factorType . ' - invalid credentials.'); |
|
415 | + $this->redirect('multiFactor'); |
|
416 | + } |
|
417 | + } |
|
418 | + else { |
|
419 | + if (!$otpCredentialProvider->userIsEnrolled($currentUser->getId())) { |
|
420 | + // user is not enrolled, we shouldn't have got here. |
|
421 | + throw new ApplicationLogicException('User is not enrolled in the selected MFA mechanism'); |
|
422 | + } |
|
423 | + |
|
424 | + $this->assignCSRFToken(); |
|
425 | + $this->assign('otpType', $factorType); |
|
426 | + $this->setTemplate('mfa/disableOtp.tpl'); |
|
427 | + } |
|
428 | + } |
|
429 | 429 | } |
430 | 430 | \ No newline at end of file |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | SessionAlert::success('Enabled YubiKey OTP.'); |
79 | 79 | |
80 | 80 | $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
81 | - if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
81 | + if ($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
82 | 82 | $scratchProvider->setCredential($currentUser, 2, null); |
83 | 83 | $tokens = $scratchProvider->getTokens($currentUser->getId()); |
84 | 84 | $this->assign('tokens', $tokens); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | } |
89 | 89 | catch (ApplicationLogicException $ex) { |
90 | - SessionAlert::error('Error enabling YubiKey OTP: ' . $ex->getMessage()); |
|
90 | + SessionAlert::error('Error enabling YubiKey OTP: '.$ex->getMessage()); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $this->redirect('multiFactor'); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | SessionAlert::success('Enabled TOTP.'); |
179 | 179 | |
180 | 180 | $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
181 | - if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
181 | + if ($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
182 | 182 | $scratchProvider->setCredential($currentUser, 2, null); |
183 | 183 | $tokens = $scratchProvider->getTokens($currentUser->getId()); |
184 | 184 | $this->assign('tokens', $tokens); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | |
255 | 255 | list($data, $reqs) = $otpCredentialProvider->getRegistrationData(); |
256 | 256 | |
257 | - $u2fRequest =json_encode($data); |
|
257 | + $u2fRequest = json_encode($data); |
|
258 | 258 | $u2fSigns = json_encode($reqs); |
259 | 259 | |
260 | 260 | $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js'); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | SessionAlert::success('Enabled TOTP.'); |
304 | 304 | |
305 | 305 | $scratchProvider = new ScratchTokenCredentialProvider($database, $this->getSiteConfiguration()); |
306 | - if($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
306 | + if ($scratchProvider->getRemaining($currentUser->getId()) < 3) { |
|
307 | 307 | $scratchProvider->setCredential($currentUser, 2, null); |
308 | 308 | $tokens = $scratchProvider->getTokens($currentUser->getId()); |
309 | 309 | $this->assign('tokens', $tokens); |
@@ -407,11 +407,11 @@ discard block |
||
407 | 407 | |
408 | 408 | if ($result) { |
409 | 409 | $otpCredentialProvider->deleteCredential($currentUser); |
410 | - SessionAlert::success('Disabled ' . $factorType . '.'); |
|
410 | + SessionAlert::success('Disabled '.$factorType.'.'); |
|
411 | 411 | $this->redirect('multiFactor'); |
412 | 412 | } |
413 | 413 | else { |
414 | - SessionAlert::error('Error disabling ' . $factorType . ' - invalid credentials.'); |
|
414 | + SessionAlert::error('Error disabling '.$factorType.' - invalid credentials.'); |
|
415 | 415 | $this->redirect('multiFactor'); |
416 | 416 | } |
417 | 417 | } |
@@ -229,7 +229,8 @@ discard block |
||
229 | 229 | $this->deleteCredential($database, $currentUser, $otpCredentialProvider, $factorType); |
230 | 230 | } |
231 | 231 | |
232 | - protected function enableU2F() { |
|
232 | + protected function enableU2F() |
|
233 | + { |
|
233 | 234 | $database = $this->getDatabase(); |
234 | 235 | $currentUser = User::getCurrent($database); |
235 | 236 | |
@@ -336,7 +337,8 @@ discard block |
||
336 | 337 | } |
337 | 338 | } |
338 | 339 | |
339 | - protected function disableU2F() { |
|
340 | + protected function disableU2F() |
|
341 | + { |
|
340 | 342 | $database = $this->getDatabase(); |
341 | 343 | $currentUser = User::getCurrent($database); |
342 | 344 |
@@ -17,90 +17,90 @@ |
||
17 | 17 | |
18 | 18 | class PageOAuthCallback extends InternalPageBase |
19 | 19 | { |
20 | - /** |
|
21 | - * @return bool |
|
22 | - */ |
|
23 | - protected function isProtectedPage() |
|
24 | - { |
|
25 | - // This page is critical to ensuring OAuth functionality is operational. |
|
26 | - return false; |
|
27 | - } |
|
20 | + /** |
|
21 | + * @return bool |
|
22 | + */ |
|
23 | + protected function isProtectedPage() |
|
24 | + { |
|
25 | + // This page is critical to ensuring OAuth functionality is operational. |
|
26 | + return false; |
|
27 | + } |
|
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 should never get hit except by URL manipulation. |
|
36 | - $this->redirect(''); |
|
37 | - } |
|
29 | + /** |
|
30 | + * Main function for this page, when no specific actions are called. |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + protected function main() |
|
34 | + { |
|
35 | + // This should never get hit except by URL manipulation. |
|
36 | + $this->redirect(''); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Registered endpoint for the account creation callback. |
|
41 | - * |
|
42 | - * If this ever gets hit, something is wrong somewhere. |
|
43 | - */ |
|
44 | - protected function create() |
|
45 | - { |
|
46 | - throw new Exception('OAuth account creation endpoint triggered.'); |
|
47 | - } |
|
39 | + /** |
|
40 | + * Registered endpoint for the account creation callback. |
|
41 | + * |
|
42 | + * If this ever gets hit, something is wrong somewhere. |
|
43 | + */ |
|
44 | + protected function create() |
|
45 | + { |
|
46 | + throw new Exception('OAuth account creation endpoint triggered.'); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Callback entry point |
|
51 | - */ |
|
52 | - protected function authorise() |
|
53 | - { |
|
54 | - $oauthToken = WebRequest::getString('oauth_token'); |
|
55 | - $oauthVerifier = WebRequest::getString('oauth_verifier'); |
|
49 | + /** |
|
50 | + * Callback entry point |
|
51 | + */ |
|
52 | + protected function authorise() |
|
53 | + { |
|
54 | + $oauthToken = WebRequest::getString('oauth_token'); |
|
55 | + $oauthVerifier = WebRequest::getString('oauth_verifier'); |
|
56 | 56 | |
57 | - $this->doCallbackValidation($oauthToken, $oauthVerifier); |
|
57 | + $this->doCallbackValidation($oauthToken, $oauthVerifier); |
|
58 | 58 | |
59 | - $database = $this->getDatabase(); |
|
59 | + $database = $this->getDatabase(); |
|
60 | 60 | |
61 | - $user = OAuthUserHelper::findUserByRequestToken($oauthToken, $database); |
|
62 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
61 | + $user = OAuthUserHelper::findUserByRequestToken($oauthToken, $database); |
|
62 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
63 | 63 | |
64 | - try { |
|
65 | - $oauth->completeHandshake($oauthVerifier); |
|
66 | - } |
|
67 | - catch (CurlException $ex) { |
|
68 | - throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
69 | - } |
|
64 | + try { |
|
65 | + $oauth->completeHandshake($oauthVerifier); |
|
66 | + } |
|
67 | + catch (CurlException $ex) { |
|
68 | + throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
69 | + } |
|
70 | 70 | |
71 | - // OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the |
|
72 | - // login to a full login |
|
73 | - if (WebRequest::getOAuthPartialLogin() === $user->getId()) { |
|
74 | - WebRequest::setLoggedInUser($user); |
|
75 | - } |
|
71 | + // OK, we're the same session that just did a partial login that was redirected to OAuth. Let's upgrade the |
|
72 | + // login to a full login |
|
73 | + if (WebRequest::getOAuthPartialLogin() === $user->getId()) { |
|
74 | + WebRequest::setLoggedInUser($user); |
|
75 | + } |
|
76 | 76 | |
77 | - // My thinking is there are three cases here: |
|
78 | - // a) new user => redirect to prefs - it's the only thing they can access other than stats |
|
79 | - // b) existing user hit the connect button in prefs => redirect to prefs since it's where they were |
|
80 | - // c) existing user logging in => redirect to wherever they came from |
|
81 | - $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
82 | - if ($redirectDestination !== null && !$user->isNewUser()) { |
|
83 | - $this->redirectUrl($redirectDestination); |
|
84 | - } |
|
85 | - else { |
|
86 | - $this->redirect('preferences', null, null, 'internal.php'); |
|
87 | - } |
|
88 | - } |
|
77 | + // My thinking is there are three cases here: |
|
78 | + // a) new user => redirect to prefs - it's the only thing they can access other than stats |
|
79 | + // b) existing user hit the connect button in prefs => redirect to prefs since it's where they were |
|
80 | + // c) existing user logging in => redirect to wherever they came from |
|
81 | + $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
82 | + if ($redirectDestination !== null && !$user->isNewUser()) { |
|
83 | + $this->redirectUrl($redirectDestination); |
|
84 | + } |
|
85 | + else { |
|
86 | + $this->redirect('preferences', null, null, 'internal.php'); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param string $oauthToken |
|
92 | - * @param string $oauthVerifier |
|
93 | - * |
|
94 | - * @throws ApplicationLogicException |
|
95 | - */ |
|
96 | - private function doCallbackValidation($oauthToken, $oauthVerifier) |
|
97 | - { |
|
98 | - if ($oauthToken === null) { |
|
99 | - throw new ApplicationLogicException('No token provided'); |
|
100 | - } |
|
90 | + /** |
|
91 | + * @param string $oauthToken |
|
92 | + * @param string $oauthVerifier |
|
93 | + * |
|
94 | + * @throws ApplicationLogicException |
|
95 | + */ |
|
96 | + private function doCallbackValidation($oauthToken, $oauthVerifier) |
|
97 | + { |
|
98 | + if ($oauthToken === null) { |
|
99 | + throw new ApplicationLogicException('No token provided'); |
|
100 | + } |
|
101 | 101 | |
102 | - if ($oauthVerifier === null) { |
|
103 | - throw new ApplicationLogicException('No oauth verifier provided.'); |
|
104 | - } |
|
105 | - } |
|
102 | + if ($oauthVerifier === null) { |
|
103 | + throw new ApplicationLogicException('No oauth verifier provided.'); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | \ No newline at end of file |
@@ -13,31 +13,31 @@ |
||
13 | 13 | |
14 | 14 | class PagePasswordLogin extends LoginCredentialPageBase |
15 | 15 | { |
16 | - protected function providerSpecificSetup() |
|
17 | - { |
|
18 | - list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
19 | - |
|
20 | - if($partialId !== null && $partialStage > 1) { |
|
21 | - $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
22 | - $statement = $this->getDatabase()->prepare($sql); |
|
23 | - $statement->execute(array(':user' => $partialId, ':stage' => $partialStage)); |
|
24 | - $nextStage = $statement->fetchColumn(); |
|
25 | - $statement->closeCursor(); |
|
26 | - |
|
27 | - $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
28 | - return; |
|
29 | - } |
|
30 | - |
|
31 | - $this->setTemplate('login/password.tpl'); |
|
32 | - } |
|
33 | - |
|
34 | - protected function getProviderCredentials() |
|
35 | - { |
|
36 | - $password = WebRequest::postString("password"); |
|
37 | - if ($password === null || $password === "") { |
|
38 | - throw new ApplicationLogicException("No password specified"); |
|
39 | - } |
|
40 | - |
|
41 | - return $password; |
|
42 | - } |
|
16 | + protected function providerSpecificSetup() |
|
17 | + { |
|
18 | + list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
19 | + |
|
20 | + if($partialId !== null && $partialStage > 1) { |
|
21 | + $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
22 | + $statement = $this->getDatabase()->prepare($sql); |
|
23 | + $statement->execute(array(':user' => $partialId, ':stage' => $partialStage)); |
|
24 | + $nextStage = $statement->fetchColumn(); |
|
25 | + $statement->closeCursor(); |
|
26 | + |
|
27 | + $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
28 | + return; |
|
29 | + } |
|
30 | + |
|
31 | + $this->setTemplate('login/password.tpl'); |
|
32 | + } |
|
33 | + |
|
34 | + protected function getProviderCredentials() |
|
35 | + { |
|
36 | + $password = WebRequest::postString("password"); |
|
37 | + if ($password === null || $password === "") { |
|
38 | + throw new ApplicationLogicException("No password specified"); |
|
39 | + } |
|
40 | + |
|
41 | + return $password; |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -17,14 +17,14 @@ |
||
17 | 17 | { |
18 | 18 | list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
19 | 19 | |
20 | - if($partialId !== null && $partialStage > 1) { |
|
20 | + if ($partialId !== null && $partialStage > 1) { |
|
21 | 21 | $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
22 | 22 | $statement = $this->getDatabase()->prepare($sql); |
23 | 23 | $statement->execute(array(':user' => $partialId, ':stage' => $partialStage)); |
24 | 24 | $nextStage = $statement->fetchColumn(); |
25 | 25 | $statement->closeCursor(); |
26 | 26 | |
27 | - $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
27 | + $this->redirect("login/".$this->nextPageMap[$nextStage]); |
|
28 | 28 | return; |
29 | 29 | } |
30 | 30 |
@@ -14,20 +14,20 @@ discard block |
||
14 | 14 | |
15 | 15 | class PageU2FLogin extends LoginCredentialPageBase |
16 | 16 | { |
17 | - protected function providerSpecificSetup() |
|
18 | - { |
|
19 | - $this->assign('showSignIn', false); |
|
20 | - $this->setTemplate('login/u2f.tpl'); |
|
17 | + protected function providerSpecificSetup() |
|
18 | + { |
|
19 | + $this->assign('showSignIn', false); |
|
20 | + $this->setTemplate('login/u2f.tpl'); |
|
21 | 21 | |
22 | - if ($this->partialUser === null) { |
|
23 | - throw new ApplicationLogicException("U2F cannot be first-stage authentication"); |
|
24 | - } |
|
22 | + if ($this->partialUser === null) { |
|
23 | + throw new ApplicationLogicException("U2F cannot be first-stage authentication"); |
|
24 | + } |
|
25 | 25 | |
26 | - $u2f = new U2FCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
27 | - $authData = json_encode($u2f->getAuthenticationData($this->partialUser)); |
|
26 | + $u2f = new U2FCredentialProvider($this->getDatabase(), $this->getSiteConfiguration()); |
|
27 | + $authData = json_encode($u2f->getAuthenticationData($this->partialUser)); |
|
28 | 28 | |
29 | - $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js'); |
|
30 | - $this->setTailScript(<<<JS |
|
29 | + $this->addJs('/vendor/yubico/u2flib-server/examples/assets/u2f-api.js'); |
|
30 | + $this->setTailScript(<<<JS |
|
31 | 31 | var request = ${authData}; |
32 | 32 | console.log("starting sign"); |
33 | 33 | u2f.sign(request, function(data) { |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | form.submit(); |
45 | 45 | }); |
46 | 46 | JS |
47 | - ); |
|
47 | + ); |
|
48 | 48 | |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - protected function getProviderCredentials() |
|
52 | - { |
|
53 | - $authenticate = WebRequest::postString("authenticate"); |
|
54 | - $request = WebRequest::postString("request"); |
|
51 | + protected function getProviderCredentials() |
|
52 | + { |
|
53 | + $authenticate = WebRequest::postString("authenticate"); |
|
54 | + $request = WebRequest::postString("request"); |
|
55 | 55 | |
56 | - if ($authenticate === null || $authenticate === "" || $request === null || $request === "") { |
|
57 | - throw new ApplicationLogicException("No authentication specified"); |
|
58 | - } |
|
56 | + if ($authenticate === null || $authenticate === "" || $request === null || $request === "") { |
|
57 | + throw new ApplicationLogicException("No authentication specified"); |
|
58 | + } |
|
59 | 59 | |
60 | - return array(json_decode($authenticate), json_decode($request), 'u2f'); |
|
61 | - } |
|
60 | + return array(json_decode($authenticate), json_decode($request), 'u2f'); |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | \ No newline at end of file |
@@ -13,18 +13,18 @@ |
||
13 | 13 | |
14 | 14 | class PageOtpLogin extends LoginCredentialPageBase |
15 | 15 | { |
16 | - protected function providerSpecificSetup() |
|
17 | - { |
|
18 | - $this->setTemplate('login/otp.tpl'); |
|
19 | - } |
|
16 | + protected function providerSpecificSetup() |
|
17 | + { |
|
18 | + $this->setTemplate('login/otp.tpl'); |
|
19 | + } |
|
20 | 20 | |
21 | - protected function getProviderCredentials() |
|
22 | - { |
|
23 | - $otp = WebRequest::postString("otp"); |
|
24 | - if ($otp === null || $otp === "") { |
|
25 | - throw new ApplicationLogicException("No one-time code specified"); |
|
26 | - } |
|
21 | + protected function getProviderCredentials() |
|
22 | + { |
|
23 | + $otp = WebRequest::postString("otp"); |
|
24 | + if ($otp === null || $otp === "") { |
|
25 | + throw new ApplicationLogicException("No one-time code specified"); |
|
26 | + } |
|
27 | 27 | |
28 | - return $otp; |
|
29 | - } |
|
28 | + return $otp; |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -20,200 +20,200 @@ |
||
20 | 20 | |
21 | 21 | abstract class PageRegisterBase extends InternalPageBase |
22 | 22 | { |
23 | - /** |
|
24 | - * Main function for this page, when no specific actions are called. |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
29 | - |
|
30 | - // Dual-mode page |
|
31 | - if (WebRequest::wasPosted()) { |
|
32 | - $this->validateCSRFToken(); |
|
33 | - |
|
34 | - try { |
|
35 | - $this->handlePost($useOAuthSignup); |
|
36 | - } |
|
37 | - catch (ApplicationLogicException $ex) { |
|
38 | - SessionAlert::error($ex->getMessage()); |
|
39 | - $this->redirect('register'); |
|
40 | - } |
|
41 | - } |
|
42 | - else { |
|
43 | - $this->assignCSRFToken(); |
|
44 | - $this->assign("useOAuthSignup", $useOAuthSignup); |
|
45 | - $this->setTemplate($this->getRegistrationTemplate()); |
|
46 | - } |
|
47 | - } |
|
48 | - |
|
49 | - protected abstract function getRegistrationTemplate(); |
|
50 | - |
|
51 | - protected function isProtectedPage() |
|
52 | - { |
|
53 | - return false; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $emailAddress |
|
58 | - * |
|
59 | - * @throws ApplicationLogicException |
|
60 | - */ |
|
61 | - protected function validateUniqueEmail($emailAddress) |
|
62 | - { |
|
63 | - $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
64 | - $statement = $this->getDatabase()->prepare($query); |
|
65 | - $statement->execute(array(':email' => $emailAddress)); |
|
66 | - |
|
67 | - if ($statement->fetchColumn() > 0) { |
|
68 | - throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
69 | - } |
|
70 | - |
|
71 | - $statement->closeCursor(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param $emailAddress |
|
76 | - * @param $password |
|
77 | - * @param $username |
|
78 | - * @param $useOAuthSignup |
|
79 | - * @param $confirmationId |
|
80 | - * @param $onwikiUsername |
|
81 | - * |
|
82 | - * @throws ApplicationLogicException |
|
83 | - */ |
|
84 | - protected function validateRequest( |
|
85 | - $emailAddress, |
|
86 | - $password, |
|
87 | - $username, |
|
88 | - $useOAuthSignup, |
|
89 | - $confirmationId, |
|
90 | - $onwikiUsername |
|
91 | - ) { |
|
92 | - if (!WebRequest::postBoolean('guidelines')) { |
|
93 | - throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
94 | - } |
|
95 | - |
|
96 | - $this->validateGeneralInformation($emailAddress, $password, $username); |
|
97 | - $this->validateUniqueEmail($emailAddress); |
|
98 | - $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param $useOAuthSignup |
|
103 | - * @param $confirmationId |
|
104 | - * @param $onwikiUsername |
|
105 | - * |
|
106 | - * @throws ApplicationLogicException |
|
107 | - */ |
|
108 | - protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
109 | - { |
|
110 | - if (!$useOAuthSignup) { |
|
111 | - if ($confirmationId === null || $confirmationId <= 0) { |
|
112 | - throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
113 | - } |
|
114 | - |
|
115 | - if ($onwikiUsername === null) { |
|
116 | - throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
117 | - } |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param $emailAddress |
|
123 | - * @param $password |
|
124 | - * @param $username |
|
125 | - * |
|
126 | - * @throws ApplicationLogicException |
|
127 | - */ |
|
128 | - protected function validateGeneralInformation($emailAddress, $password, $username) |
|
129 | - { |
|
130 | - if ($emailAddress === null) { |
|
131 | - throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
132 | - } |
|
133 | - |
|
134 | - if ($password !== WebRequest::postString('pass2')) { |
|
135 | - throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
136 | - } |
|
137 | - |
|
138 | - if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
139 | - throw new ApplicationLogicException('That username is already in use on this system.'); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param $useOAuthSignup |
|
145 | - * |
|
146 | - * @throws ApplicationLogicException |
|
147 | - * @throws \Exception |
|
148 | - */ |
|
149 | - protected function handlePost($useOAuthSignup) |
|
150 | - { |
|
151 | - // Get the data |
|
152 | - $emailAddress = WebRequest::postEmail('email'); |
|
153 | - $password = WebRequest::postString('pass'); |
|
154 | - $username = WebRequest::postString('name'); |
|
155 | - |
|
156 | - // Only set if OAuth is disabled |
|
157 | - $confirmationId = WebRequest::postInt('conf_revid'); |
|
158 | - $onwikiUsername = WebRequest::postString('wname'); |
|
159 | - |
|
160 | - // Do some validation |
|
161 | - $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
162 | - $onwikiUsername); |
|
163 | - |
|
164 | - $database = $this->getDatabase(); |
|
165 | - |
|
166 | - $user = new User(); |
|
167 | - $user->setDatabase($database); |
|
168 | - |
|
169 | - $user->setUsername($username); |
|
170 | - $user->setEmail($emailAddress); |
|
171 | - |
|
172 | - if (!$useOAuthSignup) { |
|
173 | - $user->setOnWikiName($onwikiUsername); |
|
174 | - $user->setConfirmationDiff($confirmationId); |
|
175 | - } |
|
176 | - |
|
177 | - $user->save(); |
|
178 | - |
|
179 | - $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
180 | - $passwordCredentialProvider->setCredential($user, 1, $password); |
|
181 | - |
|
182 | - $defaultRole = $this->getDefaultRole(); |
|
183 | - |
|
184 | - $role = new UserRole(); |
|
185 | - $role->setDatabase($database); |
|
186 | - $role->setUser($user->getId()); |
|
187 | - $role->setRole($defaultRole); |
|
188 | - $role->save(); |
|
189 | - |
|
190 | - // Log now to get the signup date. |
|
191 | - Logger::newUser($database, $user); |
|
192 | - Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
193 | - |
|
194 | - if ($useOAuthSignup) { |
|
195 | - $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
196 | - $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
197 | - |
|
198 | - $authoriseUrl = $oauth->getRequestToken(); |
|
199 | - WebRequest::setOAuthPartialLogin($user); |
|
200 | - $this->redirectUrl($authoriseUrl); |
|
201 | - } |
|
202 | - else { |
|
203 | - // only notify if we're not using the oauth signup. |
|
204 | - $this->getNotificationHelper()->userNew($user); |
|
205 | - WebRequest::setLoggedInUser($user); |
|
206 | - $this->redirect('preferences'); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - protected abstract function getDefaultRole(); |
|
211 | - |
|
212 | - /** |
|
213 | - * Entry point for registration complete |
|
214 | - */ |
|
215 | - protected function done() |
|
216 | - { |
|
217 | - $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
218 | - } |
|
23 | + /** |
|
24 | + * Main function for this page, when no specific actions are called. |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $useOAuthSignup = $this->getSiteConfiguration()->getUseOAuthSignup(); |
|
29 | + |
|
30 | + // Dual-mode page |
|
31 | + if (WebRequest::wasPosted()) { |
|
32 | + $this->validateCSRFToken(); |
|
33 | + |
|
34 | + try { |
|
35 | + $this->handlePost($useOAuthSignup); |
|
36 | + } |
|
37 | + catch (ApplicationLogicException $ex) { |
|
38 | + SessionAlert::error($ex->getMessage()); |
|
39 | + $this->redirect('register'); |
|
40 | + } |
|
41 | + } |
|
42 | + else { |
|
43 | + $this->assignCSRFToken(); |
|
44 | + $this->assign("useOAuthSignup", $useOAuthSignup); |
|
45 | + $this->setTemplate($this->getRegistrationTemplate()); |
|
46 | + } |
|
47 | + } |
|
48 | + |
|
49 | + protected abstract function getRegistrationTemplate(); |
|
50 | + |
|
51 | + protected function isProtectedPage() |
|
52 | + { |
|
53 | + return false; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $emailAddress |
|
58 | + * |
|
59 | + * @throws ApplicationLogicException |
|
60 | + */ |
|
61 | + protected function validateUniqueEmail($emailAddress) |
|
62 | + { |
|
63 | + $query = 'SELECT COUNT(id) FROM user WHERE email = :email'; |
|
64 | + $statement = $this->getDatabase()->prepare($query); |
|
65 | + $statement->execute(array(':email' => $emailAddress)); |
|
66 | + |
|
67 | + if ($statement->fetchColumn() > 0) { |
|
68 | + throw new ApplicationLogicException('That email address is already in use on this system.'); |
|
69 | + } |
|
70 | + |
|
71 | + $statement->closeCursor(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param $emailAddress |
|
76 | + * @param $password |
|
77 | + * @param $username |
|
78 | + * @param $useOAuthSignup |
|
79 | + * @param $confirmationId |
|
80 | + * @param $onwikiUsername |
|
81 | + * |
|
82 | + * @throws ApplicationLogicException |
|
83 | + */ |
|
84 | + protected function validateRequest( |
|
85 | + $emailAddress, |
|
86 | + $password, |
|
87 | + $username, |
|
88 | + $useOAuthSignup, |
|
89 | + $confirmationId, |
|
90 | + $onwikiUsername |
|
91 | + ) { |
|
92 | + if (!WebRequest::postBoolean('guidelines')) { |
|
93 | + throw new ApplicationLogicException('You must read the interface guidelines before your request may be submitted.'); |
|
94 | + } |
|
95 | + |
|
96 | + $this->validateGeneralInformation($emailAddress, $password, $username); |
|
97 | + $this->validateUniqueEmail($emailAddress); |
|
98 | + $this->validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param $useOAuthSignup |
|
103 | + * @param $confirmationId |
|
104 | + * @param $onwikiUsername |
|
105 | + * |
|
106 | + * @throws ApplicationLogicException |
|
107 | + */ |
|
108 | + protected function validateNonOAuthFields($useOAuthSignup, $confirmationId, $onwikiUsername) |
|
109 | + { |
|
110 | + if (!$useOAuthSignup) { |
|
111 | + if ($confirmationId === null || $confirmationId <= 0) { |
|
112 | + throw new ApplicationLogicException('Please enter the revision id of your confirmation edit.'); |
|
113 | + } |
|
114 | + |
|
115 | + if ($onwikiUsername === null) { |
|
116 | + throw new ApplicationLogicException('Please specify your on-wiki username.'); |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param $emailAddress |
|
123 | + * @param $password |
|
124 | + * @param $username |
|
125 | + * |
|
126 | + * @throws ApplicationLogicException |
|
127 | + */ |
|
128 | + protected function validateGeneralInformation($emailAddress, $password, $username) |
|
129 | + { |
|
130 | + if ($emailAddress === null) { |
|
131 | + throw new ApplicationLogicException('Your email address appears to be invalid!'); |
|
132 | + } |
|
133 | + |
|
134 | + if ($password !== WebRequest::postString('pass2')) { |
|
135 | + throw new ApplicationLogicException('Your passwords did not match, please try again.'); |
|
136 | + } |
|
137 | + |
|
138 | + if (User::getByUsername($username, $this->getDatabase()) !== false) { |
|
139 | + throw new ApplicationLogicException('That username is already in use on this system.'); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param $useOAuthSignup |
|
145 | + * |
|
146 | + * @throws ApplicationLogicException |
|
147 | + * @throws \Exception |
|
148 | + */ |
|
149 | + protected function handlePost($useOAuthSignup) |
|
150 | + { |
|
151 | + // Get the data |
|
152 | + $emailAddress = WebRequest::postEmail('email'); |
|
153 | + $password = WebRequest::postString('pass'); |
|
154 | + $username = WebRequest::postString('name'); |
|
155 | + |
|
156 | + // Only set if OAuth is disabled |
|
157 | + $confirmationId = WebRequest::postInt('conf_revid'); |
|
158 | + $onwikiUsername = WebRequest::postString('wname'); |
|
159 | + |
|
160 | + // Do some validation |
|
161 | + $this->validateRequest($emailAddress, $password, $username, $useOAuthSignup, $confirmationId, |
|
162 | + $onwikiUsername); |
|
163 | + |
|
164 | + $database = $this->getDatabase(); |
|
165 | + |
|
166 | + $user = new User(); |
|
167 | + $user->setDatabase($database); |
|
168 | + |
|
169 | + $user->setUsername($username); |
|
170 | + $user->setEmail($emailAddress); |
|
171 | + |
|
172 | + if (!$useOAuthSignup) { |
|
173 | + $user->setOnWikiName($onwikiUsername); |
|
174 | + $user->setConfirmationDiff($confirmationId); |
|
175 | + } |
|
176 | + |
|
177 | + $user->save(); |
|
178 | + |
|
179 | + $passwordCredentialProvider = new PasswordCredentialProvider($database, $this->getSiteConfiguration()); |
|
180 | + $passwordCredentialProvider->setCredential($user, 1, $password); |
|
181 | + |
|
182 | + $defaultRole = $this->getDefaultRole(); |
|
183 | + |
|
184 | + $role = new UserRole(); |
|
185 | + $role->setDatabase($database); |
|
186 | + $role->setUser($user->getId()); |
|
187 | + $role->setRole($defaultRole); |
|
188 | + $role->save(); |
|
189 | + |
|
190 | + // Log now to get the signup date. |
|
191 | + Logger::newUser($database, $user); |
|
192 | + Logger::userRolesEdited($database, $user, 'Registration', array($defaultRole), array()); |
|
193 | + |
|
194 | + if ($useOAuthSignup) { |
|
195 | + $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
196 | + $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
197 | + |
|
198 | + $authoriseUrl = $oauth->getRequestToken(); |
|
199 | + WebRequest::setOAuthPartialLogin($user); |
|
200 | + $this->redirectUrl($authoriseUrl); |
|
201 | + } |
|
202 | + else { |
|
203 | + // only notify if we're not using the oauth signup. |
|
204 | + $this->getNotificationHelper()->userNew($user); |
|
205 | + WebRequest::setLoggedInUser($user); |
|
206 | + $this->redirect('preferences'); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + protected abstract function getDefaultRole(); |
|
211 | + |
|
212 | + /** |
|
213 | + * Entry point for registration complete |
|
214 | + */ |
|
215 | + protected function done() |
|
216 | + { |
|
217 | + $this->setTemplate('registration/alert-registrationcomplete.tpl'); |
|
218 | + } |
|
219 | 219 | } |
@@ -15,137 +15,137 @@ |
||
15 | 15 | |
16 | 16 | abstract class CredentialProviderBase implements ICredentialProvider |
17 | 17 | { |
18 | - /** |
|
19 | - * @var PdoDatabase |
|
20 | - */ |
|
21 | - private $database; |
|
22 | - /** |
|
23 | - * @var SiteConfiguration |
|
24 | - */ |
|
25 | - private $configuration; |
|
26 | - /** @var string */ |
|
27 | - private $type; |
|
28 | - |
|
29 | - /** |
|
30 | - * CredentialProviderBase constructor. |
|
31 | - * |
|
32 | - * @param PdoDatabase $database |
|
33 | - * @param SiteConfiguration $configuration |
|
34 | - * @param string $type |
|
35 | - */ |
|
36 | - public function __construct(PdoDatabase $database, SiteConfiguration $configuration, $type) |
|
37 | - { |
|
38 | - $this->database = $database; |
|
39 | - $this->configuration = $configuration; |
|
40 | - $this->type = $type; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param int $userId |
|
45 | - * |
|
46 | - * @param bool $disabled |
|
47 | - * |
|
48 | - * @return Credential |
|
49 | - */ |
|
50 | - protected function getCredentialData($userId, $disabled = false) |
|
51 | - { |
|
52 | - $sql = 'SELECT * FROM credential WHERE type = :t AND user = :u'; |
|
53 | - $parameters = array( |
|
54 | - ':u' => $userId, |
|
55 | - ':t' => $this->type |
|
56 | - ); |
|
57 | - |
|
58 | - if($disabled !== null) { |
|
59 | - $sql .= ' AND disabled = :d'; |
|
60 | - $parameters[':d'] = $disabled ? 1 : 0; |
|
61 | - } |
|
62 | - |
|
63 | - $statement = $this->database->prepare($sql); |
|
64 | - $statement->execute($parameters); |
|
65 | - |
|
66 | - /** @var Credential $obj */ |
|
67 | - $obj = $statement->fetchObject(Credential::class); |
|
68 | - |
|
69 | - if ($obj === false) { |
|
70 | - return null; |
|
71 | - } |
|
72 | - |
|
73 | - $obj->setDatabase($this->database); |
|
74 | - |
|
75 | - $statement->closeCursor(); |
|
76 | - |
|
77 | - return $obj; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @return PdoDatabase |
|
82 | - */ |
|
83 | - public function getDatabase() |
|
84 | - { |
|
85 | - return $this->database; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return SiteConfiguration |
|
90 | - */ |
|
91 | - public function getConfiguration() |
|
92 | - { |
|
93 | - return $this->configuration; |
|
94 | - } |
|
95 | - |
|
96 | - public function deleteCredential(User $user) { |
|
97 | - // get this factor |
|
98 | - $statement = $this->database->prepare('SELECT * FROM credential WHERE user = :user AND type = :type'); |
|
99 | - $statement->execute(array(':user' => $user->getId(), ':type' => $this->type)); |
|
100 | - /** @var Credential $credential */ |
|
101 | - $credential = $statement->fetchObject(Credential::class); |
|
102 | - $credential->setDatabase($this->database); |
|
103 | - $statement->closeCursor(); |
|
104 | - |
|
105 | - $stage = $credential->getFactor(); |
|
106 | - |
|
107 | - $statement = $this->database->prepare('SELECT COUNT(*) FROM credential WHERE user = :user AND factor = :factor'); |
|
108 | - $statement->execute(array(':user' => $user->getId(), ':factor' => $stage)); |
|
109 | - $alternates = $statement->fetchColumn(); |
|
110 | - $statement->closeCursor(); |
|
111 | - |
|
112 | - if($alternates <= 1) { |
|
113 | - // decrement the factor for every stage above this |
|
114 | - $sql = 'UPDATE credential SET factor = factor - 1 WHERE user = :user AND factor > :factor'; |
|
115 | - $statement = $this->database->prepare($sql); |
|
116 | - $statement->execute(array(':user' => $user->getId(), ':factor' => $stage)); |
|
117 | - } |
|
118 | - else { |
|
119 | - // There are other auth factors at this point. Don't renumber the factors just yet. |
|
120 | - } |
|
121 | - |
|
122 | - // delete this credential. |
|
123 | - $credential->delete(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param User $user |
|
128 | - * |
|
129 | - * @return Credential |
|
130 | - */ |
|
131 | - protected function createNewCredential(User $user) |
|
132 | - { |
|
133 | - $credential = new Credential(); |
|
134 | - $credential->setDatabase($this->getDatabase()); |
|
135 | - $credential->setUserId($user->getId()); |
|
136 | - $credential->setType($this->type); |
|
137 | - |
|
138 | - return $credential; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @param int $userId |
|
143 | - * |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - public function userIsEnrolled($userId) { |
|
147 | - $cred = $this->getCredentialData($userId); |
|
148 | - |
|
149 | - return $cred !== null; |
|
150 | - } |
|
18 | + /** |
|
19 | + * @var PdoDatabase |
|
20 | + */ |
|
21 | + private $database; |
|
22 | + /** |
|
23 | + * @var SiteConfiguration |
|
24 | + */ |
|
25 | + private $configuration; |
|
26 | + /** @var string */ |
|
27 | + private $type; |
|
28 | + |
|
29 | + /** |
|
30 | + * CredentialProviderBase constructor. |
|
31 | + * |
|
32 | + * @param PdoDatabase $database |
|
33 | + * @param SiteConfiguration $configuration |
|
34 | + * @param string $type |
|
35 | + */ |
|
36 | + public function __construct(PdoDatabase $database, SiteConfiguration $configuration, $type) |
|
37 | + { |
|
38 | + $this->database = $database; |
|
39 | + $this->configuration = $configuration; |
|
40 | + $this->type = $type; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param int $userId |
|
45 | + * |
|
46 | + * @param bool $disabled |
|
47 | + * |
|
48 | + * @return Credential |
|
49 | + */ |
|
50 | + protected function getCredentialData($userId, $disabled = false) |
|
51 | + { |
|
52 | + $sql = 'SELECT * FROM credential WHERE type = :t AND user = :u'; |
|
53 | + $parameters = array( |
|
54 | + ':u' => $userId, |
|
55 | + ':t' => $this->type |
|
56 | + ); |
|
57 | + |
|
58 | + if($disabled !== null) { |
|
59 | + $sql .= ' AND disabled = :d'; |
|
60 | + $parameters[':d'] = $disabled ? 1 : 0; |
|
61 | + } |
|
62 | + |
|
63 | + $statement = $this->database->prepare($sql); |
|
64 | + $statement->execute($parameters); |
|
65 | + |
|
66 | + /** @var Credential $obj */ |
|
67 | + $obj = $statement->fetchObject(Credential::class); |
|
68 | + |
|
69 | + if ($obj === false) { |
|
70 | + return null; |
|
71 | + } |
|
72 | + |
|
73 | + $obj->setDatabase($this->database); |
|
74 | + |
|
75 | + $statement->closeCursor(); |
|
76 | + |
|
77 | + return $obj; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @return PdoDatabase |
|
82 | + */ |
|
83 | + public function getDatabase() |
|
84 | + { |
|
85 | + return $this->database; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return SiteConfiguration |
|
90 | + */ |
|
91 | + public function getConfiguration() |
|
92 | + { |
|
93 | + return $this->configuration; |
|
94 | + } |
|
95 | + |
|
96 | + public function deleteCredential(User $user) { |
|
97 | + // get this factor |
|
98 | + $statement = $this->database->prepare('SELECT * FROM credential WHERE user = :user AND type = :type'); |
|
99 | + $statement->execute(array(':user' => $user->getId(), ':type' => $this->type)); |
|
100 | + /** @var Credential $credential */ |
|
101 | + $credential = $statement->fetchObject(Credential::class); |
|
102 | + $credential->setDatabase($this->database); |
|
103 | + $statement->closeCursor(); |
|
104 | + |
|
105 | + $stage = $credential->getFactor(); |
|
106 | + |
|
107 | + $statement = $this->database->prepare('SELECT COUNT(*) FROM credential WHERE user = :user AND factor = :factor'); |
|
108 | + $statement->execute(array(':user' => $user->getId(), ':factor' => $stage)); |
|
109 | + $alternates = $statement->fetchColumn(); |
|
110 | + $statement->closeCursor(); |
|
111 | + |
|
112 | + if($alternates <= 1) { |
|
113 | + // decrement the factor for every stage above this |
|
114 | + $sql = 'UPDATE credential SET factor = factor - 1 WHERE user = :user AND factor > :factor'; |
|
115 | + $statement = $this->database->prepare($sql); |
|
116 | + $statement->execute(array(':user' => $user->getId(), ':factor' => $stage)); |
|
117 | + } |
|
118 | + else { |
|
119 | + // There are other auth factors at this point. Don't renumber the factors just yet. |
|
120 | + } |
|
121 | + |
|
122 | + // delete this credential. |
|
123 | + $credential->delete(); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param User $user |
|
128 | + * |
|
129 | + * @return Credential |
|
130 | + */ |
|
131 | + protected function createNewCredential(User $user) |
|
132 | + { |
|
133 | + $credential = new Credential(); |
|
134 | + $credential->setDatabase($this->getDatabase()); |
|
135 | + $credential->setUserId($user->getId()); |
|
136 | + $credential->setType($this->type); |
|
137 | + |
|
138 | + return $credential; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @param int $userId |
|
143 | + * |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + public function userIsEnrolled($userId) { |
|
147 | + $cred = $this->getCredentialData($userId); |
|
148 | + |
|
149 | + return $cred !== null; |
|
150 | + } |
|
151 | 151 | } |
152 | 152 | \ No newline at end of file |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | ':t' => $this->type |
56 | 56 | ); |
57 | 57 | |
58 | - if($disabled !== null) { |
|
58 | + if ($disabled !== null) { |
|
59 | 59 | $sql .= ' AND disabled = :d'; |
60 | 60 | $parameters[':d'] = $disabled ? 1 : 0; |
61 | 61 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $alternates = $statement->fetchColumn(); |
110 | 110 | $statement->closeCursor(); |
111 | 111 | |
112 | - if($alternates <= 1) { |
|
112 | + if ($alternates <= 1) { |
|
113 | 113 | // decrement the factor for every stage above this |
114 | 114 | $sql = 'UPDATE credential SET factor = factor - 1 WHERE user = :user AND factor > :factor'; |
115 | 115 | $statement = $this->database->prepare($sql); |
@@ -93,7 +93,8 @@ discard block |
||
93 | 93 | return $this->configuration; |
94 | 94 | } |
95 | 95 | |
96 | - public function deleteCredential(User $user) { |
|
96 | + public function deleteCredential(User $user) |
|
97 | + { |
|
97 | 98 | // get this factor |
98 | 99 | $statement = $this->database->prepare('SELECT * FROM credential WHERE user = :user AND type = :type'); |
99 | 100 | $statement->execute(array(':user' => $user->getId(), ':type' => $this->type)); |
@@ -143,7 +144,8 @@ discard block |
||
143 | 144 | * |
144 | 145 | * @return bool |
145 | 146 | */ |
146 | - public function userIsEnrolled($userId) { |
|
147 | + public function userIsEnrolled($userId) |
|
148 | + { |
|
147 | 149 | $cred = $this->getCredentialData($userId); |
148 | 150 | |
149 | 151 | return $cred !== null; |
@@ -17,121 +17,121 @@ |
||
17 | 17 | |
18 | 18 | class ScratchTokenCredentialProvider extends CredentialProviderBase |
19 | 19 | { |
20 | - /** @var EncryptionHelper */ |
|
21 | - private $encryptionHelper; |
|
22 | - |
|
23 | - /** |
|
24 | - * ScratchTokenCredentialProvider constructor. |
|
25 | - * |
|
26 | - * @param PdoDatabase $database |
|
27 | - * @param SiteConfiguration $configuration |
|
28 | - */ |
|
29 | - public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
30 | - { |
|
31 | - parent::__construct($database, $configuration, 'scratch'); |
|
32 | - $this->encryptionHelper = new EncryptionHelper($configuration); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Validates a user-provided credential |
|
37 | - * |
|
38 | - * @param User $user The user to test the authentication against |
|
39 | - * @param string $data The raw credential data to be validated |
|
40 | - * |
|
41 | - * @return bool |
|
42 | - * @throws ApplicationLogicException |
|
43 | - */ |
|
44 | - public function authenticate(User $user, $data) |
|
45 | - { |
|
46 | - if (is_array($data)) { |
|
47 | - return false; |
|
48 | - } |
|
49 | - |
|
50 | - $storedData = $this->getCredentialData($user->getId()); |
|
51 | - |
|
52 | - if ($storedData === null) { |
|
53 | - throw new ApplicationLogicException('Credential data not found'); |
|
54 | - } |
|
55 | - |
|
56 | - $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
57 | - |
|
58 | - $i = array_search($data, $scratchTokens); |
|
59 | - |
|
60 | - if($i === false) { |
|
61 | - return false; |
|
62 | - } |
|
63 | - |
|
64 | - unset($scratchTokens[$i]); |
|
65 | - |
|
66 | - $storedData->setData($this->encryptionHelper->encryptData(serialize($scratchTokens))); |
|
67 | - $storedData->save(); |
|
68 | - |
|
69 | - return true; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param User $user The user the credential belongs to |
|
74 | - * @param int $factor The factor this credential provides |
|
75 | - * @param string $data Unused. |
|
76 | - */ |
|
77 | - public function setCredential(User $user, $factor, $data) |
|
78 | - { |
|
79 | - $scratch = array(); |
|
80 | - for ($i = 0; $i < 5; $i++) { |
|
81 | - $scratch[] = Base32::encode(openssl_random_pseudo_bytes(10)); |
|
82 | - } |
|
83 | - |
|
84 | - $storedData = $this->getCredentialData($user->getId(), null); |
|
85 | - |
|
86 | - if ($storedData !== null) { |
|
87 | - $storedData->delete(); |
|
88 | - } |
|
89 | - |
|
90 | - $storedData = $this->createNewCredential($user); |
|
91 | - |
|
92 | - $storedData->setData($this->encryptionHelper->encryptData(serialize($scratch))); |
|
93 | - $storedData->setFactor($factor); |
|
94 | - $storedData->setVersion(1); |
|
95 | - $storedData->setPriority(9); |
|
96 | - |
|
97 | - $storedData->save(); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param int $userId |
|
102 | - * |
|
103 | - * @return int |
|
104 | - * @throws ApplicationLogicException |
|
105 | - */ |
|
106 | - public function getRemaining($userId) |
|
107 | - { |
|
108 | - $storedData = $this->getCredentialData($userId); |
|
109 | - |
|
110 | - if ($storedData === null) { |
|
111 | - return 0; |
|
112 | - } |
|
113 | - |
|
114 | - $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
115 | - |
|
116 | - return count($scratchTokens); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param int $userId |
|
121 | - * |
|
122 | - * @return int |
|
123 | - * @throws ApplicationLogicException |
|
124 | - */ |
|
125 | - public function getTokens($userId) |
|
126 | - { |
|
127 | - $storedData = $this->getCredentialData($userId); |
|
128 | - |
|
129 | - if ($storedData === null) { |
|
130 | - return 0; |
|
131 | - } |
|
132 | - |
|
133 | - $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
134 | - |
|
135 | - return $scratchTokens; |
|
136 | - } |
|
20 | + /** @var EncryptionHelper */ |
|
21 | + private $encryptionHelper; |
|
22 | + |
|
23 | + /** |
|
24 | + * ScratchTokenCredentialProvider constructor. |
|
25 | + * |
|
26 | + * @param PdoDatabase $database |
|
27 | + * @param SiteConfiguration $configuration |
|
28 | + */ |
|
29 | + public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
30 | + { |
|
31 | + parent::__construct($database, $configuration, 'scratch'); |
|
32 | + $this->encryptionHelper = new EncryptionHelper($configuration); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Validates a user-provided credential |
|
37 | + * |
|
38 | + * @param User $user The user to test the authentication against |
|
39 | + * @param string $data The raw credential data to be validated |
|
40 | + * |
|
41 | + * @return bool |
|
42 | + * @throws ApplicationLogicException |
|
43 | + */ |
|
44 | + public function authenticate(User $user, $data) |
|
45 | + { |
|
46 | + if (is_array($data)) { |
|
47 | + return false; |
|
48 | + } |
|
49 | + |
|
50 | + $storedData = $this->getCredentialData($user->getId()); |
|
51 | + |
|
52 | + if ($storedData === null) { |
|
53 | + throw new ApplicationLogicException('Credential data not found'); |
|
54 | + } |
|
55 | + |
|
56 | + $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
57 | + |
|
58 | + $i = array_search($data, $scratchTokens); |
|
59 | + |
|
60 | + if($i === false) { |
|
61 | + return false; |
|
62 | + } |
|
63 | + |
|
64 | + unset($scratchTokens[$i]); |
|
65 | + |
|
66 | + $storedData->setData($this->encryptionHelper->encryptData(serialize($scratchTokens))); |
|
67 | + $storedData->save(); |
|
68 | + |
|
69 | + return true; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param User $user The user the credential belongs to |
|
74 | + * @param int $factor The factor this credential provides |
|
75 | + * @param string $data Unused. |
|
76 | + */ |
|
77 | + public function setCredential(User $user, $factor, $data) |
|
78 | + { |
|
79 | + $scratch = array(); |
|
80 | + for ($i = 0; $i < 5; $i++) { |
|
81 | + $scratch[] = Base32::encode(openssl_random_pseudo_bytes(10)); |
|
82 | + } |
|
83 | + |
|
84 | + $storedData = $this->getCredentialData($user->getId(), null); |
|
85 | + |
|
86 | + if ($storedData !== null) { |
|
87 | + $storedData->delete(); |
|
88 | + } |
|
89 | + |
|
90 | + $storedData = $this->createNewCredential($user); |
|
91 | + |
|
92 | + $storedData->setData($this->encryptionHelper->encryptData(serialize($scratch))); |
|
93 | + $storedData->setFactor($factor); |
|
94 | + $storedData->setVersion(1); |
|
95 | + $storedData->setPriority(9); |
|
96 | + |
|
97 | + $storedData->save(); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param int $userId |
|
102 | + * |
|
103 | + * @return int |
|
104 | + * @throws ApplicationLogicException |
|
105 | + */ |
|
106 | + public function getRemaining($userId) |
|
107 | + { |
|
108 | + $storedData = $this->getCredentialData($userId); |
|
109 | + |
|
110 | + if ($storedData === null) { |
|
111 | + return 0; |
|
112 | + } |
|
113 | + |
|
114 | + $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
115 | + |
|
116 | + return count($scratchTokens); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param int $userId |
|
121 | + * |
|
122 | + * @return int |
|
123 | + * @throws ApplicationLogicException |
|
124 | + */ |
|
125 | + public function getTokens($userId) |
|
126 | + { |
|
127 | + $storedData = $this->getCredentialData($userId); |
|
128 | + |
|
129 | + if ($storedData === null) { |
|
130 | + return 0; |
|
131 | + } |
|
132 | + |
|
133 | + $scratchTokens = unserialize($this->encryptionHelper->decryptData($storedData->getData())); |
|
134 | + |
|
135 | + return $scratchTokens; |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | \ No newline at end of file |
@@ -57,7 +57,7 @@ |
||
57 | 57 | |
58 | 58 | $i = array_search($data, $scratchTokens); |
59 | 59 | |
60 | - if($i === false) { |
|
60 | + if ($i === false) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 |
@@ -15,55 +15,55 @@ |
||
15 | 15 | |
16 | 16 | class PasswordCredentialProvider extends CredentialProviderBase |
17 | 17 | { |
18 | - const PASSWORD_COST = 10; |
|
18 | + const PASSWORD_COST = 10; |
|
19 | 19 | |
20 | - public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
21 | - { |
|
22 | - parent::__construct($database, $configuration, 'password'); |
|
23 | - } |
|
20 | + public function __construct(PdoDatabase $database, SiteConfiguration $configuration) |
|
21 | + { |
|
22 | + parent::__construct($database, $configuration, 'password'); |
|
23 | + } |
|
24 | 24 | |
25 | - public function authenticate(User $user, $data) |
|
26 | - { |
|
27 | - $storedData = $this->getCredentialData($user->getId()); |
|
28 | - if($storedData === null) |
|
29 | - { |
|
30 | - // No available credential matching these parameters |
|
31 | - return false; |
|
32 | - } |
|
25 | + public function authenticate(User $user, $data) |
|
26 | + { |
|
27 | + $storedData = $this->getCredentialData($user->getId()); |
|
28 | + if($storedData === null) |
|
29 | + { |
|
30 | + // No available credential matching these parameters |
|
31 | + return false; |
|
32 | + } |
|
33 | 33 | |
34 | - if($storedData->getVersion() !== 2) { |
|
35 | - // Non-2 versions are not supported. |
|
36 | - return false; |
|
37 | - } |
|
34 | + if($storedData->getVersion() !== 2) { |
|
35 | + // Non-2 versions are not supported. |
|
36 | + return false; |
|
37 | + } |
|
38 | 38 | |
39 | - if(password_verify($data, $storedData->getData())) { |
|
40 | - if(password_needs_rehash($storedData->getData(), PASSWORD_BCRYPT, array('cost' => self::PASSWORD_COST))){ |
|
41 | - $this->setCredential($user, $storedData->getFactor(), $data); |
|
42 | - } |
|
39 | + if(password_verify($data, $storedData->getData())) { |
|
40 | + if(password_needs_rehash($storedData->getData(), PASSWORD_BCRYPT, array('cost' => self::PASSWORD_COST))){ |
|
41 | + $this->setCredential($user, $storedData->getFactor(), $data); |
|
42 | + } |
|
43 | 43 | |
44 | - return true; |
|
45 | - } |
|
44 | + return true; |
|
45 | + } |
|
46 | 46 | |
47 | - return false; |
|
48 | - } |
|
47 | + return false; |
|
48 | + } |
|
49 | 49 | |
50 | - public function setCredential(User $user, $factor, $password) |
|
51 | - { |
|
52 | - $storedData = $this->getCredentialData($user->getId()); |
|
50 | + public function setCredential(User $user, $factor, $password) |
|
51 | + { |
|
52 | + $storedData = $this->getCredentialData($user->getId()); |
|
53 | 53 | |
54 | - if($storedData === null){ |
|
55 | - $storedData = $this->createNewCredential($user); |
|
56 | - } |
|
54 | + if($storedData === null){ |
|
55 | + $storedData = $this->createNewCredential($user); |
|
56 | + } |
|
57 | 57 | |
58 | - $storedData->setData(password_hash($password, PASSWORD_BCRYPT, array('cost' => self::PASSWORD_COST))); |
|
59 | - $storedData->setFactor($factor); |
|
60 | - $storedData->setVersion(2); |
|
58 | + $storedData->setData(password_hash($password, PASSWORD_BCRYPT, array('cost' => self::PASSWORD_COST))); |
|
59 | + $storedData->setFactor($factor); |
|
60 | + $storedData->setVersion(2); |
|
61 | 61 | |
62 | - $storedData->save(); |
|
63 | - } |
|
62 | + $storedData->save(); |
|
63 | + } |
|
64 | 64 | |
65 | - public function deleteCredential(User $user) |
|
66 | - { |
|
67 | - throw new ApplicationLogicException('Deletion of password credential is not allowed.'); |
|
68 | - } |
|
65 | + public function deleteCredential(User $user) |
|
66 | + { |
|
67 | + throw new ApplicationLogicException('Deletion of password credential is not allowed.'); |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | \ No newline at end of file |