Page MenuHomePhabricator

DebugAuthProvider

Authored By
avivey
Dec 7 2017, 1:56 PM
Size
1 KB
Referenced Files
None
Subscribers
None

DebugAuthProvider

<?php
/**
* Drop in /extensions/ to quickly switch user accounts. For dev only!
*/
class DebugAuthProvider extends PhabricatorAuthProvider {
private $adapter;
public function getProviderName() {
return 'Debug';
}
public function getAdapter() {
if (!$this->adapter) {
$this->adapter = new DebugAuthAdapter();
}
return $this->adapter;
}
public function processLoginRequest(
PhabricatorAuthLoginController $controller) {
$request = $controller->getRequest();
$username = $request->getStr('username');
$user = id(new PhabricatorUser())->loadOneWhere(
'username = %s',
$username);
if ($user) {
$account = id(new PhabricatorExternalAccount())
->setUserPHID($user->getPHID());
return array($account, null);
}
$response = new Aphront400Response();
return array(null, $response);
}
protected function renderLoginForm(AphrontRequest $request, $mode) {
$users = id(new PhabricatorPeopleQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->execute();
$icon = id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_LOGIN)
->setSpriteIcon($this->getLoginIcon());
$login_uri = $this->getLoginURI();
$buttons = array();
foreach ($users as $user) {
$buttons[] = id(new PHUIButtonView())
->setTag('a')
->setSize(PHUIButtonView::BIG)
->setColor(PHUIButtonView::GREY)
->setIcon($icon)
->setHref(hsprintf('%s?username=%s', $login_uri, $user->getUserName()))
->setText($user->getUserName())
->setSubtext($user->getRealName());
}
return $buttons;
}
}
class DebugAuthAdapter extends PhutilAuthAdapter {
public function getAccountID() {
return 'moosh';
}
public function getAdapterType() {
return 'debug';
}
public function getAdapterDomain() {
return 'localhost';
}
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
864289
Default Alt Text
DebugAuthProvider (1 KB)

Event Timeline