/** * Run the controller * * @param common_http_Request $pRequest * @throws \ActionEnforcingException * @throws \Exception * @throws \common_exception_Error * @throws \common_ext_ExtensionException */ public function legacy(common_http_Request $pRequest) { $resolver = new Resolver($pRequest); // load the responsible extension $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId()); \Context::getInstance()->setExtensionName($resolver->getExtensionId()); // load translations $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage(); \tao_helpers_I18n::init($ext, $uiLang); //if the controller is a rest controller we try to authenticate the user $controllerClass = $resolver->getControllerClass(); if (is_subclass_of($controllerClass, \tao_actions_RestController::class)) { $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest()); try { $user = $authAdapter->authenticate(); $session = new \common_session_RestSession($user); \common_session_SessionManager::startSession($session); } catch (\common_user_auth_AuthFailedException $e) { $data['success'] = false; $data['errorCode'] = '401'; $data['errorMsg'] = 'You are not authorized to access this functionality.'; $data['version'] = TAO_VERSION; header('HTTP/1.0 401 Unauthorized'); header('WWW-Authenticate: Basic realm="' . GENERIS_INSTANCE_NAME . '"'); echo json_encode($data); exit(0); } } try { $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $pRequest->getParams()); $enforcer->execute(); } catch (InterruptedActionException $iE) { // Nothing to do here. } }
/** * (non-PHPdoc) * @see FrontController::loadModule() */ public function loadModule() { $resolver = new Resolver($this->getRequest()); // load the responsible extension $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId()); \Context::getInstance()->setExtensionName($resolver->getExtensionId()); // load translations $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage(); \tao_helpers_I18n::init($ext, $uiLang); //if the controller is a rest controller we try to authenticate the user $controllerClass = $resolver->getControllerClass(); if (is_subclass_of($controllerClass, 'tao_actions_CommonRestModule')) { $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest()); try { $user = $authAdapter->authenticate(); $session = new \common_session_RestSession($user); \common_session_SessionManager::startSession($session); } catch (\common_user_auth_AuthFailedException $e) { $class = new $controllerClass(); $class->requireLogin(); } } try { $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $this->getRequest()->getParams()); $enforcer->execute(); } catch (InterruptedActionException $iE) { // Nothing to do here. } }
/** * Initialize the internationalization * @see tao_helpers_I18n */ protected function i18n() { $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage(); tao_helpers_I18n::init($this->extension, $uiLang); }
/** * Action dedicated to change the settings of the user (language, ...) */ public function properties() { $myFormContainer = new tao_actions_form_UserSettings($this->getUserSettings()); $myForm = $myFormContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $currentUser = $this->userService->getCurrentUser(); $userSettings = array(PROPERTY_USER_UILG => $myForm->getValue('ui_lang'), PROPERTY_USER_DEFLG => $myForm->getValue('data_lang'), PROPERTY_USER_TIMEZONE => $myForm->getValue('timezone')); $uiLang = new core_kernel_classes_Resource($myForm->getValue('ui_lang')); $dataLang = new core_kernel_classes_Resource($myForm->getValue('data_lang')); $userSettings[PROPERTY_USER_UILG] = $uiLang->getUri(); $userSettings[PROPERTY_USER_DEFLG] = $dataLang->getUri(); $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($currentUser); if ($binder->bind($userSettings)) { \common_session_SessionManager::getSession()->refresh(); $uiLangCode = tao_models_classes_LanguageService::singleton()->getCode($uiLang); $extension = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); tao_helpers_I18n::init($extension, $uiLangCode); $this->setData('message', __('Settings updated')); $this->setData('reload', true); } } } $userLabel = $this->userService->getCurrentUser()->getLabel(); $this->setData('formTitle', sprintf(__("My settings (%s)"), __($userLabel))); $this->setData('myForm', $myForm->render()); //$this->setView('form.tpl'); $this->setView('form/settings_user.tpl'); }