Merge "Avoid unstubbing $wgLang in Title::getLocalURL"
[lhc/web/wiklou.git] / includes / auth / PasswordAuthenticationRequest.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Auth
20 */
21
22 namespace MediaWiki\Auth;
23
24 /**
25 * This is a value object for authentication requests with a username and password
26 * @ingroup Auth
27 * @since 1.27
28 */
29 class PasswordAuthenticationRequest extends AuthenticationRequest {
30 /** @var string Password */
31 public $password = null;
32
33 /** @var string Password, again */
34 public $retype = null;
35
36 public function getFieldInfo() {
37 if ( $this->action === AuthManager::ACTION_REMOVE ) {
38 return [];
39 }
40
41 // for password change it's nice to make extra clear that we are asking for the new password
42 $forNewPassword = $this->action === AuthManager::ACTION_CHANGE;
43 $passwordLabel = $forNewPassword ? 'newpassword' : 'userlogin-yourpassword';
44 $retypeLabel = $forNewPassword ? 'retypenew' : 'yourpasswordagain';
45
46 $ret = [
47 'username' => [
48 'type' => 'string',
49 'label' => wfMessage( 'userlogin-yourname' ),
50 'help' => wfMessage( 'authmanager-username-help' ),
51 ],
52 'password' => [
53 'type' => 'password',
54 'label' => wfMessage( $passwordLabel ),
55 'help' => wfMessage( 'authmanager-password-help' ),
56 ],
57 ];
58
59 switch ( $this->action ) {
60 case AuthManager::ACTION_CHANGE:
61 case AuthManager::ACTION_REMOVE:
62 unset( $ret['username'] );
63 break;
64 }
65
66 if ( $this->action !== AuthManager::ACTION_LOGIN ) {
67 $ret['retype'] = [
68 'type' => 'password',
69 'label' => wfMessage( $retypeLabel ),
70 'help' => wfMessage( 'authmanager-retype-help' ),
71 ];
72 }
73
74 return $ret;
75 }
76
77 public function describeCredentials() {
78 return [
79 'provider' => wfMessage( 'authmanager-provider-password' ),
80 'account' => new \RawMessage( '$1', [ $this->username ] ),
81 ];
82 }
83 }