MediaWiki REL1_34
ResetPasswordSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
38
39 public function getAuthenticationRequests( $action, array $options ) {
40 return [];
41 }
42
43 public function beginSecondaryAuthentication( $user, array $reqs ) {
44 return $this->tryReset( $user, $reqs );
45 }
46
47 public function continueSecondaryAuthentication( $user, array $reqs ) {
48 return $this->tryReset( $user, $reqs );
49 }
50
51 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
52 return $this->tryReset( $user, $reqs );
53 }
54
55 public function continueSecondaryAccountCreation( $user, $creator, array $reqs ) {
56 return $this->tryReset( $user, $reqs );
57 }
58
65 protected function tryReset( \User $user, array $reqs ) {
66 $data = $this->manager->getAuthenticationSessionData( 'reset-pass' );
67 if ( !$data ) {
69 }
70
71 if ( is_array( $data ) ) {
72 $data = (object)$data;
73 }
74 if ( !is_object( $data ) ) {
75 throw new \UnexpectedValueException( 'reset-pass is not valid' );
76 }
77
78 if ( !isset( $data->msg ) ) {
79 throw new \UnexpectedValueException( 'reset-pass msg is missing' );
80 } elseif ( !$data->msg instanceof \Message ) {
81 throw new \UnexpectedValueException( 'reset-pass msg is not valid' );
82 } elseif ( !isset( $data->hard ) ) {
83 throw new \UnexpectedValueException( 'reset-pass hard is missing' );
84 } elseif ( isset( $data->req ) && (
85 !$data->req instanceof PasswordAuthenticationRequest ||
86 !array_key_exists( 'retype', $data->req->getFieldInfo() )
87 ) ) {
88 throw new \UnexpectedValueException( 'reset-pass req is not valid' );
89 }
90
91 if ( !$data->hard ) {
92 $req = ButtonAuthenticationRequest::getRequestByName( $reqs, 'skipReset' );
93 if ( $req ) {
94 $this->manager->removeAuthenticationSessionData( 'reset-pass' );
96 }
97 }
98
100 $needReq = $data->req ?? new PasswordAuthenticationRequest();
101 '@phan-var PasswordAuthenticationRequest $needReq';
102 if ( !$needReq->action ) {
103 $needReq->action = AuthManager::ACTION_CHANGE;
104 }
105 $needReq->required = $data->hard ? AuthenticationRequest::REQUIRED
107 $needReqs = [ $needReq ];
108 if ( !$data->hard ) {
109 $needReqs[] = new ButtonAuthenticationRequest(
110 'skipReset',
111 wfMessage( 'authprovider-resetpass-skip-label' ),
112 wfMessage( 'authprovider-resetpass-skip-help' )
113 );
114 }
115
116 $req = AuthenticationRequest::getRequestByClass( $reqs, get_class( $needReq ) );
117 if ( !$req || !array_key_exists( 'retype', $req->getFieldInfo() ) ) {
118 return AuthenticationResponse::newUI( $needReqs, $data->msg, 'warning' );
119 }
120
121 if ( $req->password !== $req->retype ) {
122 return AuthenticationResponse::newUI( $needReqs, new \Message( 'badretype' ), 'error' );
123 }
124
125 $req->username = $user->getName();
126 $status = $this->manager->allowsAuthenticationDataChange( $req );
127 if ( !$status->isGood() ) {
128 return AuthenticationResponse::newUI( $needReqs, $status->getMessage(), 'error' );
129 }
130 $this->manager->changeAuthenticationData( $req );
131
132 $this->manager->removeAuthenticationSessionData( 'reset-pass' );
134 }
135}
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.
continueSecondaryAuthentication( $user, array $reqs)
Continue an authentication flow.
beginSecondaryAccountCreation( $user, $creator, array $reqs)
Start an account creation flow.
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
The Message class provides methods which fulfil two basic services:
Definition Message.php:162
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:2364