@@ -200,24 +200,24 @@ discard block |
||
200 | 200 | |
201 | 201 | // request states |
202 | 202 | $availableRequestStates = array( |
203 | - 'Open' => array( |
|
204 | - 'defertolog' => 'users', // don't change or you'll break old logs |
|
205 | - 'deferto' => 'users', |
|
206 | - 'header' => 'Open requests', |
|
207 | - 'api' => "open", |
|
208 | - ), |
|
209 | - 'Flagged users' => array( |
|
210 | - 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
211 | - 'deferto' => 'flagged users', |
|
212 | - 'header' => 'Flagged user needed', |
|
213 | - 'api' => "admin", |
|
214 | - ), |
|
215 | - 'Checkuser' => array( |
|
216 | - 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
217 | - 'deferto' => 'checkusers', |
|
218 | - 'header' => 'Checkuser needed', |
|
219 | - 'api' => "checkuser", |
|
220 | - ), |
|
203 | + 'Open' => array( |
|
204 | + 'defertolog' => 'users', // don't change or you'll break old logs |
|
205 | + 'deferto' => 'users', |
|
206 | + 'header' => 'Open requests', |
|
207 | + 'api' => "open", |
|
208 | + ), |
|
209 | + 'Flagged users' => array( |
|
210 | + 'defertolog' => 'flagged users', // don't change or you'll break old logs |
|
211 | + 'deferto' => 'flagged users', |
|
212 | + 'header' => 'Flagged user needed', |
|
213 | + 'api' => "admin", |
|
214 | + ), |
|
215 | + 'Checkuser' => array( |
|
216 | + 'defertolog' => 'checkusers', // don't change or you'll break old logs |
|
217 | + 'deferto' => 'checkusers', |
|
218 | + 'header' => 'Checkuser needed', |
|
219 | + 'api' => "checkuser", |
|
220 | + ), |
|
221 | 221 | ); |
222 | 222 | |
223 | 223 | $defaultRequestStateKey = 'Open'; |
@@ -264,21 +264,21 @@ discard block |
||
264 | 264 | require_once('config.local.inc.php'); |
265 | 265 | |
266 | 266 | $cDatabaseConfig = array( |
267 | - "acc" => array( |
|
268 | - "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
269 | - "username" => $toolserver_username, |
|
270 | - "password" => $toolserver_password, |
|
271 | - ), |
|
272 | - "wikipedia" => array( |
|
273 | - "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
274 | - "username" => $toolserver_username, |
|
275 | - "password" => $toolserver_password, |
|
276 | - ), |
|
277 | - "notifications" => array( |
|
278 | - "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
279 | - "username" => $notifications_username, |
|
280 | - "password" => $notifications_password, |
|
281 | - ), |
|
267 | + "acc" => array( |
|
268 | + "dsrcname" => "mysql:host=" . $toolserver_host . ";dbname=" . $toolserver_database, |
|
269 | + "username" => $toolserver_username, |
|
270 | + "password" => $toolserver_password, |
|
271 | + ), |
|
272 | + "wikipedia" => array( |
|
273 | + "dsrcname" => "mysql:host=" . $antispoof_host . ";dbname=" . $antispoof_db, |
|
274 | + "username" => $toolserver_username, |
|
275 | + "password" => $toolserver_password, |
|
276 | + ), |
|
277 | + "notifications" => array( |
|
278 | + "dsrcname" => "mysql:host=" . $toolserver_notification_dbhost . ";dbname=" . $toolserver_notification_database, |
|
279 | + "username" => $notifications_username, |
|
280 | + "password" => $notifications_password, |
|
281 | + ), |
|
282 | 282 | ); |
283 | 283 | |
284 | 284 | // //Keep the included files from being executed. |
@@ -290,18 +290,18 @@ discard block |
||
290 | 290 | ini_set('user_agent', $toolUserAgent); |
291 | 291 | |
292 | 292 | foreach (array( |
293 | - "mbstring", // unicode and stuff |
|
294 | - "pdo", |
|
295 | - "pdo_mysql", // new database module |
|
296 | - "session", |
|
297 | - "date", |
|
298 | - "pcre", // core stuff |
|
299 | - "curl", // mediawiki api access etc |
|
300 | - "openssl", // token generation |
|
293 | + "mbstring", // unicode and stuff |
|
294 | + "pdo", |
|
295 | + "pdo_mysql", // new database module |
|
296 | + "session", |
|
297 | + "date", |
|
298 | + "pcre", // core stuff |
|
299 | + "curl", // mediawiki api access etc |
|
300 | + "openssl", // token generation |
|
301 | 301 | ) as $x) { |
302 | - if (!extension_loaded($x)) { |
|
303 | - die("extension $x is required."); |
|
304 | - } |
|
302 | + if (!extension_loaded($x)) { |
|
303 | + die("extension $x is required."); |
|
304 | + } |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Set up the AutoLoader |
@@ -328,39 +328,39 @@ discard block |
||
328 | 328 | $siteConfiguration = new \Waca\SiteConfiguration(); |
329 | 329 | |
330 | 330 | $siteConfiguration->setBaseUrl($baseurl) |
331 | - ->setFilePath(__DIR__) |
|
332 | - ->setDebuggingTraceEnabled($enableErrorTrace) |
|
333 | - ->setForceIdentification($forceIdentification) |
|
334 | - ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
335 | - ->setMediawikiScriptPath($mediawikiScriptPath) |
|
336 | - ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
337 | - ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
338 | - ->setEnforceOAuth($enforceOAuth) |
|
339 | - ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
340 | - ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
341 | - ->setMiserModeLimit($requestLimitShowOnly) |
|
342 | - ->setRequestStates($availableRequestStates) |
|
343 | - ->setSquidList($squidIpList) |
|
344 | - ->setDefaultCreatedTemplateId($createdid) |
|
345 | - ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
346 | - ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
347 | - ->setUserAgent($toolUserAgent) |
|
348 | - ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
349 | - ->setUseOAuthSignup($useOauthSignup) |
|
350 | - ->setOAuthBaseUrl($oauthBaseUrl) |
|
351 | - ->setOAuthConsumerToken($oauthConsumerToken) |
|
352 | - ->setOAuthConsumerSecret($oauthSecretToken) |
|
353 | - ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
354 | - ->setDataClearInterval($dataclear_interval) |
|
355 | - ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
356 | - ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
357 | - ->setIrcNotificationType($ircBotNotificationType) |
|
358 | - ->setIrcNotificationsInstance($whichami) |
|
359 | - ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
360 | - ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
361 | - ->setCreationBotUsername($creationBotUsername) |
|
362 | - ->setCreationBotPassword($creationBotPassword) |
|
363 | - ->setCurlCookieJar($curlCookieJar) |
|
364 | - ->setYubicoApiId($yubicoApiId) |
|
365 | - ->setYubicoApiKey($yubicoApiKey) |
|
366 | - ->setTotpEncryptionKey($totpEncryptionKey); |
|
331 | + ->setFilePath(__DIR__) |
|
332 | + ->setDebuggingTraceEnabled($enableErrorTrace) |
|
333 | + ->setForceIdentification($forceIdentification) |
|
334 | + ->setIdentificationCacheExpiry($identificationCacheExpiry) |
|
335 | + ->setMediawikiScriptPath($mediawikiScriptPath) |
|
336 | + ->setMediawikiWebServiceEndpoint($mediawikiWebServiceEndpoint) |
|
337 | + ->setMetaWikimediaWebServiceEndpoint($metaWikimediaWebServiceEndpoint) |
|
338 | + ->setEnforceOAuth($enforceOAuth) |
|
339 | + ->setEmailConfirmationEnabled($enableEmailConfirm == 1) |
|
340 | + ->setEmailConfirmationExpiryDays($emailConfirmationExpiryDays) |
|
341 | + ->setMiserModeLimit($requestLimitShowOnly) |
|
342 | + ->setRequestStates($availableRequestStates) |
|
343 | + ->setSquidList($squidIpList) |
|
344 | + ->setDefaultCreatedTemplateId($createdid) |
|
345 | + ->setDefaultRequestStateKey($defaultRequestStateKey) |
|
346 | + ->setUseStrictTransportSecurity($strictTransportSecurityExpiry) |
|
347 | + ->setUserAgent($toolUserAgent) |
|
348 | + ->setCurlDisableVerifyPeer($curlDisableSSLVerifyPeer) |
|
349 | + ->setUseOAuthSignup($useOauthSignup) |
|
350 | + ->setOAuthBaseUrl($oauthBaseUrl) |
|
351 | + ->setOAuthConsumerToken($oauthConsumerToken) |
|
352 | + ->setOAuthConsumerSecret($oauthSecretToken) |
|
353 | + ->setOauthMediaWikiCanonicalServer($oauthMediaWikiCanonicalServer) |
|
354 | + ->setDataClearInterval($dataclear_interval) |
|
355 | + ->setXffTrustedHostsFile($xff_trusted_hosts_file) |
|
356 | + ->setIrcNotificationsEnabled($ircBotNotificationsEnabled == 1) |
|
357 | + ->setIrcNotificationType($ircBotNotificationType) |
|
358 | + ->setIrcNotificationsInstance($whichami) |
|
359 | + ->setTitleBlacklistEnabled($enableTitleblacklist == 1) |
|
360 | + ->setTorExitPaths(array_merge(gethostbynamel('en.wikipedia.org'), gethostbynamel('accounts.wmflabs.org'))) |
|
361 | + ->setCreationBotUsername($creationBotUsername) |
|
362 | + ->setCreationBotPassword($creationBotPassword) |
|
363 | + ->setCurlCookieJar($curlCookieJar) |
|
364 | + ->setYubicoApiId($yubicoApiId) |
|
365 | + ->setYubicoApiKey($yubicoApiKey) |
|
366 | + ->setTotpEncryptionKey($totpEncryptionKey); |
@@ -15,187 +15,187 @@ discard block |
||
15 | 15 | |
16 | 16 | class Credential extends DataObject |
17 | 17 | { |
18 | - /** @var int */ |
|
19 | - private $user; |
|
20 | - /** @var int */ |
|
21 | - private $factor; |
|
22 | - /** @var string */ |
|
23 | - private $type; |
|
24 | - /** @var string */ |
|
25 | - private $data; |
|
26 | - /** @var int */ |
|
27 | - private $version; |
|
28 | - private $timeout; |
|
29 | - /** @var int */ |
|
30 | - private $disabled = 0; |
|
31 | - /** @var int */ |
|
32 | - private $priority; |
|
33 | - |
|
34 | - /** |
|
35 | - * @return int |
|
36 | - */ |
|
37 | - public function getUserId() |
|
38 | - { |
|
39 | - return $this->user; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param int $user |
|
44 | - */ |
|
45 | - public function setUserId($user) |
|
46 | - { |
|
47 | - $this->user = $user; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @return int |
|
52 | - */ |
|
53 | - public function getFactor() |
|
54 | - { |
|
55 | - return $this->factor; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param int $factor |
|
60 | - */ |
|
61 | - public function setFactor($factor) |
|
62 | - { |
|
63 | - $this->factor = $factor; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function getType() |
|
70 | - { |
|
71 | - return $this->type; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param string $type |
|
76 | - */ |
|
77 | - public function setType($type) |
|
78 | - { |
|
79 | - $this->type = $type; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function getData() |
|
86 | - { |
|
87 | - return $this->data; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string $data |
|
92 | - */ |
|
93 | - public function setData($data) |
|
94 | - { |
|
95 | - $this->data = $data; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @return int |
|
100 | - */ |
|
101 | - public function getVersion() |
|
102 | - { |
|
103 | - return $this->version; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param int $version |
|
108 | - */ |
|
109 | - public function setVersion($version) |
|
110 | - { |
|
111 | - $this->version = $version; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @return mixed |
|
116 | - */ |
|
117 | - public function getTimeout() |
|
118 | - { |
|
119 | - if ($this->timeout === null) { |
|
120 | - return null; |
|
121 | - } |
|
122 | - |
|
123 | - return new DateTimeImmutable($this->timeout); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param mixed $timeout |
|
128 | - */ |
|
129 | - public function setTimeout(DateTimeImmutable $timeout = null) |
|
130 | - { |
|
131 | - if ($timeout === null) { |
|
132 | - $this->timeout = null; |
|
133 | - } |
|
134 | - else { |
|
135 | - $this->timeout = $timeout->format('Y-m-d H:i:s'); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return int |
|
141 | - */ |
|
142 | - public function getDisabled() |
|
143 | - { |
|
144 | - return $this->disabled; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param int $disabled |
|
149 | - */ |
|
150 | - public function setDisabled($disabled) |
|
151 | - { |
|
152 | - $this->disabled = $disabled; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @return int |
|
157 | - */ |
|
158 | - public function getPriority() |
|
159 | - { |
|
160 | - return $this->priority; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param int $priority |
|
165 | - */ |
|
166 | - public function setPriority($priority) |
|
167 | - { |
|
168 | - $this->priority = $priority; |
|
169 | - } |
|
170 | - |
|
171 | - public function save() |
|
172 | - { |
|
173 | - if ($this->isNew()) { |
|
174 | - // insert |
|
175 | - $statement = $this->dbObject->prepare(<<<SQL |
|
18 | + /** @var int */ |
|
19 | + private $user; |
|
20 | + /** @var int */ |
|
21 | + private $factor; |
|
22 | + /** @var string */ |
|
23 | + private $type; |
|
24 | + /** @var string */ |
|
25 | + private $data; |
|
26 | + /** @var int */ |
|
27 | + private $version; |
|
28 | + private $timeout; |
|
29 | + /** @var int */ |
|
30 | + private $disabled = 0; |
|
31 | + /** @var int */ |
|
32 | + private $priority; |
|
33 | + |
|
34 | + /** |
|
35 | + * @return int |
|
36 | + */ |
|
37 | + public function getUserId() |
|
38 | + { |
|
39 | + return $this->user; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param int $user |
|
44 | + */ |
|
45 | + public function setUserId($user) |
|
46 | + { |
|
47 | + $this->user = $user; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @return int |
|
52 | + */ |
|
53 | + public function getFactor() |
|
54 | + { |
|
55 | + return $this->factor; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param int $factor |
|
60 | + */ |
|
61 | + public function setFactor($factor) |
|
62 | + { |
|
63 | + $this->factor = $factor; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function getType() |
|
70 | + { |
|
71 | + return $this->type; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param string $type |
|
76 | + */ |
|
77 | + public function setType($type) |
|
78 | + { |
|
79 | + $this->type = $type; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function getData() |
|
86 | + { |
|
87 | + return $this->data; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string $data |
|
92 | + */ |
|
93 | + public function setData($data) |
|
94 | + { |
|
95 | + $this->data = $data; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @return int |
|
100 | + */ |
|
101 | + public function getVersion() |
|
102 | + { |
|
103 | + return $this->version; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param int $version |
|
108 | + */ |
|
109 | + public function setVersion($version) |
|
110 | + { |
|
111 | + $this->version = $version; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @return mixed |
|
116 | + */ |
|
117 | + public function getTimeout() |
|
118 | + { |
|
119 | + if ($this->timeout === null) { |
|
120 | + return null; |
|
121 | + } |
|
122 | + |
|
123 | + return new DateTimeImmutable($this->timeout); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param mixed $timeout |
|
128 | + */ |
|
129 | + public function setTimeout(DateTimeImmutable $timeout = null) |
|
130 | + { |
|
131 | + if ($timeout === null) { |
|
132 | + $this->timeout = null; |
|
133 | + } |
|
134 | + else { |
|
135 | + $this->timeout = $timeout->format('Y-m-d H:i:s'); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return int |
|
141 | + */ |
|
142 | + public function getDisabled() |
|
143 | + { |
|
144 | + return $this->disabled; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param int $disabled |
|
149 | + */ |
|
150 | + public function setDisabled($disabled) |
|
151 | + { |
|
152 | + $this->disabled = $disabled; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @return int |
|
157 | + */ |
|
158 | + public function getPriority() |
|
159 | + { |
|
160 | + return $this->priority; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param int $priority |
|
165 | + */ |
|
166 | + public function setPriority($priority) |
|
167 | + { |
|
168 | + $this->priority = $priority; |
|
169 | + } |
|
170 | + |
|
171 | + public function save() |
|
172 | + { |
|
173 | + if ($this->isNew()) { |
|
174 | + // insert |
|
175 | + $statement = $this->dbObject->prepare(<<<SQL |
|
176 | 176 | INSERT INTO credential ( updateversion, user, factor, type, data, version, timeout, disabled, priority ) |
177 | 177 | VALUES ( 0, :user, :factor, :type, :data, :version, :timeout, :disabled, :priority ); |
178 | 178 | SQL |
179 | - ); |
|
180 | - $statement->bindValue(":user", $this->user); |
|
181 | - $statement->bindValue(":factor", $this->factor); |
|
182 | - $statement->bindValue(":type", $this->type); |
|
183 | - $statement->bindValue(":data", $this->data); |
|
184 | - $statement->bindValue(":version", $this->version); |
|
185 | - $statement->bindValue(":timeout", $this->timeout); |
|
186 | - $statement->bindValue(":disabled", $this->disabled); |
|
187 | - $statement->bindValue(":priority", $this->priority); |
|
188 | - |
|
189 | - if ($statement->execute()) { |
|
190 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
191 | - } |
|
192 | - else { |
|
193 | - throw new Exception($statement->errorInfo()); |
|
194 | - } |
|
195 | - } |
|
196 | - else { |
|
197 | - // update |
|
198 | - $statement = $this->dbObject->prepare(<<<SQL |
|
179 | + ); |
|
180 | + $statement->bindValue(":user", $this->user); |
|
181 | + $statement->bindValue(":factor", $this->factor); |
|
182 | + $statement->bindValue(":type", $this->type); |
|
183 | + $statement->bindValue(":data", $this->data); |
|
184 | + $statement->bindValue(":version", $this->version); |
|
185 | + $statement->bindValue(":timeout", $this->timeout); |
|
186 | + $statement->bindValue(":disabled", $this->disabled); |
|
187 | + $statement->bindValue(":priority", $this->priority); |
|
188 | + |
|
189 | + if ($statement->execute()) { |
|
190 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
191 | + } |
|
192 | + else { |
|
193 | + throw new Exception($statement->errorInfo()); |
|
194 | + } |
|
195 | + } |
|
196 | + else { |
|
197 | + // update |
|
198 | + $statement = $this->dbObject->prepare(<<<SQL |
|
199 | 199 | UPDATE credential |
200 | 200 | SET factor = :factor |
201 | 201 | , data = :data |
@@ -206,27 +206,27 @@ discard block |
||
206 | 206 | , updateversion = updateversion + 1 |
207 | 207 | WHERE id = :id AND updateversion = :updateversion; |
208 | 208 | SQL |
209 | - ); |
|
209 | + ); |
|
210 | 210 | |
211 | - $statement->bindValue(':id', $this->id); |
|
212 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
211 | + $statement->bindValue(':id', $this->id); |
|
212 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
213 | 213 | |
214 | - $statement->bindValue(":factor", $this->factor); |
|
215 | - $statement->bindValue(":data", $this->data); |
|
216 | - $statement->bindValue(":version", $this->version); |
|
217 | - $statement->bindValue(":timeout", $this->timeout); |
|
218 | - $statement->bindValue(":disabled", $this->disabled); |
|
219 | - $statement->bindValue(":priority", $this->priority); |
|
214 | + $statement->bindValue(":factor", $this->factor); |
|
215 | + $statement->bindValue(":data", $this->data); |
|
216 | + $statement->bindValue(":version", $this->version); |
|
217 | + $statement->bindValue(":timeout", $this->timeout); |
|
218 | + $statement->bindValue(":disabled", $this->disabled); |
|
219 | + $statement->bindValue(":priority", $this->priority); |
|
220 | 220 | |
221 | - if (!$statement->execute()) { |
|
222 | - throw new Exception($statement->errorInfo()); |
|
223 | - } |
|
221 | + if (!$statement->execute()) { |
|
222 | + throw new Exception($statement->errorInfo()); |
|
223 | + } |
|
224 | 224 | |
225 | - if ($statement->rowCount() !== 1) { |
|
226 | - throw new OptimisticLockFailedException(); |
|
227 | - } |
|
225 | + if ($statement->rowCount() !== 1) { |
|
226 | + throw new OptimisticLockFailedException(); |
|
227 | + } |
|
228 | 228 | |
229 | - $this->updateversion++; |
|
230 | - } |
|
231 | - } |
|
229 | + $this->updateversion++; |
|
230 | + } |
|
231 | + } |
|
232 | 232 | } |
233 | 233 | \ No newline at end of file |
@@ -22,560 +22,560 @@ |
||
22 | 22 | */ |
23 | 23 | class WebRequest |
24 | 24 | { |
25 | - /** |
|
26 | - * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | - */ |
|
28 | - private static $globalStateProvider; |
|
29 | - |
|
30 | - /** |
|
31 | - * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function wasPosted() |
|
35 | - { |
|
36 | - return self::method() === 'POST'; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets the HTTP Method used |
|
41 | - * @return string|null |
|
42 | - */ |
|
43 | - public static function method() |
|
44 | - { |
|
45 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | - |
|
47 | - if (isset($server['REQUEST_METHOD'])) { |
|
48 | - return $server['REQUEST_METHOD']; |
|
49 | - } |
|
50 | - |
|
51 | - return null; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public static function isHttps() |
|
59 | - { |
|
60 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | - |
|
62 | - if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | - if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | - // Client <=> Proxy is encrypted |
|
65 | - return true; |
|
66 | - } |
|
67 | - else { |
|
68 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | - return false; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($server['HTTPS'])) { |
|
74 | - if ($server['HTTPS'] === 'off') { |
|
75 | - // ISAPI on IIS breaks the spec. :( |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - if ($server['HTTPS'] !== '') { |
|
80 | - // Set to a non-empty value |
|
81 | - return true; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - return false; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Gets the path info |
|
90 | - * |
|
91 | - * @return array Array of path info segments |
|
92 | - */ |
|
93 | - public static function pathInfo() |
|
94 | - { |
|
95 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | - if (!isset($server['PATH_INFO'])) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $exploded = explode('/', $server['PATH_INFO']); |
|
101 | - |
|
102 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | - // with a / |
|
104 | - return array_values(array_filter($exploded)); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Gets the remote address of the web request |
|
109 | - * @return null|string |
|
110 | - */ |
|
111 | - public static function remoteAddress() |
|
112 | - { |
|
113 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | - |
|
115 | - if (isset($server['REMOTE_ADDR'])) { |
|
116 | - return $server['REMOTE_ADDR']; |
|
117 | - } |
|
118 | - |
|
119 | - return null; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Gets the remote address of the web request |
|
124 | - * @return null|string |
|
125 | - */ |
|
126 | - public static function httpHost() |
|
127 | - { |
|
128 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | - |
|
130 | - if (isset($server['HTTP_HOST'])) { |
|
131 | - return $server['HTTP_HOST']; |
|
132 | - } |
|
133 | - |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Gets the XFF header contents for the web request |
|
139 | - * @return null|string |
|
140 | - */ |
|
141 | - public static function forwardedAddress() |
|
142 | - { |
|
143 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
144 | - |
|
145 | - if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
146 | - return $server['HTTP_X_FORWARDED_FOR']; |
|
147 | - } |
|
148 | - |
|
149 | - return null; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Sets the global state provider. |
|
154 | - * |
|
155 | - * Almost guaranteed this is not the method you want in production code. |
|
156 | - * |
|
157 | - * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
158 | - */ |
|
159 | - public static function setGlobalStateProvider($globalState) |
|
160 | - { |
|
161 | - self::$globalStateProvider = $globalState; |
|
162 | - } |
|
163 | - |
|
164 | - #region POST variables |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $key |
|
168 | - * |
|
169 | - * @return null|string |
|
170 | - */ |
|
171 | - public static function postString($key) |
|
172 | - { |
|
173 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
174 | - if (!array_key_exists($key, $post)) { |
|
175 | - return null; |
|
176 | - } |
|
177 | - |
|
178 | - if ($post[$key] === "") { |
|
179 | - return null; |
|
180 | - } |
|
181 | - |
|
182 | - return (string)$post[$key]; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $key |
|
187 | - * |
|
188 | - * @return null|string |
|
189 | - */ |
|
190 | - public static function postEmail($key) |
|
191 | - { |
|
192 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
193 | - if (!array_key_exists($key, $post)) { |
|
194 | - return null; |
|
195 | - } |
|
196 | - |
|
197 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
198 | - |
|
199 | - if ($filteredValue === false) { |
|
200 | - return null; |
|
201 | - } |
|
202 | - |
|
203 | - return (string)$filteredValue; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param string $key |
|
208 | - * |
|
209 | - * @return int|null |
|
210 | - */ |
|
211 | - public static function postInt($key) |
|
212 | - { |
|
213 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
214 | - if (!array_key_exists($key, $post)) { |
|
215 | - return null; |
|
216 | - } |
|
217 | - |
|
218 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
219 | - |
|
220 | - if ($filteredValue === null) { |
|
221 | - return null; |
|
222 | - } |
|
223 | - |
|
224 | - return (int)$filteredValue; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $key |
|
229 | - * |
|
230 | - * @return bool |
|
231 | - */ |
|
232 | - public static function postBoolean($key) |
|
233 | - { |
|
234 | - $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
235 | - if (!array_key_exists($key, $get)) { |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - // presence of parameter only |
|
240 | - if ($get[$key] === "") { |
|
241 | - return true; |
|
242 | - } |
|
243 | - |
|
244 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - return true; |
|
249 | - } |
|
250 | - |
|
251 | - #endregion |
|
252 | - |
|
253 | - #region GET variables |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $key |
|
257 | - * |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public static function getBoolean($key) |
|
261 | - { |
|
262 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
263 | - if (!array_key_exists($key, $get)) { |
|
264 | - return false; |
|
265 | - } |
|
266 | - |
|
267 | - // presence of parameter only |
|
268 | - if ($get[$key] === "") { |
|
269 | - return true; |
|
270 | - } |
|
271 | - |
|
272 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
273 | - return false; |
|
274 | - } |
|
275 | - |
|
276 | - return true; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @param string $key |
|
281 | - * |
|
282 | - * @return int|null |
|
283 | - */ |
|
284 | - public static function getInt($key) |
|
285 | - { |
|
286 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
287 | - if (!array_key_exists($key, $get)) { |
|
288 | - return null; |
|
289 | - } |
|
290 | - |
|
291 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
292 | - |
|
293 | - if ($filteredValue === null) { |
|
294 | - return null; |
|
295 | - } |
|
296 | - |
|
297 | - return (int)$filteredValue; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * @param string $key |
|
302 | - * |
|
303 | - * @return null|string |
|
304 | - */ |
|
305 | - public static function getString($key) |
|
306 | - { |
|
307 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
308 | - if (!array_key_exists($key, $get)) { |
|
309 | - return null; |
|
310 | - } |
|
311 | - |
|
312 | - if ($get[$key] === "") { |
|
313 | - return null; |
|
314 | - } |
|
315 | - |
|
316 | - return (string)$get[$key]; |
|
317 | - } |
|
318 | - |
|
319 | - #endregion |
|
320 | - |
|
321 | - /** |
|
322 | - * Sets the logged-in user to the specified user. |
|
323 | - * |
|
324 | - * @param User $user |
|
325 | - */ |
|
326 | - public static function setLoggedInUser(User $user) |
|
327 | - { |
|
328 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
329 | - |
|
330 | - $session['userID'] = $user->getId(); |
|
331 | - unset($session['partialLogin']); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sets the post-login redirect |
|
336 | - */ |
|
337 | - public static function setPostLoginRedirect() |
|
338 | - { |
|
339 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
340 | - $session['returnTo'] = self::requestUri(); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @return string|null |
|
345 | - */ |
|
346 | - public static function requestUri() |
|
347 | - { |
|
348 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
349 | - |
|
350 | - if (isset($server['REQUEST_URI'])) { |
|
351 | - return $server['REQUEST_URI']; |
|
352 | - } |
|
353 | - |
|
354 | - return null; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Clears the post-login redirect |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - public static function clearPostLoginRedirect() |
|
362 | - { |
|
363 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
364 | - if (array_key_exists('returnTo', $session)) { |
|
365 | - $path = $session['returnTo']; |
|
366 | - unset($session['returnTo']); |
|
367 | - |
|
368 | - return $path; |
|
369 | - } |
|
370 | - |
|
371 | - return null; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * @return string|null |
|
376 | - */ |
|
377 | - public static function serverName() |
|
378 | - { |
|
379 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
380 | - |
|
381 | - if (isset($server['SERVER_NAME'])) { |
|
382 | - return $server['SERVER_NAME']; |
|
383 | - } |
|
384 | - |
|
385 | - return null; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * You probably only want to deal with this through SessionAlert. |
|
390 | - * @return void |
|
391 | - */ |
|
392 | - public static function clearSessionAlertData() |
|
393 | - { |
|
394 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
395 | - if (array_key_exists('alerts', $session)) { |
|
396 | - unset($session['alerts']); |
|
397 | - } |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * You probably only want to deal with this through SessionAlert. |
|
402 | - * |
|
403 | - * @return string[] |
|
404 | - */ |
|
405 | - public static function getSessionAlertData() |
|
406 | - { |
|
407 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
408 | - if (array_key_exists('alerts', $session)) { |
|
409 | - return $session['alerts']; |
|
410 | - } |
|
411 | - |
|
412 | - return array(); |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * You probably only want to deal with this through SessionAlert. |
|
417 | - * |
|
418 | - * @param string[] $data |
|
419 | - */ |
|
420 | - public static function setSessionAlertData($data) |
|
421 | - { |
|
422 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
423 | - $session['alerts'] = $data; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * You probably only want to deal with this through TokenManager. |
|
428 | - * |
|
429 | - * @return string[] |
|
430 | - */ |
|
431 | - public static function getSessionTokenData() |
|
432 | - { |
|
433 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
434 | - if (array_key_exists('tokens', $session)) { |
|
435 | - return $session['tokens']; |
|
436 | - } |
|
437 | - |
|
438 | - return array(); |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * You probably only want to deal with this through TokenManager. |
|
443 | - * |
|
444 | - * @param string[] $data |
|
445 | - */ |
|
446 | - public static function setSessionTokenData($data) |
|
447 | - { |
|
448 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
449 | - $session['tokens'] = $data; |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * @param string $key |
|
454 | - * |
|
455 | - * @return mixed |
|
456 | - */ |
|
457 | - public static function getSessionContext($key) |
|
458 | - { |
|
459 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
460 | - |
|
461 | - if (!isset($session['context'])) { |
|
462 | - $session['context'] = array(); |
|
463 | - } |
|
464 | - |
|
465 | - if (!isset($session['context'][$key])) { |
|
466 | - return null; |
|
467 | - } |
|
468 | - |
|
469 | - return $session['context'][$key]; |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * @param string $key |
|
474 | - * @param mixed $data |
|
475 | - */ |
|
476 | - public static function setSessionContext($key, $data) |
|
477 | - { |
|
478 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
479 | - |
|
480 | - if (!isset($session['context'])) { |
|
481 | - $session['context'] = array(); |
|
482 | - } |
|
483 | - |
|
484 | - $session['context'][$key] = $data; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * @return int|null |
|
489 | - */ |
|
490 | - public static function getSessionUserId() |
|
491 | - { |
|
492 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
493 | - |
|
494 | - return isset($session['userID']) ? (int)$session['userID'] : null; |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * @param User $user |
|
499 | - */ |
|
500 | - public static function setOAuthPartialLogin(User $user) |
|
501 | - { |
|
502 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
503 | - $session['oauthPartialLogin'] = $user->getId(); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * @return int|null |
|
508 | - */ |
|
509 | - public static function getOAuthPartialLogin() |
|
510 | - { |
|
511 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
512 | - |
|
513 | - return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
514 | - } |
|
515 | - |
|
516 | - public static function setAuthPartialLogin($userId, $stage) |
|
517 | - { |
|
518 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
519 | - $session['authPartialLoginId'] = $userId; |
|
520 | - $session['authPartialLoginStage'] = $stage; |
|
521 | - } |
|
522 | - |
|
523 | - public static function getAuthPartialLogin() |
|
524 | - { |
|
525 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
526 | - |
|
527 | - $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
528 | - $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
529 | - |
|
530 | - return array($userId, $stage); |
|
531 | - } |
|
532 | - |
|
533 | - public static function clearAuthPartialLogin() |
|
534 | - { |
|
535 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
536 | - unset($session['authPartialLoginId']); |
|
537 | - unset($session['authPartialLoginStage']); |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * @return null|string |
|
542 | - */ |
|
543 | - public static function userAgent() |
|
544 | - { |
|
545 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
546 | - |
|
547 | - if (isset($server['HTTP_USER_AGENT'])) { |
|
548 | - return $server['HTTP_USER_AGENT']; |
|
549 | - } |
|
550 | - |
|
551 | - return null; |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * @return null|string |
|
556 | - */ |
|
557 | - public static function scriptName() |
|
558 | - { |
|
559 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
560 | - |
|
561 | - if (isset($server['SCRIPT_NAME'])) { |
|
562 | - return $server['SCRIPT_NAME']; |
|
563 | - } |
|
564 | - |
|
565 | - return null; |
|
566 | - } |
|
567 | - |
|
568 | - /** |
|
569 | - * @return null|string |
|
570 | - */ |
|
571 | - public static function origin() |
|
572 | - { |
|
573 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
574 | - |
|
575 | - if (isset($server['HTTP_ORIGIN'])) { |
|
576 | - return $server['HTTP_ORIGIN']; |
|
577 | - } |
|
578 | - |
|
579 | - return null; |
|
580 | - } |
|
25 | + /** |
|
26 | + * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | + */ |
|
28 | + private static $globalStateProvider; |
|
29 | + |
|
30 | + /** |
|
31 | + * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function wasPosted() |
|
35 | + { |
|
36 | + return self::method() === 'POST'; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets the HTTP Method used |
|
41 | + * @return string|null |
|
42 | + */ |
|
43 | + public static function method() |
|
44 | + { |
|
45 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | + |
|
47 | + if (isset($server['REQUEST_METHOD'])) { |
|
48 | + return $server['REQUEST_METHOD']; |
|
49 | + } |
|
50 | + |
|
51 | + return null; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public static function isHttps() |
|
59 | + { |
|
60 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | + |
|
62 | + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | + if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | + // Client <=> Proxy is encrypted |
|
65 | + return true; |
|
66 | + } |
|
67 | + else { |
|
68 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | + return false; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($server['HTTPS'])) { |
|
74 | + if ($server['HTTPS'] === 'off') { |
|
75 | + // ISAPI on IIS breaks the spec. :( |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + if ($server['HTTPS'] !== '') { |
|
80 | + // Set to a non-empty value |
|
81 | + return true; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + return false; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Gets the path info |
|
90 | + * |
|
91 | + * @return array Array of path info segments |
|
92 | + */ |
|
93 | + public static function pathInfo() |
|
94 | + { |
|
95 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | + if (!isset($server['PATH_INFO'])) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $exploded = explode('/', $server['PATH_INFO']); |
|
101 | + |
|
102 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | + // with a / |
|
104 | + return array_values(array_filter($exploded)); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Gets the remote address of the web request |
|
109 | + * @return null|string |
|
110 | + */ |
|
111 | + public static function remoteAddress() |
|
112 | + { |
|
113 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | + |
|
115 | + if (isset($server['REMOTE_ADDR'])) { |
|
116 | + return $server['REMOTE_ADDR']; |
|
117 | + } |
|
118 | + |
|
119 | + return null; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Gets the remote address of the web request |
|
124 | + * @return null|string |
|
125 | + */ |
|
126 | + public static function httpHost() |
|
127 | + { |
|
128 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | + |
|
130 | + if (isset($server['HTTP_HOST'])) { |
|
131 | + return $server['HTTP_HOST']; |
|
132 | + } |
|
133 | + |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Gets the XFF header contents for the web request |
|
139 | + * @return null|string |
|
140 | + */ |
|
141 | + public static function forwardedAddress() |
|
142 | + { |
|
143 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
144 | + |
|
145 | + if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
146 | + return $server['HTTP_X_FORWARDED_FOR']; |
|
147 | + } |
|
148 | + |
|
149 | + return null; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Sets the global state provider. |
|
154 | + * |
|
155 | + * Almost guaranteed this is not the method you want in production code. |
|
156 | + * |
|
157 | + * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
158 | + */ |
|
159 | + public static function setGlobalStateProvider($globalState) |
|
160 | + { |
|
161 | + self::$globalStateProvider = $globalState; |
|
162 | + } |
|
163 | + |
|
164 | + #region POST variables |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $key |
|
168 | + * |
|
169 | + * @return null|string |
|
170 | + */ |
|
171 | + public static function postString($key) |
|
172 | + { |
|
173 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
174 | + if (!array_key_exists($key, $post)) { |
|
175 | + return null; |
|
176 | + } |
|
177 | + |
|
178 | + if ($post[$key] === "") { |
|
179 | + return null; |
|
180 | + } |
|
181 | + |
|
182 | + return (string)$post[$key]; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $key |
|
187 | + * |
|
188 | + * @return null|string |
|
189 | + */ |
|
190 | + public static function postEmail($key) |
|
191 | + { |
|
192 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
193 | + if (!array_key_exists($key, $post)) { |
|
194 | + return null; |
|
195 | + } |
|
196 | + |
|
197 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
198 | + |
|
199 | + if ($filteredValue === false) { |
|
200 | + return null; |
|
201 | + } |
|
202 | + |
|
203 | + return (string)$filteredValue; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param string $key |
|
208 | + * |
|
209 | + * @return int|null |
|
210 | + */ |
|
211 | + public static function postInt($key) |
|
212 | + { |
|
213 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
214 | + if (!array_key_exists($key, $post)) { |
|
215 | + return null; |
|
216 | + } |
|
217 | + |
|
218 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
219 | + |
|
220 | + if ($filteredValue === null) { |
|
221 | + return null; |
|
222 | + } |
|
223 | + |
|
224 | + return (int)$filteredValue; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $key |
|
229 | + * |
|
230 | + * @return bool |
|
231 | + */ |
|
232 | + public static function postBoolean($key) |
|
233 | + { |
|
234 | + $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
235 | + if (!array_key_exists($key, $get)) { |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + // presence of parameter only |
|
240 | + if ($get[$key] === "") { |
|
241 | + return true; |
|
242 | + } |
|
243 | + |
|
244 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + return true; |
|
249 | + } |
|
250 | + |
|
251 | + #endregion |
|
252 | + |
|
253 | + #region GET variables |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $key |
|
257 | + * |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public static function getBoolean($key) |
|
261 | + { |
|
262 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
263 | + if (!array_key_exists($key, $get)) { |
|
264 | + return false; |
|
265 | + } |
|
266 | + |
|
267 | + // presence of parameter only |
|
268 | + if ($get[$key] === "") { |
|
269 | + return true; |
|
270 | + } |
|
271 | + |
|
272 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
273 | + return false; |
|
274 | + } |
|
275 | + |
|
276 | + return true; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @param string $key |
|
281 | + * |
|
282 | + * @return int|null |
|
283 | + */ |
|
284 | + public static function getInt($key) |
|
285 | + { |
|
286 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
287 | + if (!array_key_exists($key, $get)) { |
|
288 | + return null; |
|
289 | + } |
|
290 | + |
|
291 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
292 | + |
|
293 | + if ($filteredValue === null) { |
|
294 | + return null; |
|
295 | + } |
|
296 | + |
|
297 | + return (int)$filteredValue; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * @param string $key |
|
302 | + * |
|
303 | + * @return null|string |
|
304 | + */ |
|
305 | + public static function getString($key) |
|
306 | + { |
|
307 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
308 | + if (!array_key_exists($key, $get)) { |
|
309 | + return null; |
|
310 | + } |
|
311 | + |
|
312 | + if ($get[$key] === "") { |
|
313 | + return null; |
|
314 | + } |
|
315 | + |
|
316 | + return (string)$get[$key]; |
|
317 | + } |
|
318 | + |
|
319 | + #endregion |
|
320 | + |
|
321 | + /** |
|
322 | + * Sets the logged-in user to the specified user. |
|
323 | + * |
|
324 | + * @param User $user |
|
325 | + */ |
|
326 | + public static function setLoggedInUser(User $user) |
|
327 | + { |
|
328 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
329 | + |
|
330 | + $session['userID'] = $user->getId(); |
|
331 | + unset($session['partialLogin']); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sets the post-login redirect |
|
336 | + */ |
|
337 | + public static function setPostLoginRedirect() |
|
338 | + { |
|
339 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
340 | + $session['returnTo'] = self::requestUri(); |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @return string|null |
|
345 | + */ |
|
346 | + public static function requestUri() |
|
347 | + { |
|
348 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
349 | + |
|
350 | + if (isset($server['REQUEST_URI'])) { |
|
351 | + return $server['REQUEST_URI']; |
|
352 | + } |
|
353 | + |
|
354 | + return null; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Clears the post-login redirect |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + public static function clearPostLoginRedirect() |
|
362 | + { |
|
363 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
364 | + if (array_key_exists('returnTo', $session)) { |
|
365 | + $path = $session['returnTo']; |
|
366 | + unset($session['returnTo']); |
|
367 | + |
|
368 | + return $path; |
|
369 | + } |
|
370 | + |
|
371 | + return null; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * @return string|null |
|
376 | + */ |
|
377 | + public static function serverName() |
|
378 | + { |
|
379 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
380 | + |
|
381 | + if (isset($server['SERVER_NAME'])) { |
|
382 | + return $server['SERVER_NAME']; |
|
383 | + } |
|
384 | + |
|
385 | + return null; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * You probably only want to deal with this through SessionAlert. |
|
390 | + * @return void |
|
391 | + */ |
|
392 | + public static function clearSessionAlertData() |
|
393 | + { |
|
394 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
395 | + if (array_key_exists('alerts', $session)) { |
|
396 | + unset($session['alerts']); |
|
397 | + } |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * You probably only want to deal with this through SessionAlert. |
|
402 | + * |
|
403 | + * @return string[] |
|
404 | + */ |
|
405 | + public static function getSessionAlertData() |
|
406 | + { |
|
407 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
408 | + if (array_key_exists('alerts', $session)) { |
|
409 | + return $session['alerts']; |
|
410 | + } |
|
411 | + |
|
412 | + return array(); |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * You probably only want to deal with this through SessionAlert. |
|
417 | + * |
|
418 | + * @param string[] $data |
|
419 | + */ |
|
420 | + public static function setSessionAlertData($data) |
|
421 | + { |
|
422 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
423 | + $session['alerts'] = $data; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * You probably only want to deal with this through TokenManager. |
|
428 | + * |
|
429 | + * @return string[] |
|
430 | + */ |
|
431 | + public static function getSessionTokenData() |
|
432 | + { |
|
433 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
434 | + if (array_key_exists('tokens', $session)) { |
|
435 | + return $session['tokens']; |
|
436 | + } |
|
437 | + |
|
438 | + return array(); |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * You probably only want to deal with this through TokenManager. |
|
443 | + * |
|
444 | + * @param string[] $data |
|
445 | + */ |
|
446 | + public static function setSessionTokenData($data) |
|
447 | + { |
|
448 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
449 | + $session['tokens'] = $data; |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * @param string $key |
|
454 | + * |
|
455 | + * @return mixed |
|
456 | + */ |
|
457 | + public static function getSessionContext($key) |
|
458 | + { |
|
459 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
460 | + |
|
461 | + if (!isset($session['context'])) { |
|
462 | + $session['context'] = array(); |
|
463 | + } |
|
464 | + |
|
465 | + if (!isset($session['context'][$key])) { |
|
466 | + return null; |
|
467 | + } |
|
468 | + |
|
469 | + return $session['context'][$key]; |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * @param string $key |
|
474 | + * @param mixed $data |
|
475 | + */ |
|
476 | + public static function setSessionContext($key, $data) |
|
477 | + { |
|
478 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
479 | + |
|
480 | + if (!isset($session['context'])) { |
|
481 | + $session['context'] = array(); |
|
482 | + } |
|
483 | + |
|
484 | + $session['context'][$key] = $data; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * @return int|null |
|
489 | + */ |
|
490 | + public static function getSessionUserId() |
|
491 | + { |
|
492 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
493 | + |
|
494 | + return isset($session['userID']) ? (int)$session['userID'] : null; |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * @param User $user |
|
499 | + */ |
|
500 | + public static function setOAuthPartialLogin(User $user) |
|
501 | + { |
|
502 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
503 | + $session['oauthPartialLogin'] = $user->getId(); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * @return int|null |
|
508 | + */ |
|
509 | + public static function getOAuthPartialLogin() |
|
510 | + { |
|
511 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
512 | + |
|
513 | + return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
514 | + } |
|
515 | + |
|
516 | + public static function setAuthPartialLogin($userId, $stage) |
|
517 | + { |
|
518 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
519 | + $session['authPartialLoginId'] = $userId; |
|
520 | + $session['authPartialLoginStage'] = $stage; |
|
521 | + } |
|
522 | + |
|
523 | + public static function getAuthPartialLogin() |
|
524 | + { |
|
525 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
526 | + |
|
527 | + $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
528 | + $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
529 | + |
|
530 | + return array($userId, $stage); |
|
531 | + } |
|
532 | + |
|
533 | + public static function clearAuthPartialLogin() |
|
534 | + { |
|
535 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
536 | + unset($session['authPartialLoginId']); |
|
537 | + unset($session['authPartialLoginStage']); |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * @return null|string |
|
542 | + */ |
|
543 | + public static function userAgent() |
|
544 | + { |
|
545 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
546 | + |
|
547 | + if (isset($server['HTTP_USER_AGENT'])) { |
|
548 | + return $server['HTTP_USER_AGENT']; |
|
549 | + } |
|
550 | + |
|
551 | + return null; |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * @return null|string |
|
556 | + */ |
|
557 | + public static function scriptName() |
|
558 | + { |
|
559 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
560 | + |
|
561 | + if (isset($server['SCRIPT_NAME'])) { |
|
562 | + return $server['SCRIPT_NAME']; |
|
563 | + } |
|
564 | + |
|
565 | + return null; |
|
566 | + } |
|
567 | + |
|
568 | + /** |
|
569 | + * @return null|string |
|
570 | + */ |
|
571 | + public static function origin() |
|
572 | + { |
|
573 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
574 | + |
|
575 | + if (isset($server['HTTP_ORIGIN'])) { |
|
576 | + return $server['HTTP_ORIGIN']; |
|
577 | + } |
|
578 | + |
|
579 | + return null; |
|
580 | + } |
|
581 | 581 | } |
582 | 582 | \ No newline at end of file |
@@ -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 |
@@ -21,315 +21,315 @@ |
||
21 | 21 | |
22 | 22 | abstract class LoginCredentialPageBase extends InternalPageBase |
23 | 23 | { |
24 | - /** @var User */ |
|
25 | - protected $partialUser = null; |
|
26 | - protected $nextPageMap = array( |
|
27 | - 'yubikeyotp' => 'otp', |
|
28 | - 'totp' => 'otp', |
|
29 | - 'scratch' => 'otp', |
|
30 | - 'u2f' => 'u2f', |
|
31 | - ); |
|
32 | - protected $names = array( |
|
33 | - 'yubikeyotp' => 'Yubikey OTP', |
|
34 | - 'totp' => 'TOTP (phone code generator)', |
|
35 | - 'scratch' => 'scratch token', |
|
36 | - 'u2f' => 'U2F security token', |
|
37 | - ); |
|
38 | - |
|
39 | - /** |
|
40 | - * Main function for this page, when no specific actions are called. |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - protected function main() |
|
44 | - { |
|
45 | - if (!$this->enforceHttps()) { |
|
46 | - return; |
|
47 | - } |
|
48 | - |
|
49 | - if (WebRequest::wasPosted()) { |
|
50 | - $this->validateCSRFToken(); |
|
51 | - |
|
52 | - $database = $this->getDatabase(); |
|
53 | - try { |
|
54 | - list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
55 | - |
|
56 | - if ($partialStage === null) { |
|
57 | - $partialStage = 1; |
|
58 | - } |
|
59 | - |
|
60 | - if ($partialId === null) { |
|
61 | - $username = WebRequest::postString('username'); |
|
62 | - |
|
63 | - if ($username === null || trim($username) === '') { |
|
64 | - throw new ApplicationLogicException('No username specified.'); |
|
65 | - } |
|
66 | - |
|
67 | - $user = User::getByUsername($username, $database); |
|
68 | - } |
|
69 | - else { |
|
70 | - $user = User::getById($partialId, $database); |
|
71 | - } |
|
72 | - |
|
73 | - if ($user === false) { |
|
74 | - throw new ApplicationLogicException("Authentication failed"); |
|
75 | - } |
|
76 | - |
|
77 | - $authMan = new AuthenticationManager($database, $this->getSiteConfiguration(), |
|
78 | - $this->getHttpHelper()); |
|
79 | - |
|
80 | - $credential = $this->getProviderCredentials(); |
|
81 | - |
|
82 | - $authResult = $authMan->authenticate($user, $credential, $partialStage); |
|
83 | - |
|
84 | - if ($authResult === AuthenticationManager::AUTH_FAIL) { |
|
85 | - throw new ApplicationLogicException("Authentication failed"); |
|
86 | - } |
|
87 | - |
|
88 | - if ($authResult === AuthenticationManager::AUTH_REQUIRE_NEXT_STAGE) { |
|
89 | - $this->processJumpNextStage($user, $partialStage, $database); |
|
90 | - |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - if ($authResult === AuthenticationManager::AUTH_OK) { |
|
95 | - $this->processLoginSuccess($user); |
|
96 | - |
|
97 | - return; |
|
98 | - } |
|
99 | - } |
|
100 | - catch (ApplicationLogicException $ex) { |
|
101 | - WebRequest::clearAuthPartialLogin(); |
|
102 | - |
|
103 | - SessionAlert::error($ex->getMessage()); |
|
104 | - $this->redirect('login'); |
|
105 | - |
|
106 | - return; |
|
107 | - } |
|
108 | - } |
|
109 | - else { |
|
110 | - $this->assign('showSignIn', true); |
|
111 | - |
|
112 | - $this->setupPartial(); |
|
113 | - $this->assignCSRFToken(); |
|
114 | - $this->providerSpecificSetup(); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - protected function isProtectedPage() |
|
119 | - { |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Enforces HTTPS on the login form |
|
125 | - * |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - private function enforceHttps() |
|
129 | - { |
|
130 | - if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
131 | - if (WebRequest::isHttps()) { |
|
132 | - // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
133 | - $this->headerQueue[] = "Strict-Transport-Security: max-age=15768000"; |
|
134 | - } |
|
135 | - else { |
|
136 | - // This is the login form, not the request form. We need protection here. |
|
137 | - $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
138 | - |
|
139 | - return false; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - return true; |
|
144 | - } |
|
145 | - |
|
146 | - protected abstract function providerSpecificSetup(); |
|
147 | - |
|
148 | - protected function setupPartial() |
|
149 | - { |
|
150 | - $database = $this->getDatabase(); |
|
151 | - |
|
152 | - // default stuff |
|
153 | - $this->assign('alternatives', array()); // 'u2f' => array('U2F token'), 'otp' => array('TOTP', 'scratch', 'yubiotp'))); |
|
154 | - |
|
155 | - // is this stage one? |
|
156 | - list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
157 | - if ($partialStage === null || $partialId === null) { |
|
158 | - WebRequest::clearAuthPartialLogin(); |
|
159 | - } |
|
160 | - |
|
161 | - // Check to see if we have a partial login in progress |
|
162 | - $username = null; |
|
163 | - if ($partialId !== null) { |
|
164 | - // Yes, enforce this username |
|
165 | - $this->partialUser = User::getById($partialId, $database); |
|
166 | - $username = $this->partialUser->getUsername(); |
|
167 | - |
|
168 | - $this->setupAlternates($this->partialUser, $partialStage, $database); |
|
169 | - } |
|
170 | - else { |
|
171 | - // No, see if we've preloaded a username |
|
172 | - $preloadUsername = WebRequest::getString('tplUsername'); |
|
173 | - if ($preloadUsername !== null) { |
|
174 | - $username = $preloadUsername; |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - if ($partialStage === null) { |
|
179 | - $partialStage = 1; |
|
180 | - } |
|
181 | - |
|
182 | - $this->assign('partialStage', $partialStage); |
|
183 | - $this->assign('username', $username); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Redirect the user back to wherever they came from after a successful login |
|
188 | - * |
|
189 | - * @param User $user |
|
190 | - */ |
|
191 | - protected function goBackWhenceYouCame(User $user) |
|
192 | - { |
|
193 | - // Redirect to wherever the user came from |
|
194 | - $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
195 | - if ($redirectDestination !== null) { |
|
196 | - $this->redirectUrl($redirectDestination); |
|
197 | - } |
|
198 | - else { |
|
199 | - if ($user->isNewUser()) { |
|
200 | - // home page isn't allowed, go to preferences instead |
|
201 | - $this->redirect('preferences'); |
|
202 | - } |
|
203 | - else { |
|
204 | - // go to the home page |
|
205 | - $this->redirect(''); |
|
206 | - } |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - private function processLoginSuccess(User $user) |
|
211 | - { |
|
212 | - // Touch force logout |
|
213 | - $user->setForceLogout(false); |
|
214 | - $user->save(); |
|
215 | - |
|
216 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
217 | - $this->getSiteConfiguration()); |
|
218 | - |
|
219 | - if ($oauth->isFullyLinked()) { |
|
220 | - try { |
|
221 | - // Reload the user's identity ticket. |
|
222 | - $oauth->refreshIdentity(); |
|
223 | - |
|
224 | - // Check for blocks |
|
225 | - if ($oauth->getIdentity()->getBlocked()) { |
|
226 | - // blocked! |
|
227 | - SessionAlert::error("You are currently blocked on-wiki. You will not be able to log in until you are unblocked."); |
|
228 | - $this->redirect('login'); |
|
229 | - |
|
230 | - return; |
|
231 | - } |
|
232 | - } |
|
233 | - catch (OAuthException $ex) { |
|
234 | - // Oops. Refreshing ticket failed. Force a re-auth. |
|
235 | - $authoriseUrl = $oauth->getRequestToken(); |
|
236 | - WebRequest::setOAuthPartialLogin($user); |
|
237 | - $this->redirectUrl($authoriseUrl); |
|
238 | - |
|
239 | - return; |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - if (($this->getSiteConfiguration()->getEnforceOAuth() && !$oauth->isFullyLinked()) |
|
244 | - || $oauth->isPartiallyLinked() |
|
245 | - ) { |
|
246 | - $authoriseUrl = $oauth->getRequestToken(); |
|
247 | - WebRequest::setOAuthPartialLogin($user); |
|
248 | - $this->redirectUrl($authoriseUrl); |
|
249 | - |
|
250 | - return; |
|
251 | - } |
|
252 | - |
|
253 | - WebRequest::setLoggedInUser($user); |
|
254 | - |
|
255 | - $this->goBackWhenceYouCame($user); |
|
256 | - } |
|
257 | - |
|
258 | - protected abstract function getProviderCredentials(); |
|
259 | - |
|
260 | - /** |
|
261 | - * @param User $user |
|
262 | - * @param int $partialStage |
|
263 | - * @param PdoDatabase $database |
|
264 | - * |
|
265 | - * @throws ApplicationLogicException |
|
266 | - */ |
|
267 | - private function processJumpNextStage(User $user, $partialStage, PdoDatabase $database) |
|
268 | - { |
|
269 | - WebRequest::setAuthPartialLogin($user->getId(), $partialStage + 1); |
|
270 | - |
|
271 | - $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
272 | - $statement = $database->prepare($sql); |
|
273 | - $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage + 1)); |
|
274 | - $nextStage = $statement->fetchColumn(); |
|
275 | - $statement->closeCursor(); |
|
276 | - |
|
277 | - if (!isset($this->nextPageMap[$nextStage])) { |
|
278 | - throw new ApplicationLogicException('Unknown page handler for next authentication stage.'); |
|
279 | - } |
|
280 | - |
|
281 | - $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
282 | - } |
|
283 | - |
|
284 | - private function setupAlternates(User $user, $partialStage, PdoDatabase $database) |
|
285 | - { |
|
286 | - // get the providers available |
|
287 | - $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0'; |
|
288 | - $statement = $database->prepare($sql); |
|
289 | - $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage)); |
|
290 | - $alternates = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
291 | - |
|
292 | - $types = array(); |
|
293 | - foreach ($alternates as $item) { |
|
294 | - $type = $this->nextPageMap[$item]; |
|
295 | - if (!isset($types[$type])) { |
|
296 | - $types[$type] = array(); |
|
297 | - } |
|
298 | - |
|
299 | - $types[$type][] = $item; |
|
300 | - } |
|
301 | - |
|
302 | - $userOptions = array(); |
|
303 | - if (get_called_class() === PageOtpLogin::class) { |
|
304 | - $userOptions = $this->setupUserOptionsForType($types, 'u2f', $userOptions); |
|
305 | - } |
|
306 | - |
|
307 | - if (get_called_class() === PageU2FLogin::class) { |
|
308 | - $userOptions = $this->setupUserOptionsForType($types, 'otp', $userOptions); |
|
309 | - } |
|
310 | - |
|
311 | - $this->assign('alternatives', $userOptions); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * @param $types |
|
316 | - * @param $type |
|
317 | - * @param $userOptions |
|
318 | - * |
|
319 | - * @return mixed |
|
320 | - */ |
|
321 | - private function setupUserOptionsForType($types, $type, $userOptions) |
|
322 | - { |
|
323 | - if (isset($types[$type])) { |
|
324 | - $options = $types[$type]; |
|
325 | - |
|
326 | - array_walk($options, function(&$val) { |
|
327 | - $val = $this->names[$val]; |
|
328 | - }); |
|
329 | - |
|
330 | - $userOptions[$type] = $options; |
|
331 | - } |
|
332 | - |
|
333 | - return $userOptions; |
|
334 | - } |
|
24 | + /** @var User */ |
|
25 | + protected $partialUser = null; |
|
26 | + protected $nextPageMap = array( |
|
27 | + 'yubikeyotp' => 'otp', |
|
28 | + 'totp' => 'otp', |
|
29 | + 'scratch' => 'otp', |
|
30 | + 'u2f' => 'u2f', |
|
31 | + ); |
|
32 | + protected $names = array( |
|
33 | + 'yubikeyotp' => 'Yubikey OTP', |
|
34 | + 'totp' => 'TOTP (phone code generator)', |
|
35 | + 'scratch' => 'scratch token', |
|
36 | + 'u2f' => 'U2F security token', |
|
37 | + ); |
|
38 | + |
|
39 | + /** |
|
40 | + * Main function for this page, when no specific actions are called. |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + protected function main() |
|
44 | + { |
|
45 | + if (!$this->enforceHttps()) { |
|
46 | + return; |
|
47 | + } |
|
48 | + |
|
49 | + if (WebRequest::wasPosted()) { |
|
50 | + $this->validateCSRFToken(); |
|
51 | + |
|
52 | + $database = $this->getDatabase(); |
|
53 | + try { |
|
54 | + list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
55 | + |
|
56 | + if ($partialStage === null) { |
|
57 | + $partialStage = 1; |
|
58 | + } |
|
59 | + |
|
60 | + if ($partialId === null) { |
|
61 | + $username = WebRequest::postString('username'); |
|
62 | + |
|
63 | + if ($username === null || trim($username) === '') { |
|
64 | + throw new ApplicationLogicException('No username specified.'); |
|
65 | + } |
|
66 | + |
|
67 | + $user = User::getByUsername($username, $database); |
|
68 | + } |
|
69 | + else { |
|
70 | + $user = User::getById($partialId, $database); |
|
71 | + } |
|
72 | + |
|
73 | + if ($user === false) { |
|
74 | + throw new ApplicationLogicException("Authentication failed"); |
|
75 | + } |
|
76 | + |
|
77 | + $authMan = new AuthenticationManager($database, $this->getSiteConfiguration(), |
|
78 | + $this->getHttpHelper()); |
|
79 | + |
|
80 | + $credential = $this->getProviderCredentials(); |
|
81 | + |
|
82 | + $authResult = $authMan->authenticate($user, $credential, $partialStage); |
|
83 | + |
|
84 | + if ($authResult === AuthenticationManager::AUTH_FAIL) { |
|
85 | + throw new ApplicationLogicException("Authentication failed"); |
|
86 | + } |
|
87 | + |
|
88 | + if ($authResult === AuthenticationManager::AUTH_REQUIRE_NEXT_STAGE) { |
|
89 | + $this->processJumpNextStage($user, $partialStage, $database); |
|
90 | + |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + if ($authResult === AuthenticationManager::AUTH_OK) { |
|
95 | + $this->processLoginSuccess($user); |
|
96 | + |
|
97 | + return; |
|
98 | + } |
|
99 | + } |
|
100 | + catch (ApplicationLogicException $ex) { |
|
101 | + WebRequest::clearAuthPartialLogin(); |
|
102 | + |
|
103 | + SessionAlert::error($ex->getMessage()); |
|
104 | + $this->redirect('login'); |
|
105 | + |
|
106 | + return; |
|
107 | + } |
|
108 | + } |
|
109 | + else { |
|
110 | + $this->assign('showSignIn', true); |
|
111 | + |
|
112 | + $this->setupPartial(); |
|
113 | + $this->assignCSRFToken(); |
|
114 | + $this->providerSpecificSetup(); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + protected function isProtectedPage() |
|
119 | + { |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Enforces HTTPS on the login form |
|
125 | + * |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + private function enforceHttps() |
|
129 | + { |
|
130 | + if ($this->getSiteConfiguration()->getUseStrictTransportSecurity() !== false) { |
|
131 | + if (WebRequest::isHttps()) { |
|
132 | + // Client can clearly use HTTPS, so let's enforce it for all connections. |
|
133 | + $this->headerQueue[] = "Strict-Transport-Security: max-age=15768000"; |
|
134 | + } |
|
135 | + else { |
|
136 | + // This is the login form, not the request form. We need protection here. |
|
137 | + $this->redirectUrl('https://' . WebRequest::serverName() . WebRequest::requestUri()); |
|
138 | + |
|
139 | + return false; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + return true; |
|
144 | + } |
|
145 | + |
|
146 | + protected abstract function providerSpecificSetup(); |
|
147 | + |
|
148 | + protected function setupPartial() |
|
149 | + { |
|
150 | + $database = $this->getDatabase(); |
|
151 | + |
|
152 | + // default stuff |
|
153 | + $this->assign('alternatives', array()); // 'u2f' => array('U2F token'), 'otp' => array('TOTP', 'scratch', 'yubiotp'))); |
|
154 | + |
|
155 | + // is this stage one? |
|
156 | + list($partialId, $partialStage) = WebRequest::getAuthPartialLogin(); |
|
157 | + if ($partialStage === null || $partialId === null) { |
|
158 | + WebRequest::clearAuthPartialLogin(); |
|
159 | + } |
|
160 | + |
|
161 | + // Check to see if we have a partial login in progress |
|
162 | + $username = null; |
|
163 | + if ($partialId !== null) { |
|
164 | + // Yes, enforce this username |
|
165 | + $this->partialUser = User::getById($partialId, $database); |
|
166 | + $username = $this->partialUser->getUsername(); |
|
167 | + |
|
168 | + $this->setupAlternates($this->partialUser, $partialStage, $database); |
|
169 | + } |
|
170 | + else { |
|
171 | + // No, see if we've preloaded a username |
|
172 | + $preloadUsername = WebRequest::getString('tplUsername'); |
|
173 | + if ($preloadUsername !== null) { |
|
174 | + $username = $preloadUsername; |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + if ($partialStage === null) { |
|
179 | + $partialStage = 1; |
|
180 | + } |
|
181 | + |
|
182 | + $this->assign('partialStage', $partialStage); |
|
183 | + $this->assign('username', $username); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Redirect the user back to wherever they came from after a successful login |
|
188 | + * |
|
189 | + * @param User $user |
|
190 | + */ |
|
191 | + protected function goBackWhenceYouCame(User $user) |
|
192 | + { |
|
193 | + // Redirect to wherever the user came from |
|
194 | + $redirectDestination = WebRequest::clearPostLoginRedirect(); |
|
195 | + if ($redirectDestination !== null) { |
|
196 | + $this->redirectUrl($redirectDestination); |
|
197 | + } |
|
198 | + else { |
|
199 | + if ($user->isNewUser()) { |
|
200 | + // home page isn't allowed, go to preferences instead |
|
201 | + $this->redirect('preferences'); |
|
202 | + } |
|
203 | + else { |
|
204 | + // go to the home page |
|
205 | + $this->redirect(''); |
|
206 | + } |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + private function processLoginSuccess(User $user) |
|
211 | + { |
|
212 | + // Touch force logout |
|
213 | + $user->setForceLogout(false); |
|
214 | + $user->save(); |
|
215 | + |
|
216 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), |
|
217 | + $this->getSiteConfiguration()); |
|
218 | + |
|
219 | + if ($oauth->isFullyLinked()) { |
|
220 | + try { |
|
221 | + // Reload the user's identity ticket. |
|
222 | + $oauth->refreshIdentity(); |
|
223 | + |
|
224 | + // Check for blocks |
|
225 | + if ($oauth->getIdentity()->getBlocked()) { |
|
226 | + // blocked! |
|
227 | + SessionAlert::error("You are currently blocked on-wiki. You will not be able to log in until you are unblocked."); |
|
228 | + $this->redirect('login'); |
|
229 | + |
|
230 | + return; |
|
231 | + } |
|
232 | + } |
|
233 | + catch (OAuthException $ex) { |
|
234 | + // Oops. Refreshing ticket failed. Force a re-auth. |
|
235 | + $authoriseUrl = $oauth->getRequestToken(); |
|
236 | + WebRequest::setOAuthPartialLogin($user); |
|
237 | + $this->redirectUrl($authoriseUrl); |
|
238 | + |
|
239 | + return; |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + if (($this->getSiteConfiguration()->getEnforceOAuth() && !$oauth->isFullyLinked()) |
|
244 | + || $oauth->isPartiallyLinked() |
|
245 | + ) { |
|
246 | + $authoriseUrl = $oauth->getRequestToken(); |
|
247 | + WebRequest::setOAuthPartialLogin($user); |
|
248 | + $this->redirectUrl($authoriseUrl); |
|
249 | + |
|
250 | + return; |
|
251 | + } |
|
252 | + |
|
253 | + WebRequest::setLoggedInUser($user); |
|
254 | + |
|
255 | + $this->goBackWhenceYouCame($user); |
|
256 | + } |
|
257 | + |
|
258 | + protected abstract function getProviderCredentials(); |
|
259 | + |
|
260 | + /** |
|
261 | + * @param User $user |
|
262 | + * @param int $partialStage |
|
263 | + * @param PdoDatabase $database |
|
264 | + * |
|
265 | + * @throws ApplicationLogicException |
|
266 | + */ |
|
267 | + private function processJumpNextStage(User $user, $partialStage, PdoDatabase $database) |
|
268 | + { |
|
269 | + WebRequest::setAuthPartialLogin($user->getId(), $partialStage + 1); |
|
270 | + |
|
271 | + $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0 ORDER BY priority'; |
|
272 | + $statement = $database->prepare($sql); |
|
273 | + $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage + 1)); |
|
274 | + $nextStage = $statement->fetchColumn(); |
|
275 | + $statement->closeCursor(); |
|
276 | + |
|
277 | + if (!isset($this->nextPageMap[$nextStage])) { |
|
278 | + throw new ApplicationLogicException('Unknown page handler for next authentication stage.'); |
|
279 | + } |
|
280 | + |
|
281 | + $this->redirect("login/" . $this->nextPageMap[$nextStage]); |
|
282 | + } |
|
283 | + |
|
284 | + private function setupAlternates(User $user, $partialStage, PdoDatabase $database) |
|
285 | + { |
|
286 | + // get the providers available |
|
287 | + $sql = 'SELECT type FROM credential WHERE user = :user AND factor = :stage AND disabled = 0'; |
|
288 | + $statement = $database->prepare($sql); |
|
289 | + $statement->execute(array(':user' => $user->getId(), ':stage' => $partialStage)); |
|
290 | + $alternates = $statement->fetchAll(PDO::FETCH_COLUMN); |
|
291 | + |
|
292 | + $types = array(); |
|
293 | + foreach ($alternates as $item) { |
|
294 | + $type = $this->nextPageMap[$item]; |
|
295 | + if (!isset($types[$type])) { |
|
296 | + $types[$type] = array(); |
|
297 | + } |
|
298 | + |
|
299 | + $types[$type][] = $item; |
|
300 | + } |
|
301 | + |
|
302 | + $userOptions = array(); |
|
303 | + if (get_called_class() === PageOtpLogin::class) { |
|
304 | + $userOptions = $this->setupUserOptionsForType($types, 'u2f', $userOptions); |
|
305 | + } |
|
306 | + |
|
307 | + if (get_called_class() === PageU2FLogin::class) { |
|
308 | + $userOptions = $this->setupUserOptionsForType($types, 'otp', $userOptions); |
|
309 | + } |
|
310 | + |
|
311 | + $this->assign('alternatives', $userOptions); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * @param $types |
|
316 | + * @param $type |
|
317 | + * @param $userOptions |
|
318 | + * |
|
319 | + * @return mixed |
|
320 | + */ |
|
321 | + private function setupUserOptionsForType($types, $type, $userOptions) |
|
322 | + { |
|
323 | + if (isset($types[$type])) { |
|
324 | + $options = $types[$type]; |
|
325 | + |
|
326 | + array_walk($options, function(&$val) { |
|
327 | + $val = $this->names[$val]; |
|
328 | + }); |
|
329 | + |
|
330 | + $userOptions[$type] = $options; |
|
331 | + } |
|
332 | + |
|
333 | + return $userOptions; |
|
334 | + } |
|
335 | 335 | } |
@@ -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 |
@@ -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 | } |