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 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Auth; |
| 8 | |
| 9 | use MediaWiki\Language\RawMessage; |
| 10 | |
| 11 | /** |
| 12 | * This is a value object for authentication requests with a username, password, and domain |
| 13 | * |
| 14 | * @stable to extend |
| 15 | * @ingroup Auth |
| 16 | * @since 1.27 |
| 17 | */ |
| 18 | class PasswordDomainAuthenticationRequest extends PasswordAuthenticationRequest { |
| 19 | /** @var string[] Domains available */ |
| 20 | private $domainList; |
| 21 | |
| 22 | /** @var string|null */ |
| 23 | public $domain = null; |
| 24 | |
| 25 | /** |
| 26 | * @stable to call |
| 27 | * @param string[] $domainList List of available domains |
| 28 | */ |
| 29 | public function __construct( array $domainList ) { |
| 30 | $this->domainList = $domainList; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @inheritDoc |
| 35 | * @stable to override |
| 36 | */ |
| 37 | public function getFieldInfo() { |
| 38 | $ret = parent::getFieldInfo(); |
| 39 | |
| 40 | // Only add a domain field if we have the username field included |
| 41 | if ( isset( $ret['username'] ) ) { |
| 42 | $ret['domain'] = [ |
| 43 | 'type' => 'select', |
| 44 | 'options' => [], |
| 45 | 'label' => wfMessage( 'yourdomainname' ), |
| 46 | 'help' => wfMessage( 'authmanager-domain-help' ), |
| 47 | ]; |
| 48 | foreach ( $this->domainList as $domain ) { |
| 49 | $ret['domain']['options'][$domain] = new RawMessage( '$1', [ $domain ] ); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return $ret; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @inheritDoc |
| 58 | * @stable to override |
| 59 | */ |
| 60 | public function describeCredentials() { |
| 61 | return [ |
| 62 | 'provider' => wfMessage( 'authmanager-provider-password-domain' ), |
| 63 | 'account' => wfMessage( |
| 64 | 'authmanager-account-password-domain', [ $this->username, $this->domain ] |
| 65 | ), |
| 66 | ]; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @codeCoverageIgnore |
| 71 | * @param array $data |
| 72 | * @return AuthenticationRequest|static |
| 73 | */ |
| 74 | public static function __set_state( $data ) { |
| 75 | $ret = new static( $data['domainList'] ); |
| 76 | foreach ( $data as $k => $v ) { |
| 77 | if ( $k !== 'domainList' ) { |
| 78 | $ret->$k = $v; |
| 79 | } |
| 80 | } |
| 81 | return $ret; |
| 82 | } |
| 83 | } |