<?php
namespace Modules\Documents\ImportedDocuments\Webservice\Model\ExecOperation; class Authenticate extends GeneralAbstract { protected $sessionToken = NULL; protected function checkAuth() { } protected function checkRequest() { if (!$this->request->username || !$this->request->authToken) { throw new \RuntimeException(sprintf('Username and authToken must be set for operation `%s`.', stripClassNamespace(get_class($this)))); } $importedDocumentSystemsObj = new \App\EntityList\ImportedDocumentsSystems(); $importedDocumentSystemsObj->setFilter('username', '=', $this->request->username); $importedDocumentSystemsObj->setFilter('token', '=', htmlClean($this->request->authToken)); $importedDocumentSystemsList = $importedDocumentSystemsObj->exportRecords(); if (!count($importedDocumentSystemsList)) { throw new \RuntimeException(sprintf('Username or authToken are invalid for operation `%s`.', stripClassNamespace(get_class($this)))); } if (count($importedDocumentSystemsList) != 1) { throw new \RuntimeException("We found more than one system associated with the username and authToken from request"); } } protected function executeRequestedOperation() { try { $sessionTokenObject = new \Modules\Documents\ImportedDocuments\Webservice\Model\SessionToken($this->request->username); $newSessionToken = $sessionTokenObject->getSessionToken(); } catch (\Modules\Documents\ImportedDocuments\Webservice\Model\SessionTokenException $ex) { \Engine\Os::sleep(\Engine\RandomGenerator::randomFloat(1, 2)); throw new \RuntimeException($ex->getMessage()); } $this->sessionToken = $newSessionToken; } public function getSessionToken() { return $this->sessionToken; } }