Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/storage/PhabricatorFile.php
| Show All 20 Lines | final class PhabricatorFile extends PhabricatorFileDAO | ||||
| implements | implements | ||||
| PhabricatorApplicationTransactionInterface, | PhabricatorApplicationTransactionInterface, | ||||
| PhabricatorTokenReceiverInterface, | PhabricatorTokenReceiverInterface, | ||||
| PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
| PhabricatorFlaggableInterface, | PhabricatorFlaggableInterface, | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorDestructibleInterface { | PhabricatorDestructibleInterface { | ||||
| const ONETIME_TEMPORARY_TOKEN_TYPE = 'file:onetime'; | |||||
| const STORAGE_FORMAT_RAW = 'raw'; | const STORAGE_FORMAT_RAW = 'raw'; | ||||
| const METADATA_IMAGE_WIDTH = 'width'; | const METADATA_IMAGE_WIDTH = 'width'; | ||||
| const METADATA_IMAGE_HEIGHT = 'height'; | const METADATA_IMAGE_HEIGHT = 'height'; | ||||
| const METADATA_CAN_CDN = 'canCDN'; | const METADATA_CAN_CDN = 'canCDN'; | ||||
| const METADATA_BUILTIN = 'builtin'; | const METADATA_BUILTIN = 'builtin'; | ||||
| const METADATA_PARTIAL = 'partial'; | const METADATA_PARTIAL = 'partial'; | ||||
| const METADATA_PROFILE = 'profile'; | const METADATA_PROFILE = 'profile'; | ||||
| ▲ Show 20 Lines • Show All 1,076 Lines • ▼ Show 20 Lines | |||||
| public function setIsProfileImage($value) { | public function setIsProfileImage($value) { | ||||
| $this->metadata[self::METADATA_PROFILE] = $value; | $this->metadata[self::METADATA_PROFILE] = $value; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function generateOneTimeToken() { | protected function generateOneTimeToken() { | ||||
| $key = Filesystem::readRandomCharacters(16); | $key = Filesystem::readRandomCharacters(16); | ||||
| $token_type = PhabricatorFileAccessTemporaryTokenType::TOKENTYPE; | |||||
| // Save the new secret. | // Save the new secret. | ||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||||
| $token = id(new PhabricatorAuthTemporaryToken()) | $token = id(new PhabricatorAuthTemporaryToken()) | ||||
| ->setTokenResource($this->getPHID()) | ->setTokenResource($this->getPHID()) | ||||
| ->setTokenType(self::ONETIME_TEMPORARY_TOKEN_TYPE) | ->setTokenType($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_type = PhabricatorFileAccessTemporaryTokenType::TOKENTYPE; | |||||
| $token = id(new PhabricatorAuthTemporaryTokenQuery()) | $token = id(new PhabricatorAuthTemporaryTokenQuery()) | ||||
| ->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
| ->withTokenResources(array($this->getPHID())) | ->withTokenResources(array($this->getPHID())) | ||||
| ->withTokenTypes(array(self::ONETIME_TEMPORARY_TOKEN_TYPE)) | ->withTokenTypes(array($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 225 Lines • Show Last 20 Lines | |||||