Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P2081
DebugAuthProvider
Active
Public
Actions
Authored by
avivey
on Dec 7 2017, 1:56 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F5313259: DebugAuthProvider
Dec 7 2017, 1:56 PM
2017-12-07 13:56:02 (UTC+0)
Subscribers
None
<?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'
;
}
}
Event Timeline
avivey
created this paste.
Dec 7 2017, 1:56 PM
2017-12-07 13:56:02 (UTC+0)
avivey
mentioned this in
T13157: Provide more advanced tools for developing against Phabricator and discovering PHIDs
.
Jun 21 2018, 7:47 PM
2018-06-21 19:47:06 (UTC+0)
Log In to Comment