Index: branches/ApiEdit_Vodafone/includes/SpecialUserlogin.php |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | * constructor |
10 | 10 | */ |
11 | 11 | function wfSpecialUserlogin() { |
| 12 | + |
12 | 13 | global $wgRequest; |
13 | 14 | if( session_id() == '' ) { |
14 | 15 | wfSetupSession(); |
— | — | @@ -23,16 +24,40 @@ |
24 | 25 | */ |
25 | 26 | class LoginForm { |
26 | 27 | |
27 | | - const SUCCESS = 0; |
28 | | - const NO_NAME = 1; |
29 | | - const ILLEGAL = 2; |
30 | | - const WRONG_PLUGIN_PASS = 3; |
31 | | - const NOT_EXISTS = 4; |
32 | | - const WRONG_PASS = 5; |
33 | | - const EMPTY_PASS = 6; |
34 | | - const RESET_PASS = 7; |
35 | | - const ABORTED = 8; |
36 | | - |
| 28 | + const SUCCESS = 0; |
| 29 | + const NO_NAME = 1; |
| 30 | + const ILLEGAL = 2; |
| 31 | + const WRONG_PLUGIN_PASS = 3; |
| 32 | + const NOT_EXISTS = 4; |
| 33 | + const WRONG_PASS = 5; |
| 34 | + const EMPTY_PASS = 6; |
| 35 | + const RESET_PASS = 7; |
| 36 | + const ABORTED = 8; |
| 37 | + const COOKIE = 9; |
| 38 | + const NOCOOKIE = 10; |
| 39 | + const READ_ONLY = 11; |
| 40 | + const NOT_ALLOWED = 12; |
| 41 | + const SORBS = 13; |
| 42 | + const USER_EXISTS = 14; |
| 43 | + const BAD_RETYPE = 15; |
| 44 | + const TOO_SHORT = 16; |
| 45 | + const ABORT_ERROR = 17; |
| 46 | + const DB_ERROR = 18; |
| 47 | + const NO_EMAIL = 19; |
| 48 | + const MAIL_ERROR = 20; |
| 49 | + const ACCMAILTEXT = 21; |
| 50 | + const PASSWORD_SENT = 22; |
| 51 | + const PASSWORD_REMINDER_THROTTLED = 23; |
| 52 | + const NO_SUCH_USER = 24; |
| 53 | + const RATE_LIMITED = 25; |
| 54 | + const MAILPASSWORD_BLOCKED = 26; |
| 55 | + const RESETPASS_FORBIDDEN = 27; |
| 56 | + const NO_COOKIES_NEW = 28; |
| 57 | + const NO_COOKIES_LOGIN = 29; |
| 58 | + const ERROR = 30; |
| 59 | + const SUCCESFUL_LOGIN = 31; |
| 60 | + |
| 61 | + |
37 | 62 | var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted; |
38 | 63 | var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword; |
39 | 64 | var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage; |
— | — | @@ -51,6 +76,8 @@ |
52 | 77 | $this->mRetype = $request->getText( 'wpRetype' ); |
53 | 78 | $this->mDomain = $request->getText( 'wpDomain' ); |
54 | 79 | $this->mReturnTo = $request->getVal( 'returnto' ); |
| 80 | + |
| 81 | + // |
55 | 82 | $this->mCookieCheck = $request->getVal( 'wpCookieCheck' ); |
56 | 83 | $this->mPosted = $request->wasPosted(); |
57 | 84 | $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' ); |
— | — | @@ -86,16 +113,22 @@ |
87 | 114 | } |
88 | 115 | |
89 | 116 | function execute() { |
| 117 | + $resultDetails = null; |
| 118 | + $value = null; |
| 119 | + |
90 | 120 | if ( !is_null( $this->mCookieCheck ) ) { |
91 | | - $this->onCookieRedirectCheck( $this->mCookieCheck ); |
92 | | - return; |
| 121 | + $value = $this->onCookieRedirectCheck( $this->mCookieCheck, $resultDetails ); |
| 122 | + return $this->processRest($value, $resultDetails); |
93 | 123 | } else if( $this->mPosted ) { |
94 | 124 | if( $this->mCreateaccount ) { |
95 | | - return $this->addNewAccount(); |
| 125 | + $value = $this->addNewAccount($resultDetails); |
| 126 | + return $this->processRest($value,$resultDetails); |
96 | 127 | } else if ( $this->mCreateaccountMail ) { |
97 | | - return $this->addNewAccountMailPassword(); |
| 128 | + $value = $this->addNewAccountMailPassword($resultDetails); |
| 129 | + return $this->processRest($value,$resultDetails); |
98 | 130 | } else if ( $this->mMailmypassword ) { |
99 | | - return $this->mailPassword(); |
| 131 | + $value = $this->mailPassword($resultDetails); |
| 132 | + return $this->processRest($value,$resultDetails); |
100 | 133 | } else if ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) { |
101 | 134 | return $this->processLogin(); |
102 | 135 | } |
— | — | @@ -106,51 +139,46 @@ |
107 | 140 | /** |
108 | 141 | * @private |
109 | 142 | */ |
110 | | - function addNewAccountMailPassword() { |
| 143 | + function addNewAccountMailPassword(&$results) { |
111 | 144 | global $wgOut; |
112 | 145 | |
113 | 146 | if ('' == $this->mEmail) { |
114 | | - $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) ); |
115 | | - return; |
| 147 | + return self::NO_EMAIL; |
116 | 148 | } |
117 | 149 | |
118 | | - $u = $this->addNewaccountInternal(); |
| 150 | + $u = $this->addNewaccountInternal($results); |
119 | 151 | |
120 | | - if ($u == NULL) { |
121 | | - return; |
| 152 | + if( !is_object($u) ) { |
| 153 | + return $u; |
122 | 154 | } |
123 | 155 | |
124 | 156 | // Wipe the initial password and mail a temporary one |
125 | 157 | $u->setPassword( null ); |
126 | 158 | $u->saveSettings(); |
127 | | - $result = $this->mailPasswordInternal( $u, false ); |
| 159 | + $results['error'] = $this->mailPasswordInternal( $u, false ); |
128 | 160 | |
129 | 161 | wfRunHooks( 'AddNewAccount', array( $u ) ); |
130 | 162 | |
131 | | - $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) ); |
132 | | - $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
133 | | - $wgOut->setArticleRelated( false ); |
134 | 163 | |
135 | | - if( WikiError::isError( $result ) ) { |
136 | | - $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) ); |
137 | | - } else { |
138 | | - $wgOut->addWikiText( wfMsg( 'accmailtext', $u->getName(), $u->getEmail() ) ); |
139 | | - $wgOut->returnToMain( false ); |
| 164 | + $results['user'] = $u; |
| 165 | + if( WikiError::isError( $results['error'] ) ) { |
| 166 | + return self::MAIL_ERROR; |
| 167 | + } else { |
| 168 | + return self::ACCMAILTEXT; |
140 | 169 | } |
141 | | - $u = 0; |
142 | 170 | } |
| 171 | + |
143 | 172 | |
144 | | - |
145 | 173 | /** |
146 | 174 | * @private |
147 | 175 | */ |
148 | | - function addNewAccount() { |
| 176 | + function addNewAccount(&$results) { |
149 | 177 | global $wgUser, $wgEmailAuthentication; |
150 | 178 | |
151 | 179 | # Create the account and abort if there's a problem doing so |
152 | | - $u = $this->addNewAccountInternal(); |
153 | | - if( $u == NULL ) |
154 | | - return; |
| 180 | + $u = $this->addNewAccountInternal($results); |
| 181 | + if( !is_object($u) ) |
| 182 | + return $u; |
155 | 183 | |
156 | 184 | # If we showed up language selection links, and one was in use, be |
157 | 185 | # smart (and sensible) and save that language as the user's preference |
— | — | @@ -162,11 +190,12 @@ |
163 | 191 | $u->saveSettings(); |
164 | 192 | if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) { |
165 | 193 | global $wgOut; |
166 | | - $error = $u->sendConfirmationMail(); |
167 | | - if( WikiError::isError( $error ) ) { |
168 | | - $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $error->getMessage() ) ); |
| 194 | + $results['error'] = $u->sendConfirmationMail(); |
| 195 | + $results['mailMsg'] = 0; |
| 196 | + if( WikiError::isError( $results['error'] ) ) { |
| 197 | + $results['mailMsg'] = 2; |
169 | 198 | } else { |
170 | | - $wgOut->addWikiText( wfMsg( 'confirmemail_oncreate' ) ); |
| 199 | + $results['mailMsg'] = 1; |
171 | 200 | } |
172 | 201 | } |
173 | 202 | |
— | — | @@ -177,37 +206,31 @@ |
178 | 207 | $wgUser->setCookies(); |
179 | 208 | wfRunHooks( 'AddNewAccount', array( $wgUser ) ); |
180 | 209 | if( $this->hasSessionCookie() ) { |
181 | | - return $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false ); |
| 210 | + return self::COOKIE; |
182 | 211 | } else { |
183 | | - return $this->cookieRedirectCheck( 'new' ); |
| 212 | + return self::NOCOOKIE; |
184 | 213 | } |
185 | 214 | } else { |
186 | 215 | # Confirm that the account was created |
187 | | - global $wgOut; |
188 | | - $self = SpecialPage::getTitleFor( 'Userlogin' ); |
189 | | - $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) ); |
190 | | - $wgOut->setArticleRelated( false ); |
191 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
192 | | - $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $u->getName() ) ); |
193 | | - $wgOut->returnToMain( $self->getPrefixedText() ); |
| 216 | + $results['user'] = $u; |
194 | 217 | wfRunHooks( 'AddNewAccount', array( $u ) ); |
195 | | - return true; |
| 218 | + return self::SUCCESS; |
196 | 219 | } |
197 | 220 | } |
198 | 221 | |
199 | 222 | /** |
200 | 223 | * @private |
201 | 224 | */ |
202 | | - function addNewAccountInternal() { |
| 225 | + function addNewAccountInternal(&$results) { |
203 | 226 | global $wgUser, $wgOut; |
204 | 227 | global $wgEnableSorbs, $wgProxyWhitelist; |
205 | 228 | global $wgMemc, $wgAccountCreationThrottle; |
206 | 229 | global $wgAuth, $wgMinimalPasswordLength; |
207 | | - |
| 230 | + |
208 | 231 | // If the user passes an invalid domain, something is fishy |
209 | 232 | if( !$wgAuth->validDomain( $this->mDomain ) ) { |
210 | | - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); |
211 | | - return false; |
| 233 | + return self::WRONG_PASS; |
| 234 | + |
212 | 235 | } |
213 | 236 | |
214 | 237 | // If we are not allowing users to login locally, we should |
— | — | @@ -218,51 +241,52 @@ |
219 | 242 | // domains that aren't local. |
220 | 243 | if( 'local' != $this->mDomain && '' != $this->mDomain ) { |
221 | 244 | if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName ) || !$wgAuth->authenticate( $this->mName, $this->mPassword ) ) ) { |
222 | | - $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); |
223 | | - return false; |
| 245 | + return self::WRONG_PASS; |
| 246 | + |
224 | 247 | } |
225 | 248 | } |
226 | 249 | |
227 | 250 | if ( wfReadOnly() ) { |
228 | | - $wgOut->readOnlyPage(); |
229 | | - return false; |
| 251 | + return self::READ_ONLY; |
| 252 | + |
230 | 253 | } |
231 | 254 | |
232 | 255 | # Check anonymous user ($wgUser) limitations : |
233 | 256 | if (!$wgUser->isAllowedToCreateAccount()) { |
234 | | - $this->userNotPrivilegedMessage(); |
235 | | - return false; |
| 257 | + return self::NOT_ALLOWED; |
| 258 | + |
236 | 259 | } |
237 | 260 | |
238 | 261 | $ip = wfGetIP(); |
239 | 262 | if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) && |
240 | 263 | $wgUser->inSorbsBlacklist( $ip ) ) |
241 | 264 | { |
242 | | - $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $ip ) . ')' ); |
243 | | - return; |
| 265 | + $results['ip'] = $ip; |
| 266 | + return self::SORBS; |
| 267 | + |
244 | 268 | } |
245 | 269 | |
246 | 270 | # Now create a dummy user ($u) and check if it is valid |
247 | 271 | $name = trim( $this->mName ); |
248 | 272 | $u = User::newFromName( $name, 'creatable' ); |
249 | 273 | if ( is_null( $u ) ) { |
250 | | - $this->mainLoginForm( wfMsg( 'noname' ) ); |
251 | | - return false; |
| 274 | + return self::NO_NAME; |
| 275 | + |
252 | 276 | } |
253 | 277 | |
254 | 278 | if ( 0 != $u->idForName() ) { |
255 | | - $this->mainLoginForm( wfMsg( 'userexists' ) ); |
256 | | - return false; |
| 279 | + return self::USER_EXISTS; |
| 280 | + |
257 | 281 | } |
258 | 282 | |
259 | 283 | if ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) { |
260 | | - $this->mainLoginForm( wfMsg( 'badretype' ) ); |
261 | | - return false; |
| 284 | + return self::BAD_RETYPE; |
| 285 | + |
262 | 286 | } |
263 | 287 | |
264 | 288 | if ( !$u->isValidPassword( $this->mPassword ) ) { |
265 | | - $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) ); |
266 | | - return false; |
| 289 | + return self::TOO_SHORT; |
| 290 | + |
267 | 291 | } |
268 | 292 | |
269 | 293 | # Set some additional data so the AbortNewAccount hook can be |
— | — | @@ -271,11 +295,12 @@ |
272 | 296 | $u->setRealName( $this->mRealName ); |
273 | 297 | |
274 | 298 | $abortError = ''; |
275 | | - if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) { |
| 299 | + if( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) { |
276 | 300 | // Hook point to add extra creation throttles and blocks |
277 | 301 | wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" ); |
278 | | - $this->mainLoginForm( $abortError ); |
279 | | - return false; |
| 302 | + $results['error'] = $abortError; |
| 303 | + return self::ABORT_ERROR; |
| 304 | + |
280 | 305 | } |
281 | 306 | |
282 | 307 | if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) { |
— | — | @@ -285,14 +310,14 @@ |
286 | 311 | $wgMemc->set( $key, 1, 86400 ); |
287 | 312 | } |
288 | 313 | if ( $value > $wgAccountCreationThrottle ) { |
289 | | - $this->throttleHit( $wgAccountCreationThrottle ); |
290 | | - return false; |
| 314 | + |
| 315 | + return self::ILLEGAL; |
291 | 316 | } |
292 | 317 | } |
293 | 318 | |
294 | 319 | if( !$wgAuth->addUser( $u, $this->mPassword, $this->mEmail, $this->mRealName ) ) { |
295 | | - $this->mainLoginForm( wfMsg( 'externaldberror' ) ); |
296 | | - return false; |
| 320 | + return self::DB_ERROR; |
| 321 | + |
297 | 322 | } |
298 | 323 | |
299 | 324 | return $this->initUser( $u, false ); |
— | — | @@ -419,6 +444,116 @@ |
420 | 445 | return $retval; |
421 | 446 | } |
422 | 447 | |
| 448 | + function processRest($value,$results = null) { |
| 449 | + global $wgUser, $wgAuth, $wgOut; |
| 450 | + if ($results['mailMsg'] == 1) { |
| 451 | + $wgOut->addWikiText( wfMsg( 'confirmemail_oncreate' ) ); |
| 452 | + } else if ($results['mailMsg'] == 2) { |
| 453 | + $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $results['error']->getMessage() ) ); |
| 454 | + } |
| 455 | + switch ($value) |
| 456 | + { |
| 457 | + case self::SUCCESS: |
| 458 | + $self = SpecialPage::getTitleFor( 'Userlogin' ); |
| 459 | + $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) ); |
| 460 | + $wgOut->setArticleRelated( false ); |
| 461 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 462 | + $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $this->mName ) ); |
| 463 | + $wgOut->returnToMain( $self->getPrefixedText() ); |
| 464 | + break; |
| 465 | + |
| 466 | + case self::COOKIE: |
| 467 | + $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false ); |
| 468 | + break; |
| 469 | + case self::NOCOOKIE: |
| 470 | + $this->cookieRedirectCheck( 'new' ); |
| 471 | + break; |
| 472 | + case self::WRONG_PASS : |
| 473 | + $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); |
| 474 | + break; |
| 475 | + case self::READ_ONLY: |
| 476 | + $wgOut->readOnlyPage(); |
| 477 | + break; |
| 478 | + case self::NOT_ALLOWED: |
| 479 | + $this->userNotPrivilegedMessage(); |
| 480 | + break; |
| 481 | + case self::SORBS: |
| 482 | + $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $results['ip'] ) . ')' ); |
| 483 | + break; |
| 484 | + case self::NO_NAME: |
| 485 | + $this->mainLoginForm( wfMsg( 'noname' ) ); |
| 486 | + break; |
| 487 | + case self::USER_EXISTS: |
| 488 | + $this->mainLoginForm( wfMsg( 'userexists' ) ); |
| 489 | + break; |
| 490 | + case self::BAD_RETYPE: |
| 491 | + $this->mainLoginForm( wfMsg( 'badretype' ) ); |
| 492 | + break; |
| 493 | + case self::TOO_SHORT: |
| 494 | + $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) ); |
| 495 | + break; |
| 496 | + case self::ABORT_ERROR: |
| 497 | + $this->mainLoginForm( $results['error'] ); |
| 498 | + break; |
| 499 | + case self::DB_ERROR: |
| 500 | + $this->mainLoginForm( wfMsg( 'externaldberror' ) ); |
| 501 | + break; |
| 502 | + case self::NO_EMAIL: |
| 503 | + $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) ); |
| 504 | + break; |
| 505 | + case self::MAIL_ERROR: |
| 506 | + $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) ); |
| 507 | + $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
| 508 | + $wgOut->setArticleRelated( false ); |
| 509 | + $this->mainLoginForm( wfMsg( 'mailerror', $results['error']->getMessage() ) ); |
| 510 | + break; |
| 511 | + case self::ACCMAILTEXT: |
| 512 | + $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) ); |
| 513 | + $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
| 514 | + $wgOut->setArticleRelated( false ); |
| 515 | + $wgOut->addWikiText( wfMsg( 'accmailtext', $results['user']->getName(), $results['user']->getEmail() ) ); |
| 516 | + $wgOut->returnToMain( false ); |
| 517 | + break; |
| 518 | + case self::ILLEGAL: |
| 519 | + $this->throttleHit( $wgAccountCreationThrottle ); |
| 520 | + break; |
| 521 | + case self::PASSWORD_SENT: |
| 522 | + $this->mainLoginForm( wfMsg( 'passwordsent', $results['user']->getName() ), 'success' ); |
| 523 | + break; |
| 524 | + case self::PASSWORD_REMINDER_THROTTLED: |
| 525 | + global $wgPasswordReminderResendTime; |
| 526 | + # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds. |
| 527 | + $this->mainLoginForm( wfMsg( 'throttled-mailpassword', round( $wgPasswordReminderResendTime, 3 ) ) ); |
| 528 | + break; |
| 529 | + case self::NO_SUCH_USER: |
| 530 | + $this->mainLoginForm( wfMsg( 'nosuchuser', $results['user']->getName() ) ); |
| 531 | + break; |
| 532 | + case self::RATE_LIMITED: |
| 533 | + $wgOut->rateLimited(); |
| 534 | + break; |
| 535 | + case self::MAILPASSWORD_BLOCKED: |
| 536 | + $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) ); |
| 537 | + break; |
| 538 | + case self::RESETPASS_FORBIDDEN: |
| 539 | + $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) ); |
| 540 | + break; |
| 541 | + case self::NO_COOKIES_NEW: |
| 542 | + $this->mainLoginForm( wfMsg( 'nocookiesnew' ) ); |
| 543 | + break; |
| 544 | + case self::NO_COOKIES_LOGIN: |
| 545 | + $this->mainLoginForm( wfMsg( 'nocookieslogin' ) ); |
| 546 | + break; |
| 547 | + case self::ERROR: |
| 548 | + $this->mainLoginForm( wfMsg( 'error' ) ); |
| 549 | + break; |
| 550 | + case self::LOGIN_SUCCESS: |
| 551 | + $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) ); |
| 552 | + break; |
| 553 | + default: |
| 554 | + wfDebugDieBacktrace( "Unhandled case value" ); |
| 555 | + } |
| 556 | + } |
| 557 | + |
423 | 558 | function processLogin() { |
424 | 559 | global $wgUser, $wgAuth; |
425 | 560 | |
— | — | @@ -475,55 +610,53 @@ |
476 | 611 | /** |
477 | 612 | * @private |
478 | 613 | */ |
479 | | - function mailPassword() { |
| 614 | + function mailPassword(&$results){ |
480 | 615 | global $wgUser, $wgOut, $wgAuth; |
481 | 616 | |
482 | 617 | if( !$wgAuth->allowPasswordChange() ) { |
483 | | - $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) ); |
484 | | - return; |
| 618 | + return self::RESETPASS_FORBIDDEN; |
| 619 | + |
485 | 620 | } |
486 | 621 | |
487 | 622 | # Check against blocked IPs |
488 | 623 | # fixme -- should we not? |
489 | 624 | if( $wgUser->isBlocked() ) { |
490 | | - $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) ); |
491 | | - return; |
| 625 | + return self::MAILPASSWORD_BLOCKED; |
| 626 | + |
492 | 627 | } |
493 | 628 | |
494 | 629 | # Check against the rate limiter |
495 | 630 | if( $wgUser->pingLimiter( 'mailpassword' ) ) { |
496 | | - $wgOut->rateLimited(); |
497 | | - return; |
| 631 | + return self::RATE_LIMITED; |
| 632 | + |
498 | 633 | } |
499 | 634 | |
500 | 635 | if ( '' == $this->mName ) { |
501 | | - $this->mainLoginForm( wfMsg( 'noname' ) ); |
502 | | - return; |
| 636 | + return self::NO_NAME; |
| 637 | + |
503 | 638 | } |
504 | 639 | $u = User::newFromName( $this->mName ); |
505 | 640 | if( is_null( $u ) ) { |
506 | | - $this->mainLoginForm( wfMsg( 'noname' ) ); |
507 | | - return; |
| 641 | + return self::NO_NAME; |
| 642 | + |
508 | 643 | } |
509 | 644 | if ( 0 == $u->getID() ) { |
510 | | - $this->mainLoginForm( wfMsg( 'nosuchuser', $u->getName() ) ); |
511 | | - return; |
| 645 | + $results['user']=$u; |
| 646 | + return self::NO_SUCH_USER; |
| 647 | + |
512 | 648 | } |
513 | 649 | |
514 | 650 | # Check against password throttle |
515 | 651 | if ( $u->isPasswordReminderThrottled() ) { |
516 | | - global $wgPasswordReminderResendTime; |
517 | | - # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds. |
518 | | - $this->mainLoginForm( wfMsg( 'throttled-mailpassword', |
519 | | - round( $wgPasswordReminderResendTime, 3 ) ) ); |
520 | | - return; |
| 652 | + return self::PASSWORD_REMINDER_THROTTLED; |
521 | 653 | } |
522 | 654 | |
523 | | - $result = $this->mailPasswordInternal( $u, true ); |
524 | | - if( WikiError::isError( $result ) ) { |
525 | | - $this->mainLoginForm( wfMsg( 'mailerror', $result->getMessage() ) ); |
| 655 | + $results['error'] = $this->mailPasswordInternal( $u, true ); |
| 656 | + $results['user'] = $u; |
| 657 | + if( WikiError::isError( $results['error'] ) ) { |
| 658 | + return self::MAIL_ERROR; |
526 | 659 | } else { |
527 | | - $this->mainLoginForm( wfMsg( 'passwordsent', $u->getName() ), 'success' ); |
| 660 | + return self::PASSWORD_SENT; |
528 | 661 | } |
529 | 662 | } |
530 | 663 | |
— | — | @@ -756,20 +889,20 @@ |
757 | 890 | /** |
758 | 891 | * @private |
759 | 892 | */ |
760 | | - function onCookieRedirectCheck( $type ) { |
| 893 | + function onCookieRedirectCheck( $type, &$results ) { |
761 | 894 | global $wgUser; |
762 | 895 | |
763 | 896 | if ( !$this->hasSessionCookie() ) { |
764 | 897 | if ( $type == 'new' ) { |
765 | | - return $this->mainLoginForm( wfMsg( 'nocookiesnew' ) ); |
| 898 | + return self::NO_COOKIES_NEW; |
766 | 899 | } else if ( $type == 'login' ) { |
767 | | - return $this->mainLoginForm( wfMsg( 'nocookieslogin' ) ); |
| 900 | + return self::NO_COOKIES_LOGIN; |
768 | 901 | } else { |
769 | | - # shouldn't happen |
770 | | - return $this->mainLoginForm( wfMsg( 'error' ) ); |
| 902 | + # shouldn't happen |
| 903 | + return self::ERROR; |
771 | 904 | } |
772 | 905 | } else { |
773 | | - return $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) ); |
| 906 | + return self::LOGIN_SUCCESS; |
774 | 907 | } |
775 | 908 | } |
776 | 909 | |
Index: branches/ApiEdit_Vodafone/includes/api/ApiRegUser.php |
— | — | @@ -0,0 +1,230 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/*
|
| 5 | + * Created on Aug 1, 2007
|
| 6 | + *
|
| 7 | + * API for MediaWiki 1.8+
|
| 8 | + *
|
| 9 | + * Copyright (C) 2007 Jesus Velez
|
| 10 | + *
|
| 11 | + * This program is free software; you can redistribute it and/or modify
|
| 12 | + * it under the terms of the GNU General Public License as published by
|
| 13 | + * the Free Software Foundation; either version 2 of the License, or
|
| 14 | + * (at your option) any later version.
|
| 15 | + *
|
| 16 | + * This program is distributed in the hope that it will be useful,
|
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 19 | + * GNU General Public License for more details.
|
| 20 | + *
|
| 21 | + * You should have received a copy of the GNU General Public License along
|
| 22 | + * with this program; if not, write to the Free Software Foundation, Inc.,
|
| 23 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 24 | + * http://www.gnu.org/copyleft/gpl.html
|
| 25 | + */
|
| 26 | +
|
| 27 | +if (!defined('MEDIAWIKI')) {
|
| 28 | + // Eclipse helper - will be ignored in production
|
| 29 | + require_once ("ApiBase.php");
|
| 30 | +}
|
| 31 | +
|
| 32 | +
|
| 33 | +/**
|
| 34 | + * A module to register new user accounts.
|
| 35 | + *
|
| 36 | + * @addtogroup API
|
| 37 | + */
|
| 38 | +class ApiRegUser extends ApiBase {
|
| 39 | +
|
| 40 | + const GET_CAPTCHA = -1;
|
| 41 | + const MISSING_CAPTCHA = -2;
|
| 42 | +
|
| 43 | + public function __construct($query, $moduleName) {
|
| 44 | + parent :: __construct($query, $moduleName, 'ru');
|
| 45 | + }
|
| 46 | +
|
| 47 | +
|
| 48 | +
|
| 49 | + public function process($value,$results = null) {
|
| 50 | + switch ($value) {
|
| 51 | + case ApiRegUser::GET_CAPTCHA :
|
| 52 | + $myCaptcha = new FancyCaptcha();
|
| 53 | + $myCaptcha->storage->clearAll();
|
| 54 | + $result['result'] = 'CaptchaIdGenerated';
|
| 55 | + $myCaptcha->getXML($result);
|
| 56 | + break;
|
| 57 | + case ApiRegUser::MISSING_CAPTCHA :
|
| 58 | + $myCaptcha = new FancyCaptcha();
|
| 59 | + $myCaptcha->storage->clearAll();
|
| 60 | + $result['result'] = 'MissingCaptcha';
|
| 61 | + $myCaptcha->getXML($result);
|
| 62 | + break;
|
| 63 | + case LoginForm::SUCCESS :
|
| 64 | + $result['result'] = 'Success';
|
| 65 | + break;
|
| 66 | + case LoginForm::COOKIE :
|
| 67 | + $result['result'] = 'Logged';
|
| 68 | + $result['userid'] = $_SESSION['wsUserID'];
|
| 69 | + $result['username'] = $_SESSION['wsUserName'];
|
| 70 | + $result['token'] = $_SESSION['wsToken'];
|
| 71 | + break;
|
| 72 | + case LoginForm::NOCOOKIE :
|
| 73 | + $result['result'] = 'NoCookie';
|
| 74 | + $result['userid'] = $_SESSION['wsUserID'];
|
| 75 | + $result['username'] = $_SESSION['wsUserName'];
|
| 76 | + $result['token'] = $_SESSION['wsToken'];
|
| 77 | + break;
|
| 78 | + case LoginForm::WRONG_PASS :
|
| 79 | + $result['result'] = 'WrongPassword';
|
| 80 | + break;
|
| 81 | + case LoginForm::READ_ONLY :
|
| 82 | + $result['result'] = 'ReadOnly';
|
| 83 | + break;
|
| 84 | + case LoginForm::NOT_ALLOWED :
|
| 85 | + $result['result'] = 'NotAllowed';
|
| 86 | + break;
|
| 87 | + case LoginForm::SORBS :
|
| 88 | + $result['result'] = 'Sorbs';
|
| 89 | + $result['blockedIp'] = $results['ip'];
|
| 90 | + break;
|
| 91 | + case LoginForm::NO_NAME :
|
| 92 | + $result['result'] = 'NoName';
|
| 93 | + break;
|
| 94 | + case LoginForm::USER_EXISTS :
|
| 95 | + $result['result'] = 'UserExists';
|
| 96 | + break;
|
| 97 | + case LoginForm::BAD_RETYPE :
|
| 98 | + $result['result'] = 'BadRetype';
|
| 99 | + break;
|
| 100 | + case LoginForm::TOO_SHORT :
|
| 101 | + $result['result'] = 'TooShort';
|
| 102 | + break;
|
| 103 | + case LoginForm::ABORT_ERROR :
|
| 104 | + $result['result'] = 'AbortError';
|
| 105 | + break;
|
| 106 | + case LoginForm::DB_ERROR :
|
| 107 | + $result['result'] = 'DbError';
|
| 108 | + break;
|
| 109 | + case LoginForm::NO_EMAIL :
|
| 110 | + $result['result'] = 'NoEmail';
|
| 111 | + break;
|
| 112 | + case LoginForm::MAIL_ERROR :
|
| 113 | + $result['result'] = 'MailError';
|
| 114 | + break;
|
| 115 | + case LoginForm::ACCMAILTEXT :
|
| 116 | + $result['result'] = 'AccMailText';
|
| 117 | + $result['userid'] = $_SESSION['wsUserID'];
|
| 118 | + $result['username'] = $_SESSION['wsUserName'];
|
| 119 | + $result['token'] = $_SESSION['wsToken'];
|
| 120 | + break;
|
| 121 | + default :
|
| 122 | + $result['result'] = 'Invalid';
|
| 123 | +
|
| 124 | + }
|
| 125 | + if ($results['mailMsg'] == 1) {
|
| 126 | + $result['confirmEmail'] = 'MailSent';
|
| 127 | + } else if ($results['mailMsg'] == 2) {
|
| 128 | + $result['confirmEmail'] = $results['error']->getMessage();
|
| 129 | + }
|
| 130 | + $this->getResult()->addValue(null, 'reguser', $result);
|
| 131 | + }
|
| 132 | +
|
| 133 | + public function checkCaptcha() {
|
| 134 | + global $wgHooks;
|
| 135 | + $i = 0;
|
| 136 | + $value = false;
|
| 137 | + while ($i < sizeof($wgHooks['UserCreateForm'])) {
|
| 138 | + if ($wgHooks['UserCreateForm'][$i][0] instanceof FancyCaptcha) $value = true;
|
| 139 | + $i++;
|
| 140 | + }
|
| 141 | + return $value;
|
| 142 | + }
|
| 143 | +
|
| 144 | + public function execute() {
|
| 145 | + global $wgRequest;
|
| 146 | +
|
| 147 | + $resultDetails = null;
|
| 148 | + $value = null;
|
| 149 | + if( session_id() == '' ) {
|
| 150 | + wfSetupSession();
|
| 151 | + }
|
| 152 | +
|
| 153 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
| 154 | + extract($this->extractRequestParams());
|
| 155 | + if ( (strlen($user) == 0) && (strlen($password) == 0) && ($this->checkCaptcha()) ) {
|
| 156 | + $value = ApiRegUser::GET_CAPTCHA;
|
| 157 | + } elseif ($this->checkCaptcha() && ($captchaid == 0)) {
|
| 158 | + $value = ApiRegUser::MISSING_CAPTCHA;
|
| 159 | + } else {
|
| 160 | + $data = array('wpName' => $user,
|
| 161 | + 'wpPassword' => $password,
|
| 162 | + 'wpRetype' => $password,
|
| 163 | + 'wpEmail' => $email,
|
| 164 | + 'wpRealName' => $name,
|
| 165 | + 'wpCaptchaWord' => $captchaword,
|
| 166 | + 'wpCaptchaId' => $captchaid,
|
| 167 | + 'wpDomain' => $domain);
|
| 168 | + $request = new FauxRequest($data);
|
| 169 | + $wgRequest = $request;
|
| 170 | + $form = new LoginForm( $request );
|
| 171 | + $value = $form->addNewAccount($resultDetails);
|
| 172 | + }
|
| 173 | + }
|
| 174 | + $this->process($value,$resultDetails);
|
| 175 | + }
|
| 176 | +
|
| 177 | + protected function getDescription() {
|
| 178 | + return 'Create new user account';
|
| 179 | + }
|
| 180 | +
|
| 181 | + protected function getExamples() {
|
| 182 | + return array (
|
| 183 | + "Create new user account using MediaWiki API",
|
| 184 | + " You must register using POST method."
|
| 185 | + );
|
| 186 | + }
|
| 187 | +
|
| 188 | + protected function getAllowedParams() {
|
| 189 | + return array (
|
| 190 | + 'user' => array(
|
| 191 | + ApiBase :: PARAM_TYPE => 'string'
|
| 192 | + ),
|
| 193 | + 'password' => array(
|
| 194 | + ApiBase :: PARAM_TYPE => 'string'
|
| 195 | + ),
|
| 196 | + 'email' => array(
|
| 197 | + ApiBase :: PARAM_TYPE => 'string'
|
| 198 | + ),
|
| 199 | + 'name' => array(
|
| 200 | + ApiBase :: PARAM_TYPE => 'string'
|
| 201 | + ),
|
| 202 | + 'captchaword' => array(
|
| 203 | + ApiBase :: PARAM_TYPE => 'string'
|
| 204 | + ),
|
| 205 | + 'captchaid' => array(
|
| 206 | + ApiBase :: PARAM_TYPE => 'string'
|
| 207 | + ),
|
| 208 | + 'domain' => array(
|
| 209 | + ApiBase :: PARAM_TYPE => 'string'
|
| 210 | + )
|
| 211 | +
|
| 212 | + );
|
| 213 | + }
|
| 214 | +
|
| 215 | + protected function getParamDescription() {
|
| 216 | + return array (
|
| 217 | + 'user' => 'user login name',
|
| 218 | + 'password' => 'user password',
|
| 219 | + 'email' => 'user email',
|
| 220 | + 'name' => 'user name',
|
| 221 | + 'domain' => 'domain',
|
| 222 | + 'captchaid' => 'question',
|
| 223 | + 'captchaword' => 'answer'
|
| 224 | + );
|
| 225 | + }
|
| 226 | +
|
| 227 | + public function getVersion() {
|
| 228 | + return __CLASS__ . ': $Id: ApiRegUser.php 22289 2007-05-20 23:31:44Z jvelezv $';
|
| 229 | + }
|
| 230 | +}
|
| 231 | +?>
|