This will allow providers to know whether the call is just for testing
(from ApiQueryUsers) or for actual creation, and skip duplicate work
when testForAccountCreation() is going to be called.
Change-Id: Id3ef713fd377135d78f66e5100dedd4689293b59
Depends-On: I4af8b3b692f60c42f8685b90be5936da7ba4e2e2
Depends-On: Ie9639a15d04b387be0e72754301eb6d91cd8adc2
Depends-On: I063cbdfbd9a223bf2391fce2b714ab82ddd3272f
Depends-On: I7c67512634f6e72251911238f083857da9fd3f84
return \StatusValue::newGood();
}
return \StatusValue::newGood();
}
- public function testUserForCreation( $user, $autocreate ) {
+ public function testUserForCreation( $user, $autocreate, array $options = [] ) {
return \StatusValue::newGood();
}
return \StatusValue::newGood();
}
public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
}
public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
}
- public function testUserForCreation( $user, $autocreate ) {
+ public function testUserForCreation( $user, $autocreate, array $options = [] ) {
return \StatusValue::newGood();
}
return \StatusValue::newGood();
}
public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
}
public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
}
- public function testUserForCreation( $user, $autocreate ) {
+ public function testUserForCreation( $user, $autocreate, array $options = [] ) {
return \StatusValue::newGood();
}
return \StatusValue::newGood();
}
/**
* Determine whether a particular account can be created
* @param string $username
/**
* Determine whether a particular account can be created
* @param string $username
- * @param int $flags Bitfield of User:READ_* constants
+ * @param array $options
+ * - flags: (int) Bitfield of User:READ_* constants, default User::READ_NORMAL
+ * - creating: (bool) For internal use only. Never specify this.
- public function canCreateAccount( $username, $flags = User::READ_NORMAL ) {
+ public function canCreateAccount( $username, $options = [] ) {
+ // Back compat
+ if ( is_int( $options ) ) {
+ $options = [ 'flags' => $options ];
+ }
+ $options += [
+ 'flags' => User::READ_NORMAL,
+ 'creating' => false,
+ ];
+ $flags = $options['flags'];
+
if ( !$this->canCreateAccounts() ) {
return Status::newFatal( 'authmanager-create-disabled' );
}
if ( !$this->canCreateAccounts() ) {
return Status::newFatal( 'authmanager-create-disabled' );
}
$this->getPrimaryAuthenticationProviders() +
$this->getSecondaryAuthenticationProviders();
foreach ( $providers as $provider ) {
$this->getPrimaryAuthenticationProviders() +
$this->getSecondaryAuthenticationProviders();
foreach ( $providers as $provider ) {
- $status = $provider->testUserForCreation( $user, false );
+ $status = $provider->testUserForCreation( $user, false, $options );
if ( !$status->isGood() ) {
return Status::wrap( $status );
}
if ( !$status->isGood() ) {
return Status::wrap( $status );
}
return AuthenticationResponse::newFail( $status->getMessage() );
}
return AuthenticationResponse::newFail( $status->getMessage() );
}
- $status = $this->canCreateAccount( $username, User::READ_LOCKING );
+ $status = $this->canCreateAccount(
+ $username, [ 'flags' => User::READ_LOCKING, 'creating' => true ]
+ );
if ( !$status->isGood() ) {
$this->logger->debug( __METHOD__ . ': {user} cannot be created: {reason}', [
'user' => $username,
if ( !$status->isGood() ) {
$this->logger->debug( __METHOD__ . ': {user} cannot be created: {reason}', [
'user' => $username,
}
// Denied by providers?
}
// Denied by providers?
+ $options = [
+ 'flags' => User::READ_LATEST,
+ 'creating' => true,
+ ];
$providers = $this->getPreAuthenticationProviders() +
$this->getPrimaryAuthenticationProviders() +
$this->getSecondaryAuthenticationProviders();
foreach ( $providers as $provider ) {
$providers = $this->getPreAuthenticationProviders() +
$this->getPrimaryAuthenticationProviders() +
$this->getSecondaryAuthenticationProviders();
foreach ( $providers as $provider ) {
- $status = $provider->testUserForCreation( $user, $source );
+ $status = $provider->testUserForCreation( $user, $source, $options );
if ( !$status->isGood() ) {
$ret = Status::wrap( $status );
$this->logger->debug( __METHOD__ . ': Provider denied creation of {username}: {reason}', [
if ( !$status->isGood() ) {
$ret = Status::wrap( $status );
$this->logger->debug( __METHOD__ . ': Provider denied creation of {username}: {reason}', [
return AuthenticationResponse::newAbstain();
}
return AuthenticationResponse::newAbstain();
}
- public function testUserForCreation( $user, $autocreate ) {
+ public function testUserForCreation( $user, $autocreate, array $options = [] ) {
$block = $user->isBlockedFromCreateAccount();
if ( $block ) {
$errorParams = [
$block = $user->isBlockedFromCreateAccount();
if ( $block ) {
$errorParams = [
return StatusValue::newGood();
}
return StatusValue::newGood();
}
- public function testUserForCreation( $user, $autocreate ) {
+ public function testUserForCreation( $user, $autocreate, array $options = [] ) {
if ( $autocreate !== false ) {
$abortError = '';
if ( !\Hooks::run( 'AbortAutoAccount', [ $user, &$abortError ] ) ) {
if ( $autocreate !== false ) {
$abortError = '';
if ( !\Hooks::run( 'AbortAutoAccount', [ $user, &$abortError ] ) ) {
* into such.
* @param bool|string $autocreate False if this is not an auto-creation, or
* the source of the auto-creation passed to AuthManager::autoCreateUser().
* into such.
* @param bool|string $autocreate False if this is not an auto-creation, or
* the source of the auto-creation passed to AuthManager::autoCreateUser().
+ * @param array $options
+ * - flags: (int) Bitfield of User:READ_* constants, default User::READ_NORMAL
+ * - creating: (bool) If false (or missing), this call is only testing if
+ * a user could be created. If set, this (non-autocreation) is for
+ * actually creating an account and will be followed by a call to
+ * testForAccountCreation(). In this case, the provider might return
+ * StatusValue::newGood() here and let the later call to
+ * testForAccountCreation() do a more thorough test.
- public function testUserForCreation( $user, $autocreate );
+ public function testUserForCreation( $user, $autocreate, array $options = [] );
/**
* Post-creation callback
/**
* Post-creation callback
* into such.
* @param bool|string $autocreate False if this is not an auto-creation, or
* the source of the auto-creation passed to AuthManager::autoCreateUser().
* into such.
* @param bool|string $autocreate False if this is not an auto-creation, or
* the source of the auto-creation passed to AuthManager::autoCreateUser().
+ * @param array $options
+ * - flags: (int) Bitfield of User:READ_* constants, default User::READ_NORMAL
+ * - creating: (bool) If false (or missing), this call is only testing if
+ * a user could be created. If set, this (non-autocreation) is for
+ * actually creating an account and will be followed by a call to
+ * testForAccountCreation(). In this case, the provider might return
+ * StatusValue::newGood() here and let the later call to
+ * testForAccountCreation() do a more thorough test.
- public function testUserForCreation( $user, $autocreate );
+ public function testUserForCreation( $user, $autocreate, array $options = [] );
/**
* Post-auto-creation callback
/**
* Post-auto-creation callback
* into such.
* @param bool|string $autocreate False if this is not an auto-creation, or
* the source of the auto-creation passed to AuthManager::autoCreateUser().
* into such.
* @param bool|string $autocreate False if this is not an auto-creation, or
* the source of the auto-creation passed to AuthManager::autoCreateUser().
+ * @param array $options
+ * - flags: (int) Bitfield of User:READ_* constants, default User::READ_NORMAL
+ * - creating: (bool) If false (or missing), this call is only testing if
+ * a user could be created. If set, this (non-autocreation) is for
+ * actually creating an account and will be followed by a call to
+ * testForAccountCreation(). In this case, the provider might return
+ * StatusValue::newGood() here and let the later call to
+ * testForAccountCreation() do a more thorough test.
- public function testUserForCreation( $user, $autocreate );
+ public function testUserForCreation( $user, $autocreate, array $options = [] );
/**
* Post-auto-creation callback
/**
* Post-auto-creation callback