Beispiel #1
0
 public function __construct()
 {
     parent::__construct();
     $authID = session::item('auth_id');
     $userID = session::item('user_id');
     $ipaddress = substr(input::ipaddress(), 0, 15);
     $useragent = substr(input::useragent(), 0, 255);
     $user = array();
     if ($authID && ($user = $this->getSession($authID, $userID, $ipaddress, $useragent))) {
         if ($user['active_date'] < date_helper::now() - 60 * $this->timeout) {
             $this->saveSession($authID, $userID, $ipaddress, $useragent);
             if (isset($user['user_id']) && $user['user_id']) {
                 $this->saveLastvisit($user['user_id']);
             }
         }
     } else {
         $cookie = cookie::item('sessdata');
         $cookie = $cookie ? @json_decode($cookie, true) : array();
         if ($cookie && is_array($cookie)) {
             $userID = isset($cookie['user_id']) ? $cookie['user_id'] : '';
             $email = isset($cookie['email']) ? $cookie['email'] : '';
             $passhash = isset($cookie['passhash']) ? $cookie['passhash'] : '';
             if ($userID && is_numeric($userID) && $userID > 0) {
                 if ($user = $this->getUser($userID, false, false)) {
                     $newPasshash = $this->generatePasshash($email, $user['password']);
                     if ($user['active'] && $user['verified'] && strcmp($email, $user['email']) == 0 && strcmp($passhash, $newPasshash) == 0) {
                         $authID = $this->saveSession(0, $user['user_id'], $ipaddress, $useragent);
                         $this->saveLastvisit($user['user_id']);
                     } else {
                         $user = array();
                     }
                 }
             }
         }
     }
     if (!$user || !isset($user['user_id']) || !$user['user_id'] || !$this->createUserSession($user)) {
         $userID = 0;
         if (!$user) {
             $authID = $this->saveSession(0, $userID, $ipaddress, $useragent);
         }
         $this->createGuestSession();
     }
     session::set('auth_id', $authID);
     session::set('user_id', $userID);
     // Is the site offline?
     if (!input::isCP() && !config::item('site_online', 'system') && !session::permission('site_access_offline', 'system') && uri::getURI() != 'site/offline' && uri::segment(1) != 'load') {
         router::redirect('site/offline');
     } elseif (input::isCP() && !session::permission('site_access_cp', 'system') && (uri::getURI() != 'cp' && uri::getURI() != 'cp/users/login' && uri::getURI() != 'cp/users/login/license')) {
         router::redirect('cp/users/login');
     }
     if (!input::isCP() && $this->isLoggedin() && session::permission('site_access_cp', 'system') && uri::segment(1) != 'load' && input::demo(0, '', session::item('user_id'))) {
         $this->logout();
         view::setInfo('For the purposes of this demo you may not use front end of the site under the administrator account. As such we have now logged you out.<br/>Feel free ' . html_helper::anchor('users/signup', 'register on the site') . ' to test user end functionality or ' . html_helper::anchor('users/login', 'login') . ' using your existing account details if you have one already.');
         router::redirect();
     }
 }