public function setPassword($user, $password) { $data = ['username' => $user->getName(), 'password' => $password]; if ($this->domain !== null && $this->domain !== '') { $data['domain'] = $this->domain; } $reqs = AuthManager::singleton()->getAuthenticationRequests(AuthManager::ACTION_CHANGE); $reqs = AuthenticationRequest::loadRequestsFromSubmission($reqs, $data); foreach ($reqs as $req) { $status = AuthManager::singleton()->allowsAuthenticationDataChange($req); if (!$status->isGood()) { $this->logger->info(__METHOD__ . ': Password change rejected: {reason}', ['username' => $data['username'], 'reason' => $status->getWikiText(null, null, 'en')]); return false; } } foreach ($reqs as $req) { AuthManager::singleton()->changeAuthenticationData($req); } return true; }
public function addUser($user, $password, $email = '', $realname = '') { global $wgUser; $data = ['username' => $user->getName(), 'password' => $password, 'retype' => $password, 'email' => $email, 'realname' => $realname]; if ($this->domain !== null && $this->domain !== '') { $data['domain'] = $this->domain; } $reqs = AuthManager::singleton()->getAuthenticationRequests(AuthManager::ACTION_CREATE); $reqs = AuthenticationRequest::loadRequestsFromSubmission($reqs, $data); $res = AuthManager::singleton()->beginAccountCreation($wgUser, $reqs, 'null:'); switch ($res->status) { case AuthenticationResponse::PASS: return true; case AuthenticationResponse::FAIL: // Hope it's not a PreAuthenticationProvider that failed... $msg = $res->message instanceof \Message ? $res->message : new \Message($res->message); $this->logger->info(__METHOD__ . ': Authentication failed: ' . $msg->plain()); return false; default: throw new \BadMethodCallException('AuthManager does not support such simplified account creation'); } }