1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup Auth
*/
namespace MediaWiki\Auth;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use MediaWiki\Parser\Sanitizer;
use MediaWiki\User\User;
use StatusValue;
/**
* This represents additional user data requested on the account creation form
*
* @stable to extend
* @ingroup Auth
* @since 1.27
*/
class UserDataAuthenticationRequest extends AuthenticationRequest {
/** @var string|null Email address */
public $email;
/** @var string|null Real name */
public $realname;
/**
* @inheritDoc
* @stable to override
*/
public function getFieldInfo() {
$config = MediaWikiServices::getInstance()->getMainConfig();
$ret = [
'email' => [
'type' => 'string',
'label' => wfMessage( 'authmanager-email-label' ),
'help' => wfMessage( 'authmanager-email-help' ),
'optional' => true,
],
'realname' => [
'type' => 'string',
'label' => wfMessage( 'authmanager-realname-label' ),
'help' => wfMessage( 'authmanager-realname-help' ),
'optional' => true,
],
];
if ( !$config->get( MainConfigNames::EnableEmail ) ) {
unset( $ret['email'] );
}
if ( in_array( 'realname', $config->get( MainConfigNames::HiddenPrefs ), true ) ) {
unset( $ret['realname'] );
}
return $ret;
}
/**
* Add data to the User object
* @stable to override
* @param User $user User being created (not added to the database yet).
* This may become a "UserValue" in the future, or User may be refactored
* into such.
* @return StatusValue
*/
public function populateUser( $user ) {
if ( $this->email !== null && $this->email !== '' ) {
if ( !Sanitizer::validateEmail( $this->email ) ) {
return StatusValue::newFatal( 'invalidemailaddress' );
}
$user->setEmail( $this->email );
}
if ( $this->realname !== null && $this->realname !== '' ) {
$user->setRealName( $this->realname );
}
return StatusValue::newGood();
}
}
|