Path: blob/master/src/applications/auth/controller/PhabricatorAuthTerminateSessionController.php
12256 views
<?php12final class PhabricatorAuthTerminateSessionController3extends PhabricatorAuthController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();7$id = $request->getURIData('id');89$is_all = ($id === 'all');1011$query = id(new PhabricatorAuthSessionQuery())12->setViewer($viewer)13->withIdentityPHIDs(array($viewer->getPHID()));14if (!$is_all) {15$query->withIDs(array($id));16}1718$current_key = PhabricatorAuthSession::newSessionDigest(19new PhutilOpaqueEnvelope(20$request->getCookie(PhabricatorCookies::COOKIE_SESSION)));2122$sessions = $query->execute();23foreach ($sessions as $key => $session) {24$is_current = phutil_hashes_are_identical(25$session->getSessionKey(),26$current_key);27if ($is_current) {28// Don't terminate the current login session.29unset($sessions[$key]);30}31}3233$panel_uri = '/settings/panel/sessions/';3435if (!$sessions) {36return $this->newDialog()37->setTitle(pht('No Matching Sessions'))38->appendParagraph(39pht('There are no matching sessions to terminate.'))40->appendParagraph(41pht(42'(You can not terminate your current login session. To '.43'terminate it, log out.)'))44->addCancelButton($panel_uri);45}4647if ($request->isDialogFormPost()) {48foreach ($sessions as $session) {49$session->delete();50}51return id(new AphrontRedirectResponse())->setURI($panel_uri);52}5354if ($is_all) {55$title = pht('Terminate Sessions?');56$short = pht('Terminate Sessions');57$body = pht(58'Really terminate all sessions? (Your current login session will '.59'not be terminated.)');60} else {61$title = pht('Terminate Session?');62$short = pht('Terminate Session');63$body = pht(64'Really terminate session %s?',65phutil_tag('strong', array(), substr($session->getSessionKey(), 0, 6)));66}6768return $this->newDialog()69->setTitle($title)70->setShortTitle($short)71->appendParagraph($body)72->addSubmitButton(pht('Terminate'))73->addCancelButton($panel_uri);74}757677}787980