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;
 }
示例#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');
     }
 }
 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;
 }
示例#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>";
 }
示例#6
0
<?php

/**
 *    Copyright 2015 OhYea777
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once '../src/Framework/bootstrap.php';
use Framework\Database\Database;
use Framework\Misc\Config;
Config::registerConfigFile('../config.json');
Database::getInstance();