Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/storage/PhabricatorAuthTemporaryToken.php
Show All 25 Lines | return array( | ||||
), | ), | ||||
'key_expires' => array( | 'key_expires' => array( | ||||
'columns' => array('tokenExpires'), | 'columns' => array('tokenExpires'), | ||||
), | ), | ||||
), | ), | ||||
) + parent::getConfiguration(); | ) + parent::getConfiguration(); | ||||
} | } | ||||
private function newTokenTypeImplementation() { | |||||
$types = PhabricatorAuthTemporaryTokenType::getAllTypes(); | |||||
$type = idx($types, $this->tokenType); | |||||
if ($type) { | |||||
return clone $type; | |||||
} | |||||
return null; | |||||
} | |||||
public function getTokenReadableTypeName() { | public function getTokenReadableTypeName() { | ||||
// Eventually, it would be nice to let applications implement token types | $type = $this->newTokenTypeImplementation(); | ||||
// so we can put this in modular subclasses. | if ($type) { | ||||
switch ($this->tokenType) { | return $type->getTokenReadableTypeName($this); | ||||
case PhabricatorAuthSessionEngine::ONETIME_TEMPORARY_TOKEN_TYPE: | |||||
return pht('One-Time Login Token'); | |||||
case PhabricatorAuthSessionEngine::PASSWORD_TEMPORARY_TOKEN_TYPE: | |||||
return pht('Password Reset Token'); | |||||
} | } | ||||
return $this->tokenType; | return $this->tokenType; | ||||
} | } | ||||
public function isRevocable() { | public function isRevocable() { | ||||
if ($this->tokenExpires < time()) { | if ($this->tokenExpires < time()) { | ||||
return false; | return false; | ||||
} | } | ||||
switch ($this->tokenType) { | $type = $this->newTokenTypeImplementation(); | ||||
case PhabricatorAuthSessionEngine::ONETIME_TEMPORARY_TOKEN_TYPE: | if ($type) { | ||||
case PhabricatorAuthSessionEngine::PASSWORD_TEMPORARY_TOKEN_TYPE: | return $type->isTokenRevocable($this); | ||||
return true; | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
public function revokeToken() { | public function revokeToken() { | ||||
if ($this->isRevocable()) { | if ($this->isRevocable()) { | ||||
$this->setTokenExpires(PhabricatorTime::getNow() - 1)->save(); | $this->setTokenExpires(PhabricatorTime::getNow() - 1)->save(); | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |