Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / settings / panel / PhabricatorSessionsSettingsPanel.php
blobfb10572e11a51eef7b2bcff58c4ce649b42c500e
1 <?php
3 final class PhabricatorSessionsSettingsPanel extends PhabricatorSettingsPanel {
5 public function getPanelKey() {
6 return 'sessions';
9 public function getPanelName() {
10 return pht('Sessions');
13 public function getPanelMenuIcon() {
14 return 'fa-user';
17 public function getPanelGroupKey() {
18 return PhabricatorSettingsLogsPanelGroup::PANELGROUPKEY;
21 public function isEnabled() {
22 return true;
25 public function processRequest(AphrontRequest $request) {
26 $viewer = $request->getUser();
28 $accounts = id(new PhabricatorExternalAccountQuery())
29 ->setViewer($viewer)
30 ->withUserPHIDs(array($viewer->getPHID()))
31 ->requireCapabilities(
32 array(
33 PhabricatorPolicyCapability::CAN_VIEW,
34 PhabricatorPolicyCapability::CAN_EDIT,
36 ->execute();
38 $identity_phids = mpull($accounts, 'getPHID');
39 $identity_phids[] = $viewer->getPHID();
41 $sessions = id(new PhabricatorAuthSessionQuery())
42 ->setViewer($viewer)
43 ->withIdentityPHIDs($identity_phids)
44 ->execute();
46 $handles = id(new PhabricatorHandleQuery())
47 ->setViewer($viewer)
48 ->withPHIDs($identity_phids)
49 ->execute();
51 $current_key = PhabricatorAuthSession::newSessionDigest(
52 new PhutilOpaqueEnvelope(
53 $request->getCookie(PhabricatorCookies::COOKIE_SESSION)));
55 $rows = array();
56 $rowc = array();
57 foreach ($sessions as $session) {
58 $is_current = phutil_hashes_are_identical(
59 $session->getSessionKey(),
60 $current_key);
61 if ($is_current) {
62 $rowc[] = 'highlighted';
63 $button = phutil_tag(
64 'a',
65 array(
66 'class' => 'small button button-grey disabled',
68 pht('Current'));
69 } else {
70 $rowc[] = null;
71 $button = javelin_tag(
72 'a',
73 array(
74 'href' => '/auth/session/terminate/'.$session->getID().'/',
75 'class' => 'small button button-grey',
76 'sigil' => 'workflow',
78 pht('Terminate'));
81 $hisec = ($session->getHighSecurityUntil() - time());
83 $rows[] = array(
84 $handles[$session->getUserPHID()]->renderLink(),
85 substr($session->getSessionKey(), 0, 6),
86 $session->getType(),
87 ($hisec > 0)
88 ? phutil_format_relative_time($hisec)
89 : null,
90 phabricator_datetime($session->getSessionStart(), $viewer),
91 phabricator_date($session->getSessionExpires(), $viewer),
92 $button,
96 $table = new AphrontTableView($rows);
97 $table->setNoDataString(pht("You don't have any active sessions."));
98 $table->setRowClasses($rowc);
99 $table->setHeaders(
100 array(
101 pht('Identity'),
102 pht('Session'),
103 pht('Type'),
104 pht('HiSec'),
105 pht('Created'),
106 pht('Expires'),
107 pht(''),
109 $table->setColumnClasses(
110 array(
111 'wide',
112 'n',
114 'right',
115 'right',
116 'right',
117 'action',
120 $buttons = array();
121 $buttons[] = id(new PHUIButtonView())
122 ->setTag('a')
123 ->setIcon('fa-warning')
124 ->setText(pht('Terminate All Sessions'))
125 ->setHref('/auth/session/terminate/all/')
126 ->setWorkflow(true)
127 ->setColor(PHUIButtonView::RED);
129 $hisec = ($viewer->getSession()->getHighSecurityUntil() - time());
130 if ($hisec > 0) {
131 $buttons[] = id(new PHUIButtonView())
132 ->setTag('a')
133 ->setIcon('fa-lock')
134 ->setText(pht('Leave High Security'))
135 ->setHref('/auth/session/downgrade/')
136 ->setWorkflow(true)
137 ->setColor(PHUIButtonView::RED);
140 return $this->newBox(pht('Active Login Sessions'), $table, $buttons);