MediaWiki 1.44.0
ResetPasswordSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
27
42
43 public function getAuthenticationRequests( $action, array $options ) {
44 return [];
45 }
46
47 public function beginSecondaryAuthentication( $user, array $reqs ) {
48 return $this->tryReset( $user, $reqs );
49 }
50
51 public function continueSecondaryAuthentication( $user, array $reqs ) {
52 return $this->tryReset( $user, $reqs );
53 }
54
55 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
56 return $this->tryReset( $user, $reqs );
57 }
58
59 public function continueSecondaryAccountCreation( $user, $creator, array $reqs ) {
60 return $this->tryReset( $user, $reqs );
61 }
62
69 protected function tryReset( User $user, array $reqs ) {
70 $data = $this->manager->getAuthenticationSessionData( 'reset-pass' );
71 if ( !$data ) {
73 }
74
75 if ( is_array( $data ) ) {
76 $data = (object)$data;
77 }
78 if ( !is_object( $data ) ) {
79 throw new \UnexpectedValueException( 'reset-pass is not valid' );
80 }
81
82 if ( !isset( $data->msg ) ) {
83 throw new \UnexpectedValueException( 'reset-pass msg is missing' );
84 } elseif ( !$data->msg instanceof Message ) {
85 throw new \UnexpectedValueException( 'reset-pass msg is not valid' );
86 } elseif ( !isset( $data->hard ) ) {
87 throw new \UnexpectedValueException( 'reset-pass hard is missing' );
88 } elseif ( isset( $data->req ) && (
89 !$data->req instanceof PasswordAuthenticationRequest ||
90 !array_key_exists( 'retype', $data->req->getFieldInfo() )
91 ) ) {
92 throw new \UnexpectedValueException( 'reset-pass req is not valid' );
93 }
94
95 if ( !$data->hard ) {
96 $req = ButtonAuthenticationRequest::getRequestByName( $reqs, 'skipReset' );
97 if ( $req ) {
98 $this->manager->removeAuthenticationSessionData( 'reset-pass' );
100 }
101 }
102
104 $needReq = $data->req ?? new PasswordAuthenticationRequest();
105 '@phan-var PasswordAuthenticationRequest $needReq';
106 if ( !$needReq->action ) {
107 $needReq->action = AuthManager::ACTION_CHANGE;
108 }
109 $needReq->required = $data->hard ? AuthenticationRequest::REQUIRED
111 $needReqs = [ $needReq ];
112 if ( !$data->hard ) {
113 $needReqs[] = new ButtonAuthenticationRequest(
114 'skipReset',
115 wfMessage( 'authprovider-resetpass-skip-label' ),
116 wfMessage( 'authprovider-resetpass-skip-help' )
117 );
118 }
119
121 $req = AuthenticationRequest::getRequestByClass( $reqs, get_class( $needReq ) );
122 '@phan-var PasswordAuthenticationRequest $req';
123 if ( !$req || !array_key_exists( 'retype', $req->getFieldInfo() ) ) {
124 return AuthenticationResponse::newUI( $needReqs, $data->msg, 'warning' );
125 }
126
127 if ( $req->password !== $req->retype ) {
128 return AuthenticationResponse::newUI( $needReqs, new Message( 'badretype' ), 'error' );
129 }
130
131 $req->username = $user->getName();
132 $status = $this->manager->allowsAuthenticationDataChange( $req );
133 if ( !$status->isGood() ) {
134 return AuthenticationResponse::newUI( $needReqs, $status->getMessage(), 'error' );
135 }
136 $scope = LoggerFactory::getContext()->addScoped( [
137 'context.passwordResetOnLogin' => $data->hard ? 'forced' : 'suggested',
138 ] );
139 $this->manager->changeAuthenticationData( $req );
140
141 $this->manager->removeAuthenticationSessionData( 'reset-pass' );
143 }
144}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
const ACTION_CHANGE
Change a user's credentials.
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
const REQUIRED
Indicates that the request is required for authentication to proceed.
static getRequestByClass(array $reqs, $class, $allowSubclasses=false)
Select a request by class name.
static newUI(array $reqs, Message $msg, $msgtype='warning')
This is an authentication request that just implements a simple button.
static getRequestByName(array $reqs, $name)
Fetch a ButtonAuthenticationRequest or subclass by name.
This is a value object for authentication requests with a username and password.
Reset the local password, if signalled via $this->manager->setAuthenticationSessionData()
continueSecondaryAccountCreation( $user, $creator, array $reqs)
Continue an authentication flow.AuthenticationResponse Expected responses:PASS: The user creation is ...
continueSecondaryAuthentication( $user, array $reqs)
Continue an authentication flow.AuthenticationResponse Expected responses:PASS: The user is authentic...
beginSecondaryAccountCreation( $user, $creator, array $reqs)
Start an account creation flow.
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
Create PSR-3 logger objects.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:157
User class for the MediaWiki software.
Definition User.php:121
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:1612