Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/PhabricatorFile.php
| Show First 20 Lines • Show All 1,117 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| protected function generateOneTimeToken() { | protected function generateOneTimeToken() { | ||||
| $key = Filesystem::readRandomCharacters(16); | $key = Filesystem::readRandomCharacters(16); | ||||
| // Save the new secret. | // Save the new secret. | ||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||||
| $token = id(new PhabricatorAuthTemporaryToken()) | $token = id(new PhabricatorAuthTemporaryToken()) | ||||
| ->setObjectPHID($this->getPHID()) | ->setTokenResource($this->getPHID()) | ||||
| ->setTokenType(self::ONETIME_TEMPORARY_TOKEN_TYPE) | ->setTokenType(self::ONETIME_TEMPORARY_TOKEN_TYPE) | ||||
| ->setTokenExpires(time() + phutil_units('1 hour in seconds')) | ->setTokenExpires(time() + phutil_units('1 hour in seconds')) | ||||
| ->setTokenCode(PhabricatorHash::digest($key)) | ->setTokenCode(PhabricatorHash::digest($key)) | ||||
| ->save(); | ->save(); | ||||
| unset($unguarded); | unset($unguarded); | ||||
| return $key; | return $key; | ||||
| } | } | ||||
| public function validateOneTimeToken($token_code) { | public function validateOneTimeToken($token_code) { | ||||
| $token = id(new PhabricatorAuthTemporaryTokenQuery()) | $token = id(new PhabricatorAuthTemporaryTokenQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->withObjectPHIDs(array($this->getPHID())) | ->withTokenResources(array($this->getPHID())) | ||||
| ->withTokenTypes(array(self::ONETIME_TEMPORARY_TOKEN_TYPE)) | ->withTokenTypes(array(self::ONETIME_TEMPORARY_TOKEN_TYPE)) | ||||
| ->withExpired(false) | ->withExpired(false) | ||||
| ->withTokenCodes(array(PhabricatorHash::digest($token_code))) | ->withTokenCodes(array(PhabricatorHash::digest($token_code))) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| return $token; | return $token; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 226 Lines • Show Last 20 Lines | |||||