/**
  * Hook that allows actions when data was saved
  *
  * When not rerouted, the form will be populated afterwards
  *
  * @param int $changed The number of changed rows (0 or 1 usually, but can be more)
  */
 protected function afterSave($changed)
 {
     if ($changed) {
         $this->accesslog->logChange($this->request, null, $this->formData);
         // Reload the current user data
         $user = $this->currentUser;
         $currentOrg = $user->getCurrentOrganizationId();
         $this->loader->getUserLoader()->unsetCurrentUser();
         $user = $this->loader->getUser($user->getLoginName(), $user->getBaseOrganizationId())->setAsCurrentUser();
         $user->setCurrentOrganization($currentOrg);
         // In case locale has changed, set it in a cookie
         \Gems_Cookies::setLocale($this->formData['gsf_iso_lang'], $this->basepath);
         $this->addMessage($this->_('Saved your setup data', $this->formData['gsf_iso_lang']));
     } else {
         $this->addMessage($this->_('No changes to save!'));
     }
     if ($this->cacheTags && $this->cache instanceof \Zend_Cache_Core) {
         $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, (array) $this->cacheTags);
     }
 }
 public function changeUiAction()
 {
     $request = $this->getRequest();
     $lang = strtolower($request->getParam('language'));
     $url = base64_decode($request->getParam('current_uri'));
     if (!$url || '/' !== $url[0]) {
         throw new \Exception($this->_('Illegal language redirect url.'));
     }
     if (in_array($lang, $this->view->project->locales)) {
         $this->currentUser->setLocale($lang);
         if (\Gems_Cookies::setLocale($lang, $this->basepath->getBasePath())) {
             if ($url) {
                 $this->getResponse()->setRedirect($url);
             } else {
                 $this->currentUser->gotoStartPage($this->menu, $this->getRequest());
             }
             return;
         }
         throw new \Exception($this->_('Cookies must be enabled for setting the language.'));
     }
     throw new \Exception($this->_('Invalid language setting.'));
 }
 /**
  * Set this organization as teh one currently active
  *
  * @return \Gems_User_Organization (continutation pattern)
  */
 public function setAsCurrentOrganization()
 {
     $organizationId = $this->getId();
     if ($organizationId && !\Gems_Cookies::setOrganization($organizationId, $this->basepath->getBasePath())) {
         throw new \Exception('Cookies must be enabled for this site.');
     }
     $escort = \GemsEscort::getInstance();
     if ($escort instanceof \Gems_Project_Layout_MultiLayoutInterface) {
         $escort->layoutSwitch($this->getStyle());
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Returns the organization id that is currently used by this user.
  *
  * @return int
  */
 public function getCurrentOrganizationId()
 {
     $orgId = $this->_getVar('user_organization_id');
     //If not set, read it from the cookie
     if ($this->isCurrentUser() && (null === $orgId || \Gems_User_UserLoader::SYSTEM_NO_ORG === $orgId)) {
         $request = $this->getRequest();
         if ($request) {
             $orgId = \Gems_Cookies::getOrganization($this->getRequest());
         }
         if (!$orgId) {
             $orgId = 0;
         }
         $this->_setVar('user_organization_id', $orgId);
     }
     return $orgId;
 }
Ejemplo n.º 5
0
 /**
  * Common handler utility to initialize tokens from parameters
  *
  * @return boolean True if there is a real token specified in the request
  */
 protected function _initToken()
 {
     if ($this->tracker) {
         return $this->token && $this->token->exists;
     }
     $this->tracker = $this->loader->getTracker();
     $this->tokenId = $this->tracker->filterToken($this->_getParam(\MUtil_Model::REQUEST_ID));
     if (!$this->tokenId) {
         return false;
     }
     $this->token = $this->tracker->getToken($this->tokenId);
     if (!$this->token->exists) {
         return false;
     }
     if (!($this->currentUser->isActive() || $this->token->getSurvey()->isTakenByStaff())) {
         $tokenLang = strtolower($this->token->getRespondentLanguage());
         // \MUtil_Echo::track($tokenLang, $this->locale->getLanguage());
         if ($tokenLang != $this->locale->getLanguage()) {
             $this->locale->setLocale($tokenLang);
             $this->translateAdapter->setLocale($this->locale);
             $this->currentUser->setLocale($tokenLang);
             \Gems_Cookies::setLocale($tokenLang, $this->basepath->getBasePath());
         }
         $currentOrg = $this->loader->getOrganization();
         $tokenOrgId = $this->token->getOrganizationId();
         if ($tokenOrgId != $currentOrg->getId()) {
             $this->loader->getOrganization($tokenOrgId)->setAsCurrentOrganization();
         }
     }
     return true;
 }
 /**
  * Returns the top organization id that should currently be used for this form.
  *
  * @return int Returns the current organization id, if any
  */
 public function getCurrentTopOrganizationId()
 {
     $userLoader = $this->loader->getUserLoader();
     // Url determines organization first.
     if ($orgId = $userLoader->getOrganizationIdByUrl()) {
         $this->_organizationFromUrl = true;
         return ' ';
     }
     $request = $this->getRequest();
     if ($request->isPost() && ($orgId = $request->getParam($this->topOrganizationFieldName))) {
         \Gems_Cookies::set('gems_toporganization', $orgId);
         return $orgId;
     } else {
         $orgs = array_keys($this->getTopOrganisations());
         $firstId = reset($orgs);
         return \Gems_Cookies::get($this->getRequest(), 'gems_toporganization', $firstId);
     }
 }
 /**
  * Default login page
  */
 public function loginAction()
 {
     $request = $this->getRequest();
     $form = $this->createLoginForm();
     // Retrieve these before the session is reset
     $staticSession = \GemsEscort::getInstance()->getStaticSession();
     $previousRequestParameters = $staticSession->previousRequestParameters;
     $previousRequestMode = $staticSession->previousRequestMode;
     if ($form->wasSubmitted()) {
         if ($form->isValid($request->getPost(), false)) {
             $user = $form->getUser();
             $user->setAsCurrentUser();
             if ($messages = $user->reportPasswordWeakness($request->getParam($form->passwordFieldName))) {
                 $user->setPasswordResetRequired(true);
                 $this->addMessage($this->_('Your password must be changed.'));
                 foreach ($messages as &$message) {
                     $message = ucfirst($message) . '.';
                 }
                 $this->addMessage($messages);
             }
             /**
              * Fix current locale in cookies
              */
             \Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath());
             /**
              * Ready
              */
             $this->addMessage(sprintf($this->_('Login successful, welcome %s.'), $user->getFullName()), 'success');
             /**
              * Log the login
              */
             $this->accesslog->logChange($request);
             if ($previousRequestParameters) {
                 $this->_reroute(array('controller' => $previousRequestParameters['controller'], 'action' => $previousRequestParameters['action']), false);
             } else {
                 // This reroutes to the first available menu page after login.
                 //
                 // Do not user $user->gotoStartPage() as the menu is still set
                 // for no login.
                 $this->_reroute(array('controller' => null, 'action' => null), true);
             }
             return;
         } else {
             $errors = \MUtil_Ra::flatten($form->getMessages());
             // \MUtil_Echo::track($errors);
             //Also log the error to the log table
             //when the project has logging enabled
             $logErrors = join(' - ', $errors);
             $msg = sprintf('Failed login for : %s (%s) - %s', $request->getParam($form->usernameFieldName), $request->getParam($form->organizationFieldName), $logErrors);
             $this->accesslog->logChange($request, $msg);
         }
         // */
     } else {
         if ($request->isPost()) {
             $form->populate($request->getPost());
         }
     }
     $this->displayLoginForm($form);
 }
Ejemplo n.º 8
0
 /**
  * Hook 3: Called in $this->setRequest.
  *
  * All resources have been loaded and the $request object is created.
  * Theoretically this event can be triggered multiple times, but this does
  * not happen in a standard Zend application.
  *
  * Not initialized are the $response and $controller objects.
  *
  * Previous hook: beforeRun()
  * Actions since: $this->request object created
  * Actions after: $this->response object created
  * Next hook: responseChanged()
  *
  * @param \Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function requestChanged(\Zend_Controller_Request_Abstract $request)
 {
     if ($this->project->isMultiLocale()) {
         // Get the choosen language
         $localeId = \Gems_Cookies::getLocale($request);
         // Change when $localeId exists and is different from session
         if ($localeId && $this->locale->getLanguage() !== $localeId) {
             // \MUtil_Echo::r('On cookie ' . $localeId . ' <> ' . $this->locale->getLanguage());
             // Does the locale exist?
             if (isset($this->project->locales[$localeId])) {
                 // Add and implement the choosen locale
                 $this->session->user_locale = $localeId;
                 $this->locale->setLocale($localeId);
                 if (!$this->translate->isAvailable($localeId)) {
                     $languageFilename = APPLICATION_PATH . '/languages/default-' . $localeId . '.mo';
                     if (file_exists($languageFilename)) {
                         $this->translate->addTranslation($languageFilename, $localeId);
                     }
                 }
                 $this->translate->setLocale($localeId);
                 $this->translateAdapter = $this->translate->getAdapter();
             }
         }
     }
     // Set the base path, the route is now fixed
     $this->basepath->setBasePath($request->getBasePath());
     // Set the jQuery version and other information needed
     // by classes using jQuery
     $jquery = \MUtil_JQuery::jQuery();
     $jqueryVersion = '1.11.1';
     $jqueryUiVersion = '1.11.1';
     $jquery->setVersion($jqueryVersion);
     $jquery->setUiVersion($jqueryUiVersion);
     if ($this->project->isJQueryLocal()) {
         $jqueryDir = $request->getBasePath() . $this->project->getJQueryLocal();
         $jquery->setLocalPath($jqueryDir . 'jquery-' . $jqueryVersion . '.js');
         $jquery->setUiLocalPath($jqueryDir . 'jquery-ui-' . $jqueryUiVersion . '.js');
     } else {
         if (\MUtil_Https::on()) {
             $jquery->setCdnSsl(true);
         }
     }
     if (\MUtil_Bootstrap::enabled() && $this->project->isBootstrapLocal()) {
         $bootstrap = \MUtil_Bootstrap::bootstrap();
         $basePath = $request->getBasePath();
         $bootstrap->setBootstrapScriptPath($basePath . '/bootstrap/js/bootstrap.min.js');
         $bootstrap->setBootstrapStylePath($basePath . '/bootstrap/css/bootstrap.min.css');
         $bootstrap->setFontAwesomeStylePath($basePath . '/bootstrap/css/font-awesome.min.css');
     }
 }