Ejemplo n.º 1
0
 public static function authorize_cookie()
 {
     $cookie_key = Config::need('COOKIE_KEY', 'u');
     $hash_coookie_key = $cookie_key . '_sh';
     $uid_coookie_key = $cookie_key . '_id';
     if (isset($_COOKIE[$uid_coookie_key]) && isset($_COOKIE[$hash_coookie_key])) {
         $user_id = $_COOKIE[$uid_coookie_key];
         $user = Users::getByIdLoaded($user_id);
         if (!$user) {
             return false;
         }
         if ($user->data['session'] == $_COOKIE[$hash_coookie_key]) {
             self::$id = $user_id;
             Database::query('UPDATE `user` SET `lastAccessTime`=' . time() . '  WHERE `id`=' . $user_id);
             self::$authorized = true;
             return true;
         }
     } else {
         return false;
     }
 }