Page MenuHomePhabricator
Paste P2081

DebugAuthProvider
ActivePublic

Authored by avivey on Dec 7 2017, 1:56 PM.
<?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';
}
}