Index: branches/ApiEdit_Vodafone/includes/SpecialUserlogin.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | * constructor |
10 | 10 | */ |
11 | 11 | function wfSpecialUserlogin() { |
12 | | - |
| 12 | + |
13 | 13 | global $wgRequest; |
14 | 14 | if( session_id() == '' ) { |
15 | 15 | wfSetupSession(); |
— | — | @@ -24,40 +24,40 @@ |
25 | 25 | */ |
26 | 26 | class LoginForm { |
27 | 27 | |
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 | | - |
| 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 | + |
62 | 62 | var $mName, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted; |
63 | 63 | var $mAction, $mCreateaccount, $mCreateaccountMail, $mMailmypassword; |
64 | 64 | var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage; |
— | — | @@ -76,8 +76,8 @@ |
77 | 77 | $this->mRetype = $request->getText( 'wpRetype' ); |
78 | 78 | $this->mDomain = $request->getText( 'wpDomain' ); |
79 | 79 | $this->mReturnTo = $request->getVal( 'returnto' ); |
80 | | - |
81 | | - // |
| 80 | + |
| 81 | + |
82 | 82 | $this->mCookieCheck = $request->getVal( 'wpCookieCheck' ); |
83 | 83 | $this->mPosted = $request->wasPosted(); |
84 | 84 | $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' ); |
— | — | @@ -113,21 +113,21 @@ |
114 | 114 | } |
115 | 115 | |
116 | 116 | function execute() { |
117 | | - $resultDetails = null; |
118 | | - $value = null; |
119 | | - |
| 117 | + $resultDetails = null; |
| 118 | + $value = null; |
| 119 | + |
120 | 120 | if ( !is_null( $this->mCookieCheck ) ) { |
121 | | - $value = $this->onCookieRedirectCheck( $this->mCookieCheck, $resultDetails ); |
122 | | - return $this->processRest($value, $resultDetails); |
| 121 | + $value = $this->onCookieRedirectCheck( $this->mCookieCheck, $resultDetails ); |
| 122 | + return $this->processRest($value, $resultDetails); |
123 | 123 | } else if( $this->mPosted ) { |
124 | 124 | if( $this->mCreateaccount ) { |
125 | | - $value = $this->addNewAccount($resultDetails); |
| 125 | + $value = $this->addNewAccount($resultDetails); |
126 | 126 | return $this->processRest($value,$resultDetails); |
127 | 127 | } else if ( $this->mCreateaccountMail ) { |
128 | | - $value = $this->addNewAccountMailPassword($resultDetails); |
| 128 | + $value = $this->addNewAccountMailPassword($resultDetails); |
129 | 129 | return $this->processRest($value,$resultDetails); |
130 | 130 | } else if ( $this->mMailmypassword ) { |
131 | | - $value = $this->mailPassword($resultDetails); |
| 131 | + $value = $this->mailPassword($resultDetails); |
132 | 132 | return $this->processRest($value,$resultDetails); |
133 | 133 | } else if ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) { |
134 | 134 | return $this->processLogin(); |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | global $wgOut; |
145 | 145 | |
146 | 146 | if ('' == $this->mEmail) { |
147 | | - return self::NO_EMAIL; |
| 147 | + return self::NO_EMAIL; |
148 | 148 | } |
149 | 149 | |
150 | 150 | $u = $this->addNewaccountInternal($results); |
— | — | @@ -159,15 +159,13 @@ |
160 | 160 | |
161 | 161 | wfRunHooks( 'AddNewAccount', array( $u ) ); |
162 | 162 | |
163 | | - |
164 | | - $results['user'] = $u; |
| 163 | + $results['user'] = $u; |
165 | 164 | if( WikiError::isError( $results['error'] ) ) { |
166 | | - return self::MAIL_ERROR; |
| 165 | + return self::MAIL_ERROR; |
167 | 166 | } else { |
168 | 167 | return self::ACCMAILTEXT; |
169 | 168 | } |
170 | 169 | } |
171 | | - |
172 | 170 | |
173 | 171 | /** |
174 | 172 | * @private |
— | — | @@ -191,11 +189,11 @@ |
192 | 190 | if( $wgEmailAuthentication && User::isValidEmailAddr( $u->getEmail() ) ) { |
193 | 191 | global $wgOut; |
194 | 192 | $results['error'] = $u->sendConfirmationMail(); |
195 | | - $results['mailMsg'] = 0; |
| 193 | + $results['mailMsg'] = 0; |
196 | 194 | if( WikiError::isError( $results['error'] ) ) { |
197 | | - $results['mailMsg'] = 2; |
| 195 | + $results['mailMsg'] = 2; |
198 | 196 | } else { |
199 | | - $results['mailMsg'] = 1; |
| 197 | + $results['mailMsg'] = 1; |
200 | 198 | } |
201 | 199 | } |
202 | 200 | |
— | — | @@ -208,11 +206,13 @@ |
209 | 207 | if( $this->hasSessionCookie() ) { |
210 | 208 | return self::COOKIE; |
211 | 209 | } else { |
212 | | - return self::NOCOOKIE; |
| 210 | + return self::NOCOOKIE; |
213 | 211 | } |
214 | 212 | } else { |
215 | 213 | # Confirm that the account was created |
216 | | - $results['user'] = $u; |
| 214 | + $results['user'] = $u; |
| 215 | + |
| 216 | + |
217 | 217 | wfRunHooks( 'AddNewAccount', array( $u ) ); |
218 | 218 | return self::SUCCESS; |
219 | 219 | } |
— | — | @@ -226,11 +226,10 @@ |
227 | 227 | global $wgEnableSorbs, $wgProxyWhitelist; |
228 | 228 | global $wgMemc, $wgAccountCreationThrottle; |
229 | 229 | global $wgAuth, $wgMinimalPasswordLength; |
230 | | - |
| 230 | + |
231 | 231 | // If the user passes an invalid domain, something is fishy |
232 | 232 | if( !$wgAuth->validDomain( $this->mDomain ) ) { |
233 | 233 | return self::WRONG_PASS; |
234 | | - |
235 | 234 | } |
236 | 235 | |
237 | 236 | // If we are not allowing users to login locally, we should |
— | — | @@ -242,26 +241,23 @@ |
243 | 242 | if( 'local' != $this->mDomain && '' != $this->mDomain ) { |
244 | 243 | if( !$wgAuth->canCreateAccounts() && ( !$wgAuth->userExists( $this->mName ) || !$wgAuth->authenticate( $this->mName, $this->mPassword ) ) ) { |
245 | 244 | return self::WRONG_PASS; |
246 | | - |
247 | 245 | } |
248 | 246 | } |
249 | 247 | |
250 | 248 | if ( wfReadOnly() ) { |
251 | 249 | return self::READ_ONLY; |
252 | | - |
253 | 250 | } |
254 | 251 | |
255 | 252 | # Check anonymous user ($wgUser) limitations : |
256 | 253 | if (!$wgUser->isAllowedToCreateAccount()) { |
257 | 254 | return self::NOT_ALLOWED; |
258 | | - |
259 | 255 | } |
260 | 256 | |
261 | 257 | $ip = wfGetIP(); |
262 | 258 | if ( $wgEnableSorbs && !in_array( $ip, $wgProxyWhitelist ) && |
263 | 259 | $wgUser->inSorbsBlacklist( $ip ) ) |
264 | 260 | { |
265 | | - $results['ip'] = $ip; |
| 261 | + $results['ip'] = $ip; |
266 | 262 | return self::SORBS; |
267 | 263 | |
268 | 264 | } |
— | — | @@ -447,108 +443,108 @@ |
448 | 444 | function processRest($value,$results = null) { |
449 | 445 | global $wgUser, $wgAuth, $wgOut; |
450 | 446 | 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 | | - } |
| 447 | + $wgOut->addWikiText( wfMsg( 'confirmemail_oncreate' ) ); |
| 448 | + } else if ($results['mailMsg'] == 2) { |
| 449 | + $wgOut->addWikiText( wfMsg( 'confirmemail_sendfailed', $results['error']->getMessage() ) ); |
| 450 | + } |
455 | 451 | switch ($value) |
456 | 452 | { |
457 | 453 | 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; |
| 454 | + $self = SpecialPage::getTitleFor( 'Userlogin' ); |
| 455 | + $wgOut->setPageTitle( wfMsgHtml( 'accountcreated' ) ); |
| 456 | + $wgOut->setArticleRelated( false ); |
| 457 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 458 | + $wgOut->addHtml( wfMsgWikiHtml( 'accountcreatedtext', $this->mName ) ); |
| 459 | + $wgOut->returnToMain( $self->getPrefixedText() ); |
| 460 | + break; |
465 | 461 | |
466 | 462 | case self::COOKIE: |
467 | 463 | $this->successfulLogin( wfMsg( 'welcomecreation', $wgUser->getName() ), false ); |
468 | 464 | break; |
469 | 465 | case self::NOCOOKIE: |
470 | 466 | $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; |
| 467 | + break; |
| 468 | + case self::WRONG_PASS : |
| 469 | + $this->mainLoginForm( wfMsg( 'wrongpassword' ) ); |
| 470 | + break; |
| 471 | + case self::READ_ONLY: |
| 472 | + $wgOut->readOnlyPage(); |
| 473 | + break; |
| 474 | + case self::NOT_ALLOWED: |
| 475 | + $this->userNotPrivilegedMessage(); |
| 476 | + break; |
| 477 | + case self::SORBS: |
| 478 | + $this->mainLoginForm( wfMsg( 'sorbs_create_account_reason' ) . ' (' . htmlspecialchars( $results['ip'] ) . ')' ); |
| 479 | + break; |
| 480 | + case self::NO_NAME: |
| 481 | + $this->mainLoginForm( wfMsg( 'noname' ) ); |
| 482 | + break; |
| 483 | + case self::USER_EXISTS: |
| 484 | + $this->mainLoginForm( wfMsg( 'userexists' ) ); |
| 485 | + break; |
| 486 | + case self::BAD_RETYPE: |
| 487 | + $this->mainLoginForm( wfMsg( 'badretype' ) ); |
| 488 | + break; |
| 489 | + case self::TOO_SHORT: |
| 490 | + $this->mainLoginForm( wfMsg( 'passwordtooshort', $wgMinimalPasswordLength ) ); |
| 491 | + break; |
| 492 | + case self::ABORT_ERROR: |
| 493 | + $this->mainLoginForm( $results['error'] ); |
| 494 | + break; |
| 495 | + case self::DB_ERROR: |
| 496 | + $this->mainLoginForm( wfMsg( 'externaldberror' ) ); |
| 497 | + break; |
| 498 | + case self::NO_EMAIL: |
| 499 | + $this->mainLoginForm( wfMsg( 'noemail', htmlspecialchars( $this->mName ) ) ); |
| 500 | + break; |
| 501 | + case self::MAIL_ERROR: |
| 502 | + $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) ); |
| 503 | + $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
| 504 | + $wgOut->setArticleRelated( false ); |
| 505 | + $this->mainLoginForm( wfMsg( 'mailerror', $results['error']->getMessage() ) ); |
| 506 | + break; |
| 507 | + case self::ACCMAILTEXT: |
| 508 | + $wgOut->setPageTitle( wfMsg( 'accmailtitle' ) ); |
| 509 | + $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
| 510 | + $wgOut->setArticleRelated( false ); |
| 511 | + $wgOut->addWikiText( wfMsg( 'accmailtext', $results['user']->getName(), $results['user']->getEmail() ) ); |
| 512 | + $wgOut->returnToMain( false ); |
| 513 | + break; |
| 514 | + case self::ILLEGAL: |
| 515 | + $this->throttleHit( $wgAccountCreationThrottle ); |
| 516 | + break; |
| 517 | + case self::PASSWORD_SENT: |
| 518 | + $this->mainLoginForm( wfMsg( 'passwordsent', $results['user']->getName() ), 'success' ); |
| 519 | + break; |
| 520 | + case self::PASSWORD_REMINDER_THROTTLED: |
| 521 | + global $wgPasswordReminderResendTime; |
| 522 | + # Round the time in hours to 3 d.p., in case someone is specifying minutes or seconds. |
| 523 | + $this->mainLoginForm( wfMsg( 'throttled-mailpassword', round( $wgPasswordReminderResendTime, 3 ) ) ); |
| 524 | + break; |
| 525 | + case self::NO_SUCH_USER: |
| 526 | + $this->mainLoginForm( wfMsg( 'nosuchuser', $results['user']->getName() ) ); |
| 527 | + break; |
| 528 | + case self::RATE_LIMITED: |
| 529 | + $wgOut->rateLimited(); |
| 530 | + break; |
| 531 | + case self::MAILPASSWORD_BLOCKED: |
| 532 | + $this->mainLoginForm( wfMsg( 'blocked-mailpassword' ) ); |
| 533 | + break; |
| 534 | + case self::RESETPASS_FORBIDDEN: |
| 535 | + $this->mainLoginForm( wfMsg( 'resetpass_forbidden' ) ); |
| 536 | + break; |
| 537 | + case self::NO_COOKIES_NEW: |
| 538 | + $this->mainLoginForm( wfMsg( 'nocookiesnew' ) ); |
| 539 | + break; |
| 540 | + case self::NO_COOKIES_LOGIN: |
| 541 | + $this->mainLoginForm( wfMsg( 'nocookieslogin' ) ); |
| 542 | + break; |
| 543 | + case self::ERROR: |
| 544 | + $this->mainLoginForm( wfMsg( 'error' ) ); |
| 545 | + break; |
| 546 | + case self::LOGIN_SUCCESS: |
| 547 | + $this->successfulLogin( wfMsg( 'loginsuccess', $wgUser->getName() ) ); |
| 548 | + break; |
553 | 549 | default: |
554 | 550 | wfDebugDieBacktrace( "Unhandled case value" ); |
555 | 551 | } |
— | — | @@ -641,7 +637,7 @@ |
642 | 638 | |
643 | 639 | } |
644 | 640 | if ( 0 == $u->getID() ) { |
645 | | - $results['user']=$u; |
| 641 | + $results['user']=$u; |
646 | 642 | return self::NO_SUCH_USER; |
647 | 643 | |
648 | 644 | } |
— | — | @@ -652,11 +648,11 @@ |
653 | 649 | } |
654 | 650 | |
655 | 651 | $results['error'] = $this->mailPasswordInternal( $u, true ); |
656 | | - $results['user'] = $u; |
| 652 | + $results['user'] = $u; |
657 | 653 | if( WikiError::isError( $results['error'] ) ) { |
658 | | - return self::MAIL_ERROR; |
| 654 | + return self::MAIL_ERROR; |
659 | 655 | } else { |
660 | | - return self::PASSWORD_SENT; |
| 656 | + return self::PASSWORD_SENT; |
661 | 657 | } |
662 | 658 | } |
663 | 659 | |
— | — | @@ -894,15 +890,15 @@ |
895 | 891 | |
896 | 892 | if ( !$this->hasSessionCookie() ) { |
897 | 893 | if ( $type == 'new' ) { |
898 | | - return self::NO_COOKIES_NEW; |
| 894 | + return self::NO_COOKIES_NEW; |
899 | 895 | } else if ( $type == 'login' ) { |
900 | | - return self::NO_COOKIES_LOGIN; |
| 896 | + return self::NO_COOKIES_LOGIN; |
901 | 897 | } else { |
902 | | - # shouldn't happen |
903 | | - return self::ERROR; |
| 898 | + # shouldn't happen |
| 899 | + return self::ERROR; |
904 | 900 | } |
905 | 901 | } else { |
906 | | - return self::LOGIN_SUCCESS; |
| 902 | + return self::LOGIN_SUCCESS; |
907 | 903 | } |
908 | 904 | } |
909 | 905 | |
Index: branches/ApiEdit_Vodafone/includes/api/ApiRegUser.php |
— | — | @@ -22,157 +22,154 @@ |
23 | 23 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
24 | 24 | * http://www.gnu.org/copyleft/gpl.html
|
25 | 25 | */
|
26 | | -
|
27 | | -if (!defined('MEDIAWIKI')) {
|
| 26 | +
|
| 27 | +if (!defined('MEDIAWIKI')) {
|
28 | 28 | // Eclipse helper - will be ignored in production
|
29 | | - require_once ("ApiBase.php");
|
| 29 | + require_once ("ApiBase.php");
|
30 | 30 | }
|
31 | | -
|
32 | 31 |
|
33 | 32 | /**
|
34 | 33 | * A module to register new user accounts.
|
35 | 34 | *
|
36 | 35 | * @addtogroup API
|
37 | 36 | */
|
38 | | -class ApiRegUser extends ApiBase {
|
| 37 | +class ApiRegUser extends ApiBase {
|
39 | 38 |
|
40 | | - const GET_CAPTCHA = -1;
|
41 | | - const MISSING_CAPTCHA = -2;
|
| 39 | + const GET_CAPTCHA = -1;
|
| 40 | + const MISSING_CAPTCHA = -2;
|
42 | 41 |
|
43 | 42 | public function __construct($query, $moduleName) {
|
44 | 43 | parent :: __construct($query, $moduleName, 'ru');
|
45 | 44 | }
|
46 | | -
|
47 | 45 |
|
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 | | - }
|
| 46 | + public function process($value,$results = null) {
|
| 47 | + switch ($value) {
|
| 48 | + case ApiRegUser::GET_CAPTCHA :
|
| 49 | + $myCaptcha = new FancyCaptcha();
|
| 50 | + $myCaptcha->storage->clearAll();
|
| 51 | + $result['result'] = 'CaptchaIdGenerated';
|
| 52 | + $myCaptcha->getXML($result);
|
| 53 | + break;
|
| 54 | + case ApiRegUser::MISSING_CAPTCHA :
|
| 55 | + $myCaptcha = new FancyCaptcha();
|
| 56 | + $myCaptcha->storage->clearAll();
|
| 57 | + $result['result'] = 'MissingCaptcha';
|
| 58 | + $myCaptcha->getXML($result);
|
| 59 | + break;
|
| 60 | + case LoginForm::SUCCESS :
|
| 61 | + $result['result'] = 'Success';
|
| 62 | + break;
|
| 63 | + case LoginForm::COOKIE :
|
| 64 | + $result['result'] = 'Logged';
|
| 65 | + $result['userid'] = $_SESSION['wsUserID'];
|
| 66 | + $result['username'] = $_SESSION['wsUserName'];
|
| 67 | + $result['token'] = $_SESSION['wsToken'];
|
| 68 | + break;
|
| 69 | + case LoginForm::NOCOOKIE :
|
| 70 | + $result['result'] = 'NoCookie';
|
| 71 | + $result['userid'] = $_SESSION['wsUserID'];
|
| 72 | + $result['username'] = $_SESSION['wsUserName'];
|
| 73 | + $result['token'] = $_SESSION['wsToken'];
|
| 74 | + break;
|
| 75 | + case LoginForm::WRONG_PASS :
|
| 76 | + $result['result'] = 'WrongPassword';
|
| 77 | + break;
|
| 78 | + case LoginForm::READ_ONLY :
|
| 79 | + $result['result'] = 'ReadOnly';
|
| 80 | + break;
|
| 81 | + case LoginForm::NOT_ALLOWED :
|
| 82 | + $result['result'] = 'NotAllowed';
|
| 83 | + break;
|
| 84 | + case LoginForm::SORBS :
|
| 85 | + $result['result'] = 'Sorbs';
|
| 86 | + $result['blockedIp'] = $results['ip'];
|
| 87 | + break;
|
| 88 | + case LoginForm::NO_NAME :
|
| 89 | + $result['result'] = 'NoName';
|
| 90 | + break;
|
| 91 | + case LoginForm::USER_EXISTS :
|
| 92 | + $result['result'] = 'UserExists';
|
| 93 | + break;
|
| 94 | + case LoginForm::BAD_RETYPE :
|
| 95 | + $result['result'] = 'BadRetype';
|
| 96 | + break;
|
| 97 | + case LoginForm::TOO_SHORT :
|
| 98 | + $result['result'] = 'TooShort';
|
| 99 | + break;
|
| 100 | + case LoginForm::ABORT_ERROR :
|
| 101 | + $result['result'] = 'AbortError';
|
| 102 | + break;
|
| 103 | + case LoginForm::DB_ERROR :
|
| 104 | + $result['result'] = 'DbError';
|
| 105 | + break;
|
| 106 | + case LoginForm::NO_EMAIL :
|
| 107 | + $result['result'] = 'NoEmail';
|
| 108 | + break;
|
| 109 | + case LoginForm::MAIL_ERROR :
|
| 110 | + $result['result'] = 'MailError';
|
| 111 | + break;
|
| 112 | + case LoginForm::ACCMAILTEXT :
|
| 113 | + $result['result'] = 'AccMailText';
|
| 114 | + $result['userid'] = $_SESSION['wsUserID'];
|
| 115 | + $result['username'] = $_SESSION['wsUserName'];
|
| 116 | + $result['token'] = $_SESSION['wsToken'];
|
| 117 | + break;
|
| 118 | + default :
|
| 119 | + $result['result'] = 'Invalid';
|
143 | 120 |
|
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);
|
| 121 | + }
|
| 122 | + if ($results['mailMsg'] == 1) {
|
| 123 | + $result['confirmEmail'] = 'MailSent';
|
| 124 | + } else if ($results['mailMsg'] == 2) {
|
| 125 | + $result['confirmEmail'] = $results['error']->getMessage();
|
| 126 | + }
|
| 127 | + $this->getResult()->addValue(null, 'reguser', $result);
|
175 | 128 | }
|
176 | 129 |
|
| 130 | + public function checkCaptcha() {
|
| 131 | + global $wgHooks;
|
| 132 | + $i = 0;
|
| 133 | + $value = false;
|
| 134 | + while ($i < sizeof($wgHooks['UserCreateForm'])) {
|
| 135 | + if ($wgHooks['UserCreateForm'][$i][0] instanceof FancyCaptcha) $value = true;
|
| 136 | + $i++;
|
| 137 | + }
|
| 138 | + return $value;
|
| 139 | + }
|
| 140 | +
|
| 141 | + public function execute() {
|
| 142 | + global $wgRequest;
|
| 143 | +
|
| 144 | + $resultDetails = null;
|
| 145 | + $value = null;
|
| 146 | + if( session_id() == '' ) {
|
| 147 | + wfSetupSession();
|
| 148 | + }
|
| 149 | +
|
| 150 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
| 151 | + extract($this->extractRequestParams());
|
| 152 | + if ( (strlen($user) == 0) && (strlen($password) == 0) && ($this->checkCaptcha()) ) {
|
| 153 | + $value = ApiRegUser::GET_CAPTCHA;
|
| 154 | + } elseif ($this->checkCaptcha() && ($captchaid == 0)) {
|
| 155 | + $value = ApiRegUser::MISSING_CAPTCHA;
|
| 156 | + } else {
|
| 157 | + $data = array('wpName' => $user,
|
| 158 | + 'wpPassword' => $password,
|
| 159 | + 'wpRetype' => $password,
|
| 160 | + 'wpEmail' => $email,
|
| 161 | + 'wpRealName' => $name,
|
| 162 | + 'wpCaptchaWord' => $captchaword,
|
| 163 | + 'wpCaptchaId' => $captchaid,
|
| 164 | + 'wpDomain' => $domain);
|
| 165 | + $request = new FauxRequest($data);
|
| 166 | + $wgRequest = $request;
|
| 167 | + $form = new LoginForm( $request );
|
| 168 | + $value = $form->addNewAccount($resultDetails);
|
| 169 | + }
|
| 170 | + }
|
| 171 | + $this->process($value,$resultDetails);
|
| 172 | + }
|
| 173 | +
|
177 | 174 | protected function getDescription() {
|
178 | 175 | return 'Create new user account';
|
179 | 176 | }
|
— | — | @@ -180,49 +177,49 @@ |
181 | 178 | protected function getExamples() {
|
182 | 179 | return array (
|
183 | 180 | "Create new user account using MediaWiki API",
|
184 | | - " You must register using POST method."
|
| 181 | + " You must register using POST method."
|
185 | 182 | );
|
186 | 183 | }
|
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 | 184 |
|
| 185 | + protected function getAllowedParams() {
|
| 186 | + return array (
|
| 187 | + 'user' => array(
|
| 188 | + ApiBase :: PARAM_TYPE => 'string'
|
| 189 | + ),
|
| 190 | + 'password' => array(
|
| 191 | + ApiBase :: PARAM_TYPE => 'string'
|
| 192 | + ),
|
| 193 | + 'email' => array(
|
| 194 | + ApiBase :: PARAM_TYPE => 'string'
|
| 195 | + ),
|
| 196 | + 'name' => array(
|
| 197 | + ApiBase :: PARAM_TYPE => 'string'
|
| 198 | + ),
|
| 199 | + 'captchaword' => array(
|
| 200 | + ApiBase :: PARAM_TYPE => 'string'
|
| 201 | + ),
|
| 202 | + 'captchaid' => array(
|
| 203 | + ApiBase :: PARAM_TYPE => 'string'
|
| 204 | + ),
|
| 205 | + 'domain' => array(
|
| 206 | + ApiBase :: PARAM_TYPE => 'string'
|
| 207 | + )
|
| 208 | +
|
| 209 | + );
|
| 210 | + }
|
| 211 | +
|
| 212 | + protected function getParamDescription() {
|
| 213 | + return array (
|
| 214 | + 'user' => 'user login name',
|
| 215 | + 'password' => 'user password',
|
| 216 | + 'email' => 'user email',
|
| 217 | + 'name' => 'user name',
|
| 218 | + 'domain' => 'domain',
|
| 219 | + 'captchaid' => 'question',
|
| 220 | + 'captchaword' => 'answer'
|
| 221 | + );
|
| 222 | + }
|
| 223 | +
|
227 | 224 | public function getVersion() {
|
228 | 225 | return __CLASS__ . ': $Id: ApiRegUser.php 22289 2007-05-20 23:31:44Z jvelezv $';
|
229 | 226 | }
|