MediaWiki master
ResetPasswordSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Auth;
8
12
27
29 public function getAuthenticationRequests( $action, array $options ) {
30 return [];
31 }
32
34 public function beginSecondaryAuthentication( $user, array $reqs ) {
35 return $this->tryReset( $user, $reqs );
36 }
37
39 public function continueSecondaryAuthentication( $user, array $reqs ) {
40 return $this->tryReset( $user, $reqs );
41 }
42
44 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
45 return $this->tryReset( $user, $reqs );
46 }
47
49 public function continueSecondaryAccountCreation( $user, $creator, array $reqs ) {
50 return $this->tryReset( $user, $reqs );
51 }
52
59 protected function tryReset( User $user, array $reqs ) {
60 $data = $this->manager->getAuthenticationSessionData( 'reset-pass' );
61 if ( !$data ) {
63 }
64
65 if ( is_array( $data ) ) {
66 $data = (object)$data;
67 }
68 if ( !is_object( $data ) ) {
69 throw new \UnexpectedValueException( 'reset-pass is not valid' );
70 }
71
72 if ( !isset( $data->msg ) ) {
73 throw new \UnexpectedValueException( 'reset-pass msg is missing' );
74 } elseif ( !$data->msg instanceof Message ) {
75 throw new \UnexpectedValueException( 'reset-pass msg is not valid' );
76 } elseif ( !isset( $data->hard ) ) {
77 throw new \UnexpectedValueException( 'reset-pass hard is missing' );
78 } elseif ( isset( $data->req ) && (
79 !$data->req instanceof PasswordAuthenticationRequest ||
80 !array_key_exists( 'retype', $data->req->getFieldInfo() )
81 ) ) {
82 throw new \UnexpectedValueException( 'reset-pass req is not valid' );
83 }
84
85 if ( !$data->hard ) {
86 $req = ButtonAuthenticationRequest::getRequestByName( $reqs, 'skipReset' );
87 if ( $req ) {
88 $this->manager->removeAuthenticationSessionData( 'reset-pass' );
90 }
91 }
92
94 $needReq = $data->req ?? new PasswordAuthenticationRequest();
95 '@phan-var PasswordAuthenticationRequest $needReq';
96 if ( !$needReq->action ) {
97 $needReq->action = AuthManager::ACTION_CHANGE;
98 }
99 $needReq->required = $data->hard ? AuthenticationRequest::REQUIRED
101 $needReqs = [ $needReq ];
102 if ( !$data->hard ) {
103 $needReqs[] = new ButtonAuthenticationRequest(
104 'skipReset',
105 wfMessage( 'authprovider-resetpass-skip-label' ),
106 wfMessage( 'authprovider-resetpass-skip-help' )
107 );
108 }
109
111 $req = AuthenticationRequest::getRequestByClass( $reqs, get_class( $needReq ) );
112 '@phan-var PasswordAuthenticationRequest $req';
113 if ( !$req || !array_key_exists( 'retype', $req->getFieldInfo() ) ) {
114 return AuthenticationResponse::newUI( $needReqs, $data->msg, 'warning' );
115 }
116
117 if ( $req->password !== $req->retype ) {
118 return AuthenticationResponse::newUI( $needReqs, new Message( 'badretype' ), 'error' );
119 }
120
121 $req->username = $user->getName();
122 $status = $this->manager->allowsAuthenticationDataChange( $req );
123 if ( !$status->isGood() ) {
124 return AuthenticationResponse::newUI( $needReqs, $status->getMessage(), 'error' );
125 }
126 $scope = LoggerFactory::getContext()->addScoped( [
127 'context.passwordResetOnLogin' => $data->hard ? 'forced' : 'suggested',
128 ] );
129 $this->manager->changeAuthenticationData( $req );
130
131 $this->manager->removeAuthenticationSessionData( 'reset-pass' );
133 }
134}
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')
An authentication request that implements a single 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.There is no guarantee this will be called in a successful account crea...
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.Possible values for $action depend on whether th...
beginSecondaryAuthentication( $user, array $reqs)
Start an authentication flow.Note that this may be called for a user even if beginSecondaryAccountCre...
Create PSR-3 logger objects.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
User class for the MediaWiki software.
Definition User.php:108
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:1502