public function on_start()
 {
     Events::addListener('on_page_view', function ($event) {
         $request = $event->getRequest();
         $url = Url::createFromUrl($request->getUri());
         $isSSL = false;
         $pathMatcher = new PathRequestMatcher();
         if ($pathMatcher->matches($request)) {
             $isSSL = true;
         }
         if (!$pathMatcher->matches($request)) {
             $isSSL = false;
         }
         $userMatcher = new UserRequestMatcher();
         if ($userMatcher->matches($request)) {
             $isSSL = true;
         }
         if (!$userMatcher->matches($request) && $isSSL === false) {
             $isSSL = false;
         }
         if ($isSSL === true && $request->getScheme() == 'http') {
             $config_canonical_ssl_url = Config::get('concrete.seo.canonical_ssl_url');
             if (strlen($config_canonical_ssl_url)) {
                 $canonical_ssl_url = Url::createFromUrl($config_canonical_ssl_url);
                 $url->setHost($canonical_ssl_url->getHost());
             }
             $url->setScheme('https');
             $response = new RedirectResponse($url);
         } elseif ($isSSL === false && $request->getScheme() == 'https') {
             $config_canonical_url = Config::get('concrete.seo.canonical_url');
             if (strlen($config_canonical_url)) {
                 $canonical_url = Url::createFromUrl($config_canonical_url);
                 $url->setHost($canonical_url->getHost());
             }
             $url->setScheme('http');
             $response = new RedirectResponse($url);
         }
         if (isset($response)) {
             $response->send();
             exit;
         }
     });
 }
示例#2
0
 public function chooseRedirect()
 {
     if (!$this->error) {
         $this->error = Loader::helper('validation/error');
     }
     $nh = Loader::helper('validation/numbers');
     $navigation = Loader::helper('navigation');
     $rUrl = false;
     $u = new User();
     // added for the required registration attribute change above. We recalc the user and make sure they're still logged in
     if ($u->isRegistered()) {
         if ($u->config('NEWSFLOW_LAST_VIEWED') == 'FIRSTRUN') {
             $u->saveConfig('NEWSFLOW_LAST_VIEWED', 0);
         }
         do {
             // redirect to original destination
             if (Session::has('rcID')) {
                 $rcID = Session::get('rcID');
                 if ($nh->integer($rcID)) {
                     $rc = Page::getByID($rcID);
                 } elseif (strlen($rcID)) {
                     $rcID = trim($rcID, '/');
                     $rc = Page::getByPath('/' . $rcID);
                 }
                 if ($rc instanceof Page && !$rc->isError()) {
                     $rUrl = $navigation->getLinkToCollection($rc);
                     break;
                 }
             }
             // admin to dashboard?
             $dash = Page::getByPath("/dashboard", "RECENT");
             $dbp = new Permissions($dash);
             //should administrator be redirected to dashboard?  defaults to yes if not set.
             $adminToDash = intval(Config::get('concrete.misc.login_admin_to_dashboard'));
             if ($dbp->canRead() && $adminToDash) {
                 if (!$rc instanceof Page || $rc->isError()) {
                     $rc = $dash;
                 }
                 $rUrl = $navigation->getLinkToCollection($rc);
                 break;
             }
             //options set in dashboard/users/registration
             $login_redirect_mode = Config::get('concrete.misc.login_redirect');
             //redirect to user profile
             if ($login_redirect_mode == 'PROFILE' && Config::get('concrete.user.profiles_enabled')) {
                 $rUrl = View::url('/members/profile/', $u->getUserID());
                 break;
             }
             //redirect to custom page
             $login_redirect_cid = intval(Config::get('concrete.misc.login_redirect_cid'));
             if ($login_redirect_mode == 'CUSTOM' && $login_redirect_cid > 0) {
                 $rc = Page::getByID($login_redirect_cid);
                 if ($rc instanceof Page && !$rc->isError()) {
                     $rUrl = $navigation->getLinkToCollection($rc);
                     break;
                 }
             }
             break;
         } while (false);
         if ($rUrl) {
             $r = new RedirectResponse($rUrl);
             $r->send();
             exit;
         } else {
             $this->redirect('/');
         }
     } else {
         $this->error->add(t('User is not registered. Check your authentication controller.'));
         $u->logout();
     }
 }
示例#3
0
 public function send()
 {
     return parent::send();
 }