/** * checks if there is a cookie we can use for log in. If cookie exists * we will log in the user * * You can run trigger events which needs to be set in session_events * in config/config.ini * * @return void */ public static function checkSystemCookie() { if (isset($_COOKIE['system_cookie'])) { // user is in session. Can only be this after first request. if (isset($_SESSION['in_session'])) { return; } if (isset($_SESSION['id'])) { // user is logged in we return return; } // get a system cookie if any $row = q::select('system_cookie')->filter('cookie_id =', @$_COOKIE['system_cookie'])->fetchSingle(); // we got a cookie that equals one found in database if (!empty($row)) { $days = self::getCookiePersistentDays(); // delete system_cookies that are out of date. $now = date::getDateNow(); $last = date::substractDaysFromTimestamp($now, $days); q::delete('system_cookie')->filter('account_id =', $row['account_id'])->condition('AND')->filter('last_login <', $last)->exec(); // on every cookie login we update the cookie id $last_login = date::getDateNow(array('hms' => true)); $new_cookie_id = random::md5(); $values = array('account_id' => $row['account_id'], 'cookie_id' => $new_cookie_id, 'last_login' => $last_login); q::delete('system_cookie')->filter('cookie_id=', @$_COOKIE['system_cookie'])->exec(); q::insert('system_cookie')->values($values)->exec(); //filter('cookie_id =' , $new_cookie_id)->condition('AND')-> //filter('last_login ='******'system_cookie', $new_cookie_id); // get account which is connected to account id $account = self::getAccount($row['account_id']); // user with account if (!empty($account)) { $_SESSION['id'] = $account['id']; $_SESSION['admin'] = $account['admin']; $_SESSION['super'] = $account['super']; $_SESSION['type'] = $account['type']; } else { // keep anon user in session $_SESSION['id'] = 0; $_SESSION['type'] = 'anon'; } } } }
/** * delete a string from cache * @param string $module * @param int $id * @return boolean $res db result */ private static function deleteDb($module, $id) { $id = self::generateId($module, $id); $row = q::select(self::$table)->filter('id =', $id)->fetchSingle(); if (!empty($row)) { return q::delete(self::$table)->filter('id =', $id)->exec(); } }
/** * clears system_cache table * @return int */ public static function db() { $res = q::delete('system_cache')->filter('1 =', 1)->exec(); return $res; }
/** * checks if there is a cookie we can use for log in. If cookie exists * we will log in the user * * You can run trigger events which needs to be set in session_events * in config/config.ini * * @return void */ public static function checkSystemCookie() { if (isset($_COOKIE['system_cookie'])) { // Check against cookie from DB // User may have logged out of all devices $row = self::getSystemCookieDb(); if (empty($row)) { return; } // we got a cookie that equals one found in database $days = self::getCookiePersistentDays(); // delete system_cookies that are out of date. $now = date::getDateNow(); $last = date::substractDaysFromTimestamp($now, $days); q::delete('system_cookie')->filter('account_id =', $row['account_id'])->condition('AND')->filter('last_login <', $last)->exec(); // on every cookie login we update the cookie id $last_login = date::getDateNow(array('hms' => true)); $new_cookie_id = random::md5(); $values = array('account_id' => $row['account_id'], 'cookie_id' => $new_cookie_id, 'last_login' => $last_login); q::delete('system_cookie')->filter('cookie_id=', $_COOKIE['system_cookie'])->exec(); q::insert('system_cookie')->values($values)->exec(); // set the new cookie self::setCookie('system_cookie', $new_cookie_id); // get account which is connected to account id $account = self::getAccount($row['account_id']); // user with account if (!empty($account)) { $_SESSION['id'] = $account['id']; $_SESSION['admin'] = $account['admin']; $_SESSION['super'] = $account['super']; $_SESSION['type'] = $account['type']; } } }