Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserDataAuthenticationRequest | |
100.00% |
27 / 27 |
|
100.00% |
2 / 2 |
9 | |
100.00% |
1 / 1 |
| getFieldInfo | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
3 | |||
| populateUser | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Auth; |
| 8 | |
| 9 | use MediaWiki\MainConfigNames; |
| 10 | use MediaWiki\MediaWikiServices; |
| 11 | use MediaWiki\Parser\Sanitizer; |
| 12 | use MediaWiki\User\User; |
| 13 | use StatusValue; |
| 14 | |
| 15 | /** |
| 16 | * This represents additional user data requested on the account creation form |
| 17 | * |
| 18 | * @stable to extend |
| 19 | * @ingroup Auth |
| 20 | * @since 1.27 |
| 21 | */ |
| 22 | class UserDataAuthenticationRequest extends AuthenticationRequest { |
| 23 | /** @var string|null Email address */ |
| 24 | public $email; |
| 25 | |
| 26 | /** @var string|null Real name */ |
| 27 | public $realname; |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | * @stable to override |
| 32 | */ |
| 33 | public function getFieldInfo() { |
| 34 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
| 35 | $ret = [ |
| 36 | 'email' => [ |
| 37 | 'type' => 'string', |
| 38 | 'label' => wfMessage( 'authmanager-email-label' ), |
| 39 | 'help' => wfMessage( 'authmanager-email-help' ), |
| 40 | 'optional' => true, |
| 41 | ], |
| 42 | 'realname' => [ |
| 43 | 'type' => 'string', |
| 44 | 'label' => wfMessage( 'authmanager-realname-label' ), |
| 45 | 'help' => wfMessage( 'authmanager-realname-help' ), |
| 46 | 'optional' => true, |
| 47 | ], |
| 48 | ]; |
| 49 | |
| 50 | if ( !$config->get( MainConfigNames::EnableEmail ) ) { |
| 51 | unset( $ret['email'] ); |
| 52 | } |
| 53 | |
| 54 | if ( in_array( 'realname', $config->get( MainConfigNames::HiddenPrefs ), true ) ) { |
| 55 | unset( $ret['realname'] ); |
| 56 | } |
| 57 | |
| 58 | return $ret; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Add data to the User object |
| 63 | * @stable to override |
| 64 | * @param User $user User being created (not added to the database yet). |
| 65 | * This may become a "UserValue" in the future, or User may be refactored |
| 66 | * into such. |
| 67 | * @return StatusValue |
| 68 | */ |
| 69 | public function populateUser( $user ) { |
| 70 | if ( $this->email !== null && $this->email !== '' ) { |
| 71 | if ( !Sanitizer::validateEmail( $this->email ) ) { |
| 72 | return StatusValue::newFatal( 'invalidemailaddress' ); |
| 73 | } |
| 74 | $user->setEmail( $this->email ); |
| 75 | } |
| 76 | if ( $this->realname !== null && $this->realname !== '' ) { |
| 77 | $user->setRealName( $this->realname ); |
| 78 | } |
| 79 | return StatusValue::newGood(); |
| 80 | } |
| 81 | |
| 82 | } |