public function Execute() { $activityData = $this->getRestActivityData(); if (!$activityData || !Loader::includeModule('rest')) { return CBPActivityExecutionStatus::Closed; } $propertiesData = array(); if (!empty($activityData['PROPERTIES'])) { foreach ($activityData['PROPERTIES'] as $name => $property) { $propertiesData[$name] = $this->{$name}; } } $auth = null; $userId = $this->AuthUserId; if ($userId > 0) { $auth = CRestUtil::getAuthForEvent($activityData['APP_ID'], $userId, array('WORKFLOW_ID' => $this->getWorkflowInstanceId(), 'ACTIVITY_NAME' => $this->name, 'CODE' => $activityData['CODE'])); } $this->eventId = \Bitrix\Main\Security\Random::getString(32, true); $queryItems = array(Sqs::queryItem($activityData['HANDLER'], array('workflow_id' => $this->getWorkflowInstanceId(), 'code' => $activityData['CODE'], 'event_token' => self::generateToken($this->getWorkflowInstanceId(), $this->name, $this->eventId), 'properties' => $propertiesData, 'auth' => $auth, 'ts' => time()))); Sqs::query($queryItems); if ($this->SetStatusMessage == 'Y') { $message = $this->StatusMessage; if (empty($message)) { $message = Loc::getMessage('BPRA_DEFAULT_STATUS_MESSAGE'); } $this->SetStatusTitle($message); } if ($this->isInEventActivityMode || $this->UseSubscription != 'Y') { return CBPActivityExecutionStatus::Closed; } $this->Subscribe($this); $this->isInEventActivityMode = false; return CBPActivityExecutionStatus::Executing; }
public static function getUniqueEventId() { list($usec, $sec) = explode(" ", microtime()); $uniqid = substr(base_convert($sec . substr($usec, 2), 10, 36), 0, 16); if (strlen($uniqid) < 16) { $uniqid .= Random::getString(16 - strlen($uniqid)); } return $uniqid; }
protected function processActionDefault() { $validPassword = true; if ($this->externalLink->hasPassword()) { $validPassword = $this->checkPassword(); } $file = $this->externalLink->getFile(); $downloadToken = Random::getString(12); $this->storeDownloadToken($file, $downloadToken); $this->arResult = array('FILE' => array('ID' => $file->getId(), 'IS_IMAGE' => TypeFile::isImage($file->getName()), 'ICON_CLASS' => Icon::getIconClassByObject($file), 'UPDATE_TIME' => $file->getUpdateTime(), 'NAME' => $file->getName(), 'SIZE' => $file->getSize(), 'DOWNLOAD_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'download', 'token' => $downloadToken)), 'SHOW_PREVIEW_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'showPreview', 'token' => $downloadToken)), 'SHOW_FILE_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'showFile', 'token' => $downloadToken)), 'VIEW_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getShortUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'default'), true), 'VIEW_FULL_URL' => \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $this->externalLink->getHash(), 'action' => 'default'))), 'PROTECTED_BY_PASSWORD' => $this->externalLink->hasPassword(), 'VALID_PASSWORD' => $validPassword); $this->includeComponentTemplate(); }
/** * Generate new recovery codes for provided user * Previously generated codes will be removed * * @param int $userId Needed user id. * @return bool Returns true if successful * @throws ArgumentTypeException */ public static function regenerateCodes($userId) { $userId = (int) $userId; if ($userId <= 0) { throw new ArgumentTypeException('userId', 'positive integer'); } static::clearByUser($userId); $randomVector = Random::getString(static::CODES_PER_USER * 8); $randomVector = str_split($randomVector, 4); for ($i = 0; $i < static::CODES_PER_USER; $i++) { $code = array('USER_ID' => $userId, 'USED' => 'N', 'CODE' => sprintf('%s-%s', $randomVector[$i * 2], $randomVector[$i * 2 + 1])); static::add($code); } return true; }
public static function createSid() { return \Bitrix\Main\Security\Random::getString(32, true); }
/** * Reinitialize OTP (generate new secret, set default algo, etc), must be called before connect new device * * @param null $newSecret Using custom secret. * @return $this */ public function regenerate($newSecret = null) { if (!$newSecret) { $newSecret = Random::getBytes(static::SECRET_LENGTH); } $this->regenerated = true; return $this->setType(static::getDefaultType())->setAttempts(0)->setSkipMandatory(false)->setInitialDate(new Type\DateTime())->setDeactivateUntil(null)->setParams(null)->setSecret($newSecret)->setActive(true); }