79b4b7418a94aeede7f77d88fa1ccb4f87339896
[lhc/web/wiklou.git] / includes / api / ApiLogin.php
1 <?php
2
3
4 /*
5 * Created on Sep 19, 2006
6 *
7 * API for MediaWiki 1.8+
8 *
9 * Copyright (C) 2006 Yuri Astrakhan <FirstnameLastname@gmail.com>
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 class ApiLogin extends ApiBase {
33
34 /**
35 * Constructor
36 */
37 public function __construct($main, $action) {
38 parent :: __construct($main);
39 }
40
41 public function Execute() {
42 $lgname = $lgpassword = $lgdomain = null;
43 extract($this->ExtractRequestParams());
44
45 $params = new FauxRequest(array (
46 'wpName' => $lgname,
47 'wpPassword' => $lgpassword,
48 'wpDomain' => $lgdomain,
49 'wpRemember' => ''
50 ));
51
52 $result = array();
53
54 $loginForm = new LoginForm($params);
55 switch ($loginForm->authenticateUserData())
56 {
57 case (AuthSuccess):
58 $result['result'] = 'Success';
59 $result['lguserid'] = $_SESSION['wsUserID'];
60 $result['lgusername'] = $_SESSION['wsUserName'];
61 $result['lgtoken'] = $_SESSION['wsToken'];
62 break;
63
64 case (AuthNoName):
65 $result['result'] = 'AuthNoName';
66 break;
67 case (AuthIllegal):
68 $result['result'] = 'AuthIllegal';
69 break;
70 case (AuthWrongPluginPass):
71 $result['result'] = 'AuthWrongPluginPass';
72 break;
73 case (AuthNotExists):
74 $result['result'] = 'AuthNotExists';
75 break;
76 case (AuthWrongPass):
77 $result['result'] = 'AuthWrongPass';
78 break;
79 case (AuthEmptyPass):
80 $result['result'] = 'AuthEmptyPass';
81 break;
82 default:
83 $this->DieDebug( "Unhandled case value" );
84 }
85
86 $this->GetResult()->AddMessage('login', null, $result);
87 }
88
89 /**
90 * Returns an array of allowed parameters (keys) => default value for that parameter
91 */
92 protected function GetAllowedParams() {
93 return array (
94 'lgname' => '',
95 'lgpassword' => '',
96 'lgdomain' => null
97 );
98 }
99
100 /**
101 * Returns the description string for the given parameter.
102 */
103 protected function GetParamDescription() {
104 return array (
105 'lgname' => 'User Name',
106 'lgpassword' => 'Password',
107 'lgdomain' => 'Domain (optional)',
108
109 );
110 }
111
112 /**
113 * Returns the description string for this module
114 */
115 protected function GetDescription() {
116 return array("*Login Module*",
117 "This module is used to login and get the authentication tokens.");
118 }
119 }
120 ?>