/**
  * @param int $onRoot
  */
 private function setupHelperAppDirRelativePath($onRoot = 0)
 {
     $this->helper->setConfigurations(array('sitename' => 'mySitename', 'zf2appDir' => 'demo', 'isPublicDirOnRoot' => $onRoot));
     $this->helper->setRequest(new \Zend\Http\PhpEnvironment\Request());
     $this->helper->setupZf2appDir();
     $this->helper->setupAppDirRelativePath();
 }
 public function indexAction()
 {
     $appServiceLoader = $this->recoverAppServiceLoader();
     $configurations = $appServiceLoader->recoverService('configurations');
     $session = new SessionContainer();
     if (!isset($configurations['preview_password_area']) or $this->checkPasswordPreviewArea($configurations, $session) or !$this->hasPasswordPreviewArea($configurations)) {
         return $this->redirect()->toRoute('main');
     }
     $request = $this->getRequest();
     $helper = new SetupAbstractControllerHelper();
     $helper->setConfigurations($configurations);
     $helper->setRequest($request);
     $helper->setupZf2appDir();
     $helper->setupAppDirRelativePath();
     $form = new PasswordPreviewForm();
     $this->layout()->setVariables(array('form' => $form, 'sitename' => isset($configurations['sitename']) ? $configurations['sitename'] : null));
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $formPost = $form->getData();
             if ($formPost['password'] == $configurations['preview_password']) {
                 $session->offsetSet('preview_area_ok', 1);
                 $session->offsetSet('preview_area_logintimeout', date("Y-m-d H:i:s"));
                 return $this->redirect()->toRoute('main');
             } else {
                 $this->layout()->setVariable('errorMessage', 'Password errata!');
             }
         }
     }
     $this->layout()->setVariable('publicDirRelativePath', $helper->getAppDirRelativePath() . '/public');
     $this->layout()->setTemplate('frontend/projects/' . $configurations['project_frontend'] . 'templates/' . $configurations['template_frontend'] . 'preview-area/preview-area.phtml');
 }
 public function indexAction()
 {
     $appServiceLoader = $this->recoverAppServiceLoader();
     $configurations = $appServiceLoader->recoverService('configurations');
     $templateBackend = $appServiceLoader->recoverServiceKey('configurations', 'template_backend');
     $request = $this->getRequest();
     $helper = new SetupAbstractControllerHelper();
     $helper->setConfigurations($configurations);
     $helper->setRequest($request);
     $helper->setupZf2appDir();
     $helper->setupAppDirRelativePath();
     $form = new RecoverPasswordForm();
     $form->addSubmitButton();
     $this->layout()->setVariables(array('configurations' => $configurations, 'publicDirRelativePath' => $helper->getAppDirRelativePath() . '/public', 'form' => $form));
     return $this->layout('backend/templates/' . $templateBackend . 'recover-password.phtml');
 }
Beispiel #4
0
 /**
  * Form login user authentication
  *
  * @return Redirect
  * @throws Exception
  */
 public function authenticateAction()
 {
     $redirect = 'login';
     $request = $this->getRequest();
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $appServiceLoader = $this->recoverAppServiceLoader();
     $configurations = $appServiceLoader->recoverService('configurations');
     $helper = new SetupAbstractControllerHelper();
     $helper->setConfigurations($configurations);
     $helper->setRequest($request);
     $helper->setupZf2appDir();
     $helper->setupAppDirRelativePath();
     $formValidator = new UserFormAuthenticationInputFilter();
     $form = new UserFormAuthentication();
     $form->setInputFilter($formValidator->getInputFilter());
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // Check authentication...
             $this->getAuthService()->getAdapter()->setIdentity($request->getPost('username'))->setCredential($request->getPost('password'));
             $result = $this->getAuthService()->authenticate();
             foreach ($result->getMessages() as $message) {
                 $this->flashmessenger()->addMessage($message);
             }
             if ($result->isValid()) {
                 $redirect = 'admin';
                 // set session timeout stored in MyAuthStorage class...
                 $this->getSessionStorage()->setRememberMe();
                 // set storage into the auth service
                 $this->getAuthService()->setStorage($this->getSessionStorage());
                 $this->getAuthService()->getStorage()->write($request->getPost('username'));
                 // Search user into db
                 $usersGetterWrapper = new UsersGetterWrapper(new UsersGetter($entityManager));
                 $usersGetterWrapper->setInput(array('username' => $request->getPost('username'), 'password' => $request->getPost('password'), 'adminAccess' => 1, 'limit' => 1));
                 $usersGetterWrapper->setupQueryBuilder();
                 $records = $usersGetterWrapper->getRecords();
                 if (isset($records) and count($records) == 1) {
                     $records = $records[0];
                     // Set ACL
                     $aclSetter = new AclSetter(new Acl());
                     $aclSetter->setUsersRolesGetterWrapper(new UsersRolesGetterWrapper(new UsersRolesGetter($entityManager)));
                     $aclSetter->addRoles($aclSetter->recoverRoles(array()));
                     if ($records['roleName'] === 'WebMaster') {
                         // Assign all permissions
                         $aclSetter->getAcl()->allow($records['roleName']);
                         $wrapper = new UsersRolesPermissionsGetterWrapper(new UsersRolesPermissionsGetter($entityManager));
                         $wrapper->setInput(array());
                         $wrapper->setupQueryBuilder();
                         $permissionsRecords = $wrapper->getRecords();
                         if (empty($permissionsRecords)) {
                             throw new NullException("Error: no permissions stored on database!");
                         }
                         foreach ($permissionsRecords as $permissionsRecord) {
                             $aclSetter->getAcl()->addResource($permissionsRecord['flag']);
                             $aclSetter->getAcl()->allow($records['roleName'], $permissionsRecord['flag']);
                         }
                     } else {
                         $wrapper = new UsersRolesPermissionsRelationsGetterWrapper(new UsersRolesPermissionsRelationsGetter($entityManager));
                         $wrapper->setInput(array('roleId' => $records['roleId']));
                         $wrapper->setupQueryBuilder();
                         $permissionsRecords = $wrapper->getRecords();
                         if (empty($permissionsRecords)) {
                             throw new NullException("Error: no permissions stored on database!");
                         }
                         foreach ($permissionsRecords as $permissionsRecord) {
                             $aclSetter->getAcl()->addResource($permissionsRecord['flag']);
                             $aclSetter->getAcl()->allow($records['roleName'], $permissionsRecord['flag']);
                         }
                     }
                     $sitename = $configurations['sitename'];
                     if (!$sitename) {
                         throw new NullException('Site name is not set. Cannot complete the login');
                     }
                     $ckFinderUploadDir = $helper->getAppDirRelativePath() . '/public/' . $configurations['media_dir'] . $configurations['media_project'] . 'ckfinder_files';
                     $userDetails = new \stdClass();
                     $userDetails->sitename = $sitename;
                     $userDetails->id = $records['id'];
                     $userDetails->name = $records['name'];
                     $userDetails->surname = $records['surname'];
                     $userDetails->email = $records['email'];
                     $userDetails->acl = $aclSetter->getAcl();
                     $userDetails->salt = $records['salt'];
                     $userDetails->passwordLastUpdate = $records['passwordLastUpdate'];
                     $userDetails->role = $records['roleName'];
                     /* Set user session values */
                     $sessionContainer = new SessionContainer();
                     $sessionContainer->offsetSet('userDetails', $userDetails);
                     $sessionContainer->offsetSet('ckFinderUploadDir', $ckFinderUploadDir);
                     /* Regenerate Session ID after login */
                     $manager = new \Zend\Session\SessionManager();
                     $manager->regenerateId();
                     /* Log entering admin area */
                     $logWriter = new LogWriter($entityManager->getConnection());
                     $logWriter->writeLog(array('user_id' => $userDetails->id, 'module_id' => ModulesContainer::contenuti_id, 'message' => "Ingresso nell'area riservata", 'description' => $records['name'] . ' ' . $records['surname'] . " ha effettuato un ingresso nell'area riservata", 'type' => 'info', 'reference_id' => 0, 'backend' => 1));
                 } else {
                     $this->flashmessenger()->addMessage(print_r("Nome utente e \\ o password non validi", 1));
                 }
             }
         } else {
             $sessionContainer = new SessionContainer();
             $loginFailures = $sessionContainer->offsetGet('loginFailures');
             $sessionContainer->offsetSet('loginFailures', $loginFailures);
             foreach ($form->getMessages() as $message) {
                 $this->flashmessenger()->addMessage(print_r($message, 1));
             }
         }
     }
     return $this->redirect()->toRoute($redirect, array("lang" => 'it'));
 }
 /**
  * Initialize variables for the public website
  *
  * @return string
  */
 protected function initializeFrontendWebsite($channel = 1)
 {
     $appServiceLoader = $this->recoverAppServiceLoader($channel);
     $configurations = $appServiceLoader->recoverService('configurations');
     $sessionContainer = new SessionContainer();
     if (!$this->checkPasswordPreviewArea($configurations, $sessionContainer)) {
         header("Location: " . $this->url()->fromRoute('password-preview'));
         exit;
     }
     $serviceLocator = $this->getServiceLocator();
     $request = $this->getRequest();
     $uri = $request->getUri();
     $cookieWarningSession = $sessionContainer->offsetGet('cookie-warning');
     $lang = $this->params()->fromRoute('lang') ? $this->params()->fromRoute('lang') : 'it';
     $helper = new SetupAbstractControllerHelper();
     $helper->setConfigurations($configurations);
     $helper->setRequest($request);
     $helper->setSezioniGetterWrapper(new SezioniGetterWrapper(new SezioniGetter($this->getServiceLocator()->get('doctrine.entitymanager.orm_default'))));
     $helper->setupSezioniRecords(array('attivo' => 1, 'languageAbbreviation' => isset($lang) ? $lang : 'it', 'orderBy' => 'sezioni.posizione ASC'));
     $sottosezioniRecords = $helper->getSezioniGetterWrapper()->addSottoSezioni($helper->getSezioniRecords(), array('attivo' => 1));
     $helper->setSezioniRecords($helper->getSezioniGetterWrapper()->formatRecordsPerColumn($sottosezioniRecords));
     $helper->setupServer();
     $helper->setupFrontendTemplatePath();
     $helper->setupPhpRenderer($this->getServiceLocator());
     $helper->setupZf2appDir();
     $helper->setupAppDirRelativePath();
     $serverVars = $helper->getServer();
     /**
      * @var \Zend\Mvc\I18n\Translator $translator
      */
     $translator = $serviceLocator->get('translator');
     if (file_exists('./module/Application/language/app.' . $lang . '.php')) {
         $translator->addTranslationFile('phparray', './module/Application/language/app.' . $lang . '.php');
     }
     if (file_exists('./module/Application/language/form.array.' . $lang . '.php')) {
         $translator->addTranslationFile('phparray', './module/Application/language/form.array.' . $lang . '.php');
     }
     $serviceLocator->get('ViewHelperManager')->get('translate')->setTranslator($translator);
     $this->layout()->setVariables($configurations);
     $this->layout()->setVariables(array('basePath' => sprintf('%s://%s%s', $uri->getScheme(), $uri->getHost(), $request->getBaseUrl() . '/'), 'publicDirRelativePath' => $helper->getAppDirRelativePath() . '/public', 'configurations' => $configurations, 'sezioni' => $helper->getSezioniRecords(), 'templateDir' => 'frontend/projects/' . $configurations['project_frontend'] . 'templates/' . $configurations['template_frontend'], 'preloadResponse' => isset($input['preloadResponse']) ? $input['preloadResponse'] : null, 'currentUrl' => "http://" . $serverVars["SERVER_NAME"] . $serverVars["REQUEST_URI"], 'currentDateTime' => date("Y-m-d H:i:s"), 'template_frontend' => $configurations['template_frontend'], 'cssName' => $sessionContainer->offSetGet('cssName'), 'passwordPreviewArea' => $this->hasPasswordPreviewArea($configurations), 'renderer' => $helper->getPhpRenderer(), 'cookieWarning' => isset($cookieWarningSession[$configurations['sitename']]) ? $cookieWarningSession[$configurations['sitename']] : null, 'lang' => isset($lang) ? $lang : 'it', 'isMultiLanguage' => isset($configurations['isMultiLanguage']) ? 1 : 0, 'defaultLanguageId' => 1, 'searchEngineForm' => new SearchEngineForm(), 'defaultLanguageAbbreviation' => 'it'));
     return 'frontend/projects/' . $configurations['project_frontend'] . 'templates/' . $configurations['template_frontend'] . 'layout.phtml';
 }