MediaWiki master
UserDataAuthenticationRequest.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
28use StatusValue;
29
39 public $email;
40
42 public $realname;
43
48 public function getFieldInfo() {
49 $config = MediaWikiServices::getInstance()->getMainConfig();
50 $ret = [
51 'email' => [
52 'type' => 'string',
53 'label' => wfMessage( 'authmanager-email-label' ),
54 'help' => wfMessage( 'authmanager-email-help' ),
55 'optional' => true,
56 ],
57 'realname' => [
58 'type' => 'string',
59 'label' => wfMessage( 'authmanager-realname-label' ),
60 'help' => wfMessage( 'authmanager-realname-help' ),
61 'optional' => true,
62 ],
63 ];
64
65 if ( !$config->get( MainConfigNames::EnableEmail ) ) {
66 unset( $ret['email'] );
67 }
68
69 if ( in_array( 'realname', $config->get( MainConfigNames::HiddenPrefs ), true ) ) {
70 unset( $ret['realname'] );
71 }
72
73 return $ret;
74 }
75
84 public function populateUser( $user ) {
85 if ( $this->email !== null && $this->email !== '' ) {
86 if ( !Sanitizer::validateEmail( $this->email ) ) {
87 return StatusValue::newFatal( 'invalidemailaddress' );
88 }
89 $user->setEmail( $this->email );
90 }
91 if ( $this->realname !== null && $this->realname !== '' ) {
92 $user->setRealName( $this->realname );
93 }
94 return StatusValue::newGood();
95 }
96
97}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This is a value object for authentication requests.
This represents additional user data requested on the account creation form.
getFieldInfo()
Fetch input field info.This will be used in the AuthManager APIs and web UIs to define API input para...
A class containing constants representing the names of configuration variables.
const HiddenPrefs
Name constant for the HiddenPrefs setting, for use with Config::get()
const EnableEmail
Name constant for the EnableEmail setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:46
internal since 1.36
Definition User.php:93
Generic operation result class Has warning/error list, boolean status and arbitrary value.