Ejemplo n.º 1
0
 public static function getLoggedInController()
 {
     if ($controller = ControllerManager::getControllerFromSession(__CLASS__)) {
         return $controller;
     } else {
         if (Cookie::exists(Config::get('cookie', 'name'))) {
             /** @var CookieController $cookieController */
             if ($uuid = CookieController::verifyCookie()) {
                 return ControllerManager::getController(__CLASS__, ['uuid' => $uuid], true);
             }
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * @return AbstractDatabase
  */
 public static function getInstance()
 {
     if (isset(self::$instance)) {
         return self::$instance;
     } else {
         $databaseType = strtolower(Config::get('database', 'type'));
         if (array_key_exists($databaseType, self::$databaseMappings)) {
             if (ClassUtils::isClass($databaseClass = self::$databaseMappings[$databaseType], AbstractDatabase::class)) {
                 return new $databaseClass(Config::get('database', 'host'), Config::get('database', 'port'), Config::get('database', 'name'), Config::get('database', 'user'), Config::get('database', 'pass'));
             }
         }
         die('Unknown database type');
     }
 }
Ejemplo n.º 3
0
 public static function verifyCookie()
 {
     if (Cookie::exists(Config::get('cookie', 'name'))) {
         $token = Cookie::get(Config::get('cookie', 'name'));
         $toVerify = hash("sha512", $token . Utils::getClientIP());
         if ($data = Database::getInstance()->get(call_user_func(self::getModelClass() . '::getTableName'), ['token' => $toVerify], ['user_uuid'])) {
             if (array_key_exists(0, $data) && is_array($data[0])) {
                 $data = $data[0];
             }
             if (array_key_exists('user_uuid', $data)) {
                 return $data['user_uuid'];
             }
         }
         Cookie::remove(Config::get('cookie', 'name'));
     }
     return false;
 }
Ejemplo n.º 4
0
 public function insert($table, $params)
 {
     $table = Config::get('mysql', 'prefix') . $table;
     try {
         $update = '';
         foreach ($params as $col => $val) {
             if (!empty($update)) {
                 $update .= ', ';
             }
             $update .= '`' . $col . '` = :' . $col;
         }
         $stmt = $this->db->prepare('INSERT INTO ' . $table . '(`' . implode('`, `', array_keys($params)) . '`) VALUES(:' . implode(', :', array_keys($params)) . ') ON DUPLICATE KEY UPDATE ' . $update);
         $stmt->execute($params);
     } catch (\PDOException $e) {
         return printf("Fatal SQL Error: %s", $e->getMessage());
     }
     return true;
 }
 public static function generateBaseSQL()
 {
     $parser = new DatabaseAnnotationParser(get_called_class());
     $cols = $parser->getAsArray();
     $sql = '<pre>CREATE TABLE IF NOT EXISTS `' . Config::get('mysql', 'prefix') . call_user_func(get_called_class() . '::getTableName') . '` (<br>';
     foreach ($cols as $colName => $colInfo) {
         if ($colName == '__indexes__') {
             continue;
         }
         $sql .= "&Tab;`{$colName}` {$colInfo['type']}({$colInfo['length']})" . ($colInfo['null'] ? ' NOT ' : ' ') . 'NULL' . ($colInfo['defaulttype'] == 'AUTO_INC' ? ' AUTO_INCREMENT' : " DEFAULT " . ($colInfo['null'] ? "'{$colInfo['default']}'" : "NULL")) . ",<br>";
     }
     foreach ($cols['__indexes__'] as $col => $indexInfo) {
         switch ($indexInfo) {
             case 'PRIMARY':
                 $sql .= "&Tab;PRIMARY KEY (`{$col}`),<br>";
                 break;
             default:
                 $sql .= "&Tab;UNIQUE INDEX `{$col}` (`{$col}`),<br>";
         }
     }
     return substr($sql, 0, -5) . "<br>)<br>COLLATE='utf8_general_ci'<br>ENGINE=InnoDB;</pre>";
 }