Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
PasswordDomainAuthenticationRequest | |
100.00% |
18 / 18 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFieldInfo | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
3 | |||
describeCredentials | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
__set_state | n/a |
0 / 0 |
n/a |
0 / 0 |
3 |
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 | use MediaWiki\Language\RawMessage; |
25 | |
26 | /** |
27 | * This is a value object for authentication requests with a username, password, and domain |
28 | * @stable to extend |
29 | * @ingroup Auth |
30 | * @since 1.27 |
31 | */ |
32 | class PasswordDomainAuthenticationRequest extends PasswordAuthenticationRequest { |
33 | /** @var string[] Domains available */ |
34 | private $domainList; |
35 | |
36 | /** @var string Domain */ |
37 | public $domain = null; |
38 | |
39 | /** |
40 | * @stable to call |
41 | * @param string[] $domainList List of available domains |
42 | */ |
43 | public function __construct( array $domainList ) { |
44 | $this->domainList = $domainList; |
45 | } |
46 | |
47 | /** |
48 | * @inheritDoc |
49 | * @stable to override |
50 | */ |
51 | public function getFieldInfo() { |
52 | $ret = parent::getFieldInfo(); |
53 | |
54 | // Only add a domain field if we have the username field included |
55 | if ( isset( $ret['username'] ) ) { |
56 | $ret['domain'] = [ |
57 | 'type' => 'select', |
58 | 'options' => [], |
59 | 'label' => wfMessage( 'yourdomainname' ), |
60 | 'help' => wfMessage( 'authmanager-domain-help' ), |
61 | ]; |
62 | foreach ( $this->domainList as $domain ) { |
63 | $ret['domain']['options'][$domain] = new RawMessage( '$1', [ $domain ] ); |
64 | } |
65 | } |
66 | |
67 | return $ret; |
68 | } |
69 | |
70 | /** |
71 | * @inheritDoc |
72 | * @stable to override |
73 | */ |
74 | public function describeCredentials() { |
75 | return [ |
76 | 'provider' => wfMessage( 'authmanager-provider-password-domain' ), |
77 | 'account' => wfMessage( |
78 | 'authmanager-account-password-domain', [ $this->username, $this->domain ] |
79 | ), |
80 | ]; |
81 | } |
82 | |
83 | /** |
84 | * @codeCoverageIgnore |
85 | * @param array $data |
86 | * @return AuthenticationRequest|static |
87 | */ |
88 | public static function __set_state( $data ) { |
89 | $ret = new static( $data['domainList'] ); |
90 | foreach ( $data as $k => $v ) { |
91 | if ( $k !== 'domainList' ) { |
92 | $ret->$k = $v; |
93 | } |
94 | } |
95 | return $ret; |
96 | } |
97 | } |