00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 if (!defined('MEDIAWIKI')) {
00028
00029 require_once ('ApiBase.php');
00030 }
00031
00037 class ApiLogin extends ApiBase {
00038
00039 public function __construct($main, $action) {
00040 parent :: __construct($main, $action, 'lg');
00041 }
00042
00054 public function execute() {
00055 $params = $this->extractRequestParams();
00056
00057 $result = array ();
00058
00059 $req = new FauxRequest(array (
00060 'wpName' => $params['name'],
00061 'wpPassword' => $params['password'],
00062 'wpDomain' => $params['domain'],
00063 'wpRemember' => ''
00064 ));
00065
00066
00067 if( session_id() == '' ) {
00068 wfSetupSession();
00069 }
00070
00071 $loginForm = new LoginForm($req);
00072 switch ($authRes = $loginForm->authenticateUserData()) {
00073 case LoginForm :: SUCCESS :
00074 global $wgUser, $wgCookiePrefix;
00075
00076 $wgUser->setOption('rememberpassword', 1);
00077 $wgUser->setCookies();
00078
00079
00080
00081 $injected_html = '';
00082 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
00083
00084 $result['result'] = 'Success';
00085 $result['lguserid'] = intval($wgUser->getId());
00086 $result['lgusername'] = $wgUser->getName();
00087 $result['lgtoken'] = $wgUser->getToken();
00088 $result['cookieprefix'] = $wgCookiePrefix;
00089 $result['sessionid'] = session_id();
00090 break;
00091
00092 case LoginForm :: NO_NAME :
00093 $result['result'] = 'NoName';
00094 break;
00095 case LoginForm :: ILLEGAL :
00096 $result['result'] = 'Illegal';
00097 break;
00098 case LoginForm :: WRONG_PLUGIN_PASS :
00099 $result['result'] = 'WrongPluginPass';
00100 break;
00101 case LoginForm :: NOT_EXISTS :
00102 $result['result'] = 'NotExists';
00103 break;
00104 case LoginForm :: WRONG_PASS :
00105 $result['result'] = 'WrongPass';
00106 break;
00107 case LoginForm :: EMPTY_PASS :
00108 $result['result'] = 'EmptyPass';
00109 break;
00110 case LoginForm :: CREATE_BLOCKED :
00111 $result['result'] = 'CreateBlocked';
00112 $result['details'] = 'Your IP address is blocked from account creation';
00113 break;
00114 case LoginForm :: THROTTLED :
00115 global $wgPasswordAttemptThrottle;
00116 $result['result'] = 'Throttled';
00117 $result['wait'] = intval($wgPasswordAttemptThrottle['seconds']);
00118 break;
00119 default :
00120 ApiBase :: dieDebug(__METHOD__, "Unhandled case value: {$authRes}");
00121 }
00122
00123 $this->getResult()->addValue(null, 'login', $result);
00124 }
00125
00126 public function mustBePosted() { return true; }
00127
00128 public function isReadMode() {
00129 return false;
00130 }
00131
00132 public function getAllowedParams() {
00133 return array (
00134 'name' => null,
00135 'password' => null,
00136 'domain' => null
00137 );
00138 }
00139
00140 public function getParamDescription() {
00141 return array (
00142 'name' => 'User Name',
00143 'password' => 'Password',
00144 'domain' => 'Domain (optional)'
00145 );
00146 }
00147
00148 public function getDescription() {
00149 return array (
00150 'This module is used to login and get the authentication tokens. ',
00151 'In the event of a successful log-in, a cookie will be attached',
00152 'to your session. In the event of a failed log-in, you will not ',
00153 'be able to attempt another log-in through this method for 5 seconds.',
00154 'This is to prevent password guessing by automated password crackers.'
00155 );
00156 }
00157
00158 protected function getExamples() {
00159 return array(
00160 'api.php?action=login&lgname=user&lgpassword=password'
00161 );
00162 }
00163
00164 public function getVersion() {
00165 return __CLASS__ . ': $Id: ApiLogin.php 48091 2009-03-06 13:49:44Z catrope $';
00166 }
00167 }