/** * Authentication form, * default page, main entry point to the user * * @return void */ public function login() { $params = array(); if ($this->hasRequestParameter('redirect')) { $redirectUrl = $_REQUEST['redirect']; if (substr($redirectUrl, 0, 1) == '/' || substr($redirectUrl, 0, strlen(ROOT_URL)) == ROOT_URL) { $params['redirect'] = $redirectUrl; } } $myLoginFormContainer = new tao_actions_form_Login($params); $myForm = $myLoginFormContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $success = LoginService::login($myForm->getValue('login'), $myForm->getValue('password')); if ($success) { \common_Logger::i("Successful login of user '" . $myForm->getValue('login') . "'."); if ($this->hasRequestParameter('redirect') && tao_models_classes_accessControl_AclProxy::hasAccessUrl($_REQUEST['redirect'])) { $this->redirect($_REQUEST['redirect']); } else { $this->redirect(_url('entry', 'Main')); } } else { \common_Logger::i("Unsuccessful login of user '" . $myForm->getValue('login') . "'."); $this->setData('errorMessage', __('Invalid login or password. Please try again.')); } } } $this->setData('form', $myForm->render()); $this->setData('title', __("TAO Login")); $this->setData('messageServiceIsAvailable', MessagingService::singleton()->isAvailable()); if ($this->hasRequestParameter('msg')) { $this->setData('msg', $this->getRequestParameter('msg')); } $this->setData('content-template', array('blocks/login.tpl', 'tao')); $this->setView('layout.tpl', 'tao'); }
/** * Authentication form, * default page, main entry point to the user * * @return void */ public function login() { $extension = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); $config = $extension->getConfig('login'); $disableAutocomplete = !empty($config['disableAutocomplete']); $params = array('disableAutocomplete' => $disableAutocomplete); if ($this->hasRequestParameter('redirect')) { $redirectUrl = $_REQUEST['redirect']; if (substr($redirectUrl, 0, 1) == '/' || substr($redirectUrl, 0, strlen(ROOT_URL)) == ROOT_URL) { $params['redirect'] = $redirectUrl; } } $myLoginFormContainer = new tao_actions_form_Login($params); $myForm = $myLoginFormContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $success = LoginService::login($myForm->getValue('login'), $myForm->getValue('password')); $eventManager = $this->getServiceManager()->get(EventManager::CONFIG_ID); if ($success) { \common_Logger::i("Successful login of user '" . $myForm->getValue('login') . "'."); $eventManager->trigger(new LoginSucceedEvent($myForm->getValue('login'))); if ($this->hasRequestParameter('redirect') && tao_models_classes_accessControl_AclProxy::hasAccessUrl($_REQUEST['redirect'])) { $this->redirect($_REQUEST['redirect']); } else { $this->forward('entry'); } } else { \common_Logger::i("Unsuccessful login of user '" . $myForm->getValue('login') . "'."); $eventManager->trigger(new LoginFailedEvent($myForm->getValue('login'))); $this->setData('errorMessage', __('Invalid login or password. Please try again.')); } } } $renderedForm = $myForm->render(); // replace the login form by a fake form that will delegate the submit to the real form // this will allow to prevent the browser ability to cache login/password if ($disableAutocomplete) { // make a copy of the form and replace the form attributes $fakeForm = preg_replace('/<form[^>]+>/', '<div class="form loginForm fakeForm">', $renderedForm); $fakeForm = str_replace('</form>', '</div>', $fakeForm); // replace the password field by a text field in the actual form, // so the browser won't detect it and won't be able to cache the credentials $renderedForm = preg_replace('/type=[\'"]+password[\'"]+/', 'type="text"', $renderedForm); // hide the actual form, // it will be submitted through javascript delegation $renderedForm = preg_replace_callback('/<form([^>]+)>/', function ($matches) { $str = $matches[0]; if (false !== strpos($str, ' style=')) { $str = preg_replace('/ style=([\'"]+)([^\'"]+)([\'"]+)/', ' style=$1$2;display:none;$3', $str); } else { $str = '<form' . $matches[1] . ' style="display:none;">'; } return $str; }, $renderedForm); // the fake form will be displayed instead of the actual form, // it will behave like the actual form $renderedForm .= $fakeForm; } $this->setData('form', $renderedForm); $this->setData('title', __("TAO Login")); $entryPointService = $this->getServiceManager()->getServiceManager()->get(EntryPointService::SERVICE_ID); $this->setData('entryPoints', $entryPointService->getEntryPoints(EntryPointService::OPTION_PRELOGIN)); if ($this->hasRequestParameter('msg')) { $this->setData('msg', $this->getRequestParameter('msg')); } $this->setData('content-template', array('blocks/login.tpl', 'tao')); $this->setView('layout.tpl', 'tao'); }