Backend\Core\Engine\Authentication::isLoggedIn PHP Метод

isLoggedIn() публичный статический Метод

Is the current user logged in?
public static isLoggedIn ( ) : boolean
Результат boolean
    public static function isLoggedIn()
    {
        if (BackendModel::getContainer()->has('logged_in')) {
            return BackendModel::getContainer()->get('logged_in');
        }
        // check if all needed values are set in the session
        // @todo could be written by SpoonSession::get (since that no longer throws exceptions)
        if (\SpoonSession::exists('backend_logged_in', 'backend_secret_key') && (bool) \SpoonSession::get('backend_logged_in') && (string) \SpoonSession::get('backend_secret_key') != '') {
            // get database instance
            $db = BackendModel::get('database');
            // get the row from the tables
            $sessionData = $db->getRecord('SELECT us.id, us.user_id
                 FROM users_sessions AS us
                 WHERE us.session_id = ? AND us.secret_key = ?
                 LIMIT 1', array(\SpoonSession::getSessionId(), \SpoonSession::get('backend_secret_key')));
            // if we found a matching row, we know the user is logged in, so we update his session
            if ($sessionData !== null) {
                // update the session in the table
                $db->update('users_sessions', array('date' => BackendModel::getUTCDate()), 'id = ?', (int) $sessionData['id']);
                // create a user object, it will handle stuff related to the current authenticated user
                self::$user = new User($sessionData['user_id']);
                // the user is logged on
                BackendModel::getContainer()->set('logged_in', true);
                return true;
            }
        }
        // no data found, so fuck up the session, will be handled later on in the code
        \SpoonSession::set('backend_logged_in', false);
        BackendModel::getContainer()->set('logged_in', false);
        \SpoonSession::set('backend_secret_key', '');
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Do authentication stuff
  * This method could end the script by throwing an exception
  */
 private function validateLogin()
 {
     // check if the user is logged on, if not he shouldn't load any JS-file
     if (!Authentication::isLoggedIn()) {
         throw new Exception('Not logged in.');
     }
     // set interface language
     BackendLanguage::setLocale(Authentication::getUser()->getSetting('interface_language'));
 }
All Usage Examples Of Backend\Core\Engine\Authentication::isLoggedIn