service = CrudService::singleton(); } public function index() { $this->returnFailure(new common_exception_RestApi('Not implemented.')); } /** * Optionally a specific rest controller may declare * aliases for parameters used for the rest communication */ protected function getParametersAliases() { return array_merge(parent::getParametersAliases(), [ 'login' => UserRdf::PROPERTY_LOGIN, 'password' => UserRdf::PROPERTY_PASSWORD, 'userLanguage' => UserRdf::PROPERTY_UILG, 'defaultLanguage' => UserRdf::PROPERTY_DEFLG, 'firstName' => UserRdf::PROPERTY_FIRSTNAME, 'lastName' => UserRdf::PROPERTY_LASTNAME, 'mail' => UserRdf::PROPERTY_MAIL ]); } /** * Optional Requirements for parameters to be sent on every service */ protected function getParametersRequirements() { return [ 'post' => ["login", "password", "userLanguage"] ]; } /** * @param null $uri * @return mixed * @throws \common_exception_NotImplemented */ public function get($uri = null) { $this->returnFailure(new common_exception_RestApi('Not implemented.')); } /** * @param string $uri * @return mixed * @throws \common_exception_NotImplemented */ public function put($uri) { $this->returnFailure(new common_exception_RestApi('Not implemented.')); } public function post() { try { /** @var \core_kernel_classes_Resource $testTakerResource */ $testTakerResource = parent::post(); $parameters = $this->getParameters(); $hashForKey = array_key_exists(UserRdf::PROPERTY_PASSWORD, $parameters) ? UserHashForEncryption::hash($parameters[UserRdf::PROPERTY_PASSWORD]) : null; /** @var tao_models_classes_UserService $userService */ $userService = $this->getServiceLocator()->get(tao_models_classes_UserService::SERVICE_ID); $userService->triggerUpdatedEvent( $testTakerResource, [UserRdf::PROPERTY_PASSWORD => $testTakerResource->getProperty(UserRdf::PROPERTY_PASSWORD)], $hashForKey ); $this->returnSuccess([ 'success' => true, 'uri' => $testTakerResource->getUri(), ], false); } catch (PasswordConstraintsException $e) { $this->returnFailure(new common_exception_RestApi($e->getMessage())); } catch (common_exception_ValidationFailed $e) { $alias = $this->reverseSearchAlias($e->getField()); $this->returnFailure(new common_exception_ValidationFailed($alias, null, $e->getCode())); } catch (Exception $e) { $this->returnFailure($e); } } /** * @param string $uri * @return mixed * @throws \common_exception_NotImplemented */ public function delete($uri = null) { $this->returnFailure(new common_exception_RestApi('Not implemented.')); } /** * @throws common_exception_RestApi * * @return array */ protected function getParameters() { if (!$this->parameters) { $this->parameters = parent::getParameters(); } if ( $this->getRequestMethod() === 'POST' && $classResource = $this->getClassFromRequest($this->getClass(self::ROOT_CLASS)) ) { $this->parameters[OntologyRdf::RDF_TYPE] = $classResource->getUri(); } return $this->parameters; } }