Index: trunk/extensions/AjaxLogin/AjaxLogin.i18n.php |
— | — | @@ -21,6 +21,8 @@ |
22 | 22 | 'al-nosuchuser' => 'There is no user by the name "$1". |
23 | 23 | User names are case sensitive. |
24 | 24 | Check your spelling.', |
| 25 | + 'al-createblocked' => 'Your IP address is blocked from account creation.', |
| 26 | + 'al-throttled' => 'You have had too many recent password attempts. Please wait $1 {{PLURAL:$1|second|seconds}} before trying again.', |
25 | 27 | ); |
26 | 28 | |
27 | 29 | /** Message documentation (Message documentation) |
Index: trunk/extensions/AjaxLogin/AjaxLogin.php |
— | — | @@ -4,9 +4,10 @@ |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
8 | | - * @version 2.1.0 |
| 8 | + * @version 2.2.0 |
9 | 9 | * @author Inez Korczyński <korczynski(at)gmail(dot)com> |
10 | 10 | * @author Jack Phoenix <jack@countervandalism.net> |
| 11 | + * @author Ryan Schmidt <skizzerz@shoutwiki.com> |
11 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
12 | 13 | */ |
13 | 14 | |
— | — | @@ -18,8 +19,8 @@ |
19 | 20 | $wgExtensionCredits['other'][] = array( |
20 | 21 | 'path' => __FILE__, |
21 | 22 | 'name' => 'AjaxLogin', |
22 | | - 'version' => '2.1.0', |
23 | | - 'author' => array( 'Inez Korczyński', 'Jack Phoenix' ), |
| 23 | + 'version' => '2.2.0', |
| 24 | + 'author' => array( 'Inez Korczyński', 'Jack Phoenix', 'Ryan Schmidt' ), |
24 | 25 | 'url' => 'http://www.mediawiki.org/wiki/Extension:AjaxLogin', |
25 | 26 | 'descriptionmsg' => 'ajaxlogin-desc', |
26 | 27 | ); |
— | — | @@ -94,13 +95,16 @@ |
95 | 96 | * @param $data The data, AjaxLogin form in this case, to be added to the HTML output of a page |
96 | 97 | * @return true |
97 | 98 | */ |
98 | | -function GetAjaxLoginForm( &$data, $skin ) { |
| 99 | +function GetAjaxLoginForm( &$data, $skin = null ) { |
99 | 100 | global $wgAuth, $wgEnableEmail, $wgOut, $wgUser; |
100 | 101 | global $wgEnableAjaxLogin; |
101 | | - if ( |
102 | | - isset( $wgEnableAjaxLogin ) && $wgUser->isAnon() && |
103 | | - $skin->getTitle()->getNamespace() != 8 && !$skin->getTitle()->isSpecial( 'Userlogin' ) |
104 | | - ) { |
| 102 | + if( is_null( $skin ) ) { |
| 103 | + global $wgTitle; |
| 104 | + $userlogincheck = $wgTitle->getNamespace() != 8 && $wgTitle->getDBkey() != 'Userlogin'; |
| 105 | + } else { |
| 106 | + $userlogincheck = $skin->getTitle()->getNamespace() != 8 && !$skin->getTitle()->isSpecial( 'Userlogin' ); |
| 107 | + } |
| 108 | + if( isset( $wgEnableAjaxLogin ) && $wgUser->isAnon() && $userlogincheck ) { |
105 | 109 | $titleObj = SpecialPage::getTitleFor( 'Userlogin' ); |
106 | 110 | $link = $titleObj->getLocalURL( 'type=signup' ); |
107 | 111 | $wgOut->addHTML( '<!--[if lt IE 9]><style type="text/css">#userloginRound { width: 350px !important; }</style><![endif]--> |
Index: trunk/extensions/AjaxLogin/AjaxLogin.js |
— | — | @@ -47,8 +47,8 @@ |
48 | 48 | mediawiki.AjaxLogin.prototype.postAjax = function( action ) { |
49 | 49 | var actionURL = wgServer + wgScriptPath + '/api.php?action=ajaxlogin&format=json'; |
50 | 50 | var dataString = this._loginForm.serialize(); |
| 51 | + this.disableForm(); |
51 | 52 | dataString += '&' + action + '=' + action; |
52 | | - this.disableForm(); |
53 | 53 | var that = this; |
54 | 54 | $.ajax({ |
55 | 55 | type : 'POST', |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | dataType : 'json', |
58 | 58 | data : dataString, |
59 | 59 | success : function( data ) { |
60 | | - that.requestSuccess( data ); |
| 60 | + that.requestSuccess( data, dataString, actionURL ); |
61 | 61 | }, |
62 | 62 | error : function( XMLHttpRequest, textStatus, errorThrown ) { |
63 | 63 | // TODO : add error handling here |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | this._loginPanel.jqmHide(); |
112 | 112 | }; |
113 | 113 | |
114 | | -mediawiki.AjaxLogin.prototype.requestSuccess = function( data ) { |
| 114 | +mediawiki.AjaxLogin.prototype.requestSuccess = function( data, dataString, actionURL ) { |
115 | 115 | var responseResult = data.ajaxlogin.result; |
116 | 116 | switch( responseResult ) { |
117 | 117 | case 'Reset': |
— | — | @@ -143,6 +143,26 @@ |
144 | 144 | } |
145 | 145 | } |
146 | 146 | break; |
| 147 | + case 'NeedToken': |
| 148 | + case 'WrongToken': |
| 149 | + // TODO: make it so this can't go in an infinite loop |
| 150 | + var that = this; |
| 151 | + $.ajax({ |
| 152 | + type : 'POST', |
| 153 | + url : actionURL, |
| 154 | + dataType : 'json', |
| 155 | + data : dataString + '&wpToken=' + data.ajaxlogin.token, |
| 156 | + success : function( data ) { |
| 157 | + that.requestSuccess( data, dataString, actionURL ); |
| 158 | + }, |
| 159 | + error : function( XMLHttpRequest, textStatus, errorThrown ) { |
| 160 | + // TODO : add error handling here |
| 161 | + if( typeof console != 'undefined' ) { |
| 162 | + console.log( 'Error in AjaxLogin.js!' ); |
| 163 | + } |
| 164 | + } |
| 165 | + }); |
| 166 | + break; |
147 | 167 | case 'NotExists': |
148 | 168 | this.enableForm(); |
149 | 169 | $('#wpName1').value = ''; |
Index: trunk/extensions/AjaxLogin/ApiAjaxLogin.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | |
20 | 20 | public function execute() { |
21 | 21 | session_start(); |
22 | | - $Name = $Password = $Remember = $Loginattempt = $Mailmypassword = null; |
| 22 | + $Name = $Password = $Remember = $Loginattempt = $Mailmypassword = $Token = null; |
23 | 23 | extract( $this->extractRequestParams() ); |
24 | 24 | |
25 | 25 | if ( !empty( $Loginattempt ) ) { |
— | — | @@ -28,7 +28,8 @@ |
29 | 29 | 'wpName' => $Name, |
30 | 30 | 'wpPassword' => $Password, |
31 | 31 | 'wpRemember' => $Remember, |
32 | | - 'wpLoginattempt' => $Loginattempt |
| 32 | + 'wpLoginattempt' => $Loginattempt, |
| 33 | + 'wpLoginToken' => $Token, |
33 | 34 | ) |
34 | 35 | ); |
35 | 36 | |
— | — | @@ -39,16 +40,27 @@ |
40 | 41 | $result['result'] = 'Reset'; |
41 | 42 | break; |
42 | 43 | case LoginForm::SUCCESS: |
43 | | - global $wgUser; |
| 44 | + global $wgUser, $wgCookiePrefix; |
44 | 45 | |
45 | 46 | $wgUser->setOption( 'rememberpassword', $Remember ? 1 : 0 ); |
46 | 47 | $wgUser->setCookies(); |
47 | 48 | |
48 | 49 | $result['result'] = 'Success'; |
49 | | - $result['lguserid'] = $_SESSION['wsUserID']; |
50 | | - $result['lgusername'] = $_SESSION['wsUserName']; |
51 | | - $result['lgtoken'] = $_SESSION['wsToken']; |
| 50 | + $result['lguserid'] = intval( $wgUser->getId() ); |
| 51 | + $result['lgusername'] = $wgUser->getName(); |
| 52 | + $result['lgtoken'] = $wgUser->getToken(); |
| 53 | + $result['cookieprefix'] = $wgCookiePrefix; |
| 54 | + $result['sessionid'] = session_id(); |
52 | 55 | break; |
| 56 | + case LoginForm::NEED_TOKEN: |
| 57 | + $result['result'] = 'NeedToken'; |
| 58 | + $result['token'] = $loginForm->getLoginToken(); |
| 59 | + $result['cookieprefix'] = $wgCookiePrefix; |
| 60 | + $result['sessionid'] = session_id(); |
| 61 | + break; |
| 62 | + case LoginForm::WRONG_TOKEN: |
| 63 | + $result['result'] = 'WrongToken'; |
| 64 | + break; |
53 | 65 | case LoginForm::NO_NAME: |
54 | 66 | $result['result'] = 'NoName'; |
55 | 67 | $result['text'] = wfMsg( 'noname' ); |
— | — | @@ -65,6 +77,7 @@ |
66 | 78 | $result['result'] = 'NotExists'; |
67 | 79 | $result['text'] = wfMsg( 'al-nosuchuser', htmlspecialchars( $Name ) ); |
68 | 80 | break; |
| 81 | + case LoginForm::RESET_PASS: |
69 | 82 | case LoginForm::WRONG_PASS: |
70 | 83 | $result['result'] = 'WrongPass'; |
71 | 84 | $result['text'] = wfMsg( 'wrongpassword' ); |
— | — | @@ -73,6 +86,18 @@ |
74 | 87 | $result['result'] = 'EmptyPass'; |
75 | 88 | $result['text'] = wfMsg( 'wrongpasswordempty' ); |
76 | 89 | break; |
| 90 | + case LoginForm::CREATE_BLOCKED: |
| 91 | + $result['result'] = 'CreateBlocked'; |
| 92 | + $result['text'] = wfMsg( 'al-createblocked' ); |
| 93 | + break; |
| 94 | + case LoginForm::THROTTLED: |
| 95 | + global $wgPasswordAttemptThrottle; |
| 96 | + $result['result'] = 'Throttled'; |
| 97 | + $result['text'] = wfMsg( 'al-throttled', intval( $wgPasswordAttemptThrottle['seconds'] ) ); |
| 98 | + break; |
| 99 | + case LoginForm::USER_BLOCKED: |
| 100 | + $result['result'] = 'Blocked'; |
| 101 | + break; |
77 | 102 | default: |
78 | 103 | ApiBase::dieDebug( __METHOD__, 'Unhandled case value' ); |
79 | 104 | } |
— | — | @@ -135,8 +160,8 @@ |
136 | 161 | 'Password' => null, |
137 | 162 | 'Remember' => null, |
138 | 163 | 'Loginattempt' => null, |
139 | | - 'Mailmypassword' => null |
140 | | - |
| 164 | + 'Mailmypassword' => null, |
| 165 | + 'Token' => null |
141 | 166 | ); |
142 | 167 | } |
143 | 168 | |