user = $user; $this->centralId = $centralId; } public function getUser(): UserIdentity { return $this->user; } /** * @return int The central ID of this user */ public function getCentralId(): int { return $this->centralId; } /** * @return string */ public function getIssuer() { global $wgSitename, $wgOATHAuthAccountPrefix; if ( $wgOATHAuthAccountPrefix !== false ) { return $wgOATHAuthAccountPrefix; } return $wgSitename; } /** * @return string */ public function getAccount() { return $this->user->getName(); } /** * Get the key associated with this user. * * @return IAuthKey[] */ public function getKeys(): array { return $this->keys; } /** * @param string $moduleName As in IModule::getName(). * @return IAuthKey[] */ public function getKeysForModule( string $moduleName ): array { return array_values( array_filter( $this->keys, static fn ( IAuthKey $key ) => $key->getModule() === $moduleName ) ); } public function removeKey( IAuthKey $key ) { $keyId = $key->getId(); $this->keys = array_values( array_filter( $this->keys, static fn ( IAuthKey $key ) => $key->getId() !== $keyId ) ); } /** * @param string $moduleName As in IModule::getName() */ public function removeKeysForModule( string $moduleName ): void { $this->keys = array_values( array_filter( $this->keys, static fn ( IAuthKey $key ) => $key->getModule() !== $moduleName ) ); } /** * Adds single key to the key array * * @param IAuthKey $key */ public function addKey( IAuthKey $key ) { $this->keys[] = $key; } /** * Gets the module instance associated with this user * * @return IModule|null * @deprecated Use {@link IAuthKey::getModule()} instead */ public function getModule() { // wfDeprecated( 'OATHUser::getModule()', '1.44', 'OATHAuth' ); if ( !$this->keys ) { return null; } $key = $this->keys[0]; return OATHAuthServices::getInstance()->getModuleRegistry()->getModuleByKey( $key->getModule() ); } /** * @return bool Whether this user has two-factor authentication enabled or not */ public function isTwoFactorAuthEnabled(): bool { return count( $this->getKeys() ) >= 1; } /** * Disables current (if any) auth method */ public function disable() { $this->keys = []; } }