Skip to content

Commit

Permalink
Clean CSS, Added helpers, Added 404 tpl
Browse files Browse the repository at this point in the history
  • Loading branch information
copostic committed May 29, 2018
1 parent ab17546 commit a7048d9
Show file tree
Hide file tree
Showing 36 changed files with 538 additions and 10,498 deletions.
6 changes: 3 additions & 3 deletions config/conf.hybridauth.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
$config = [
'callback' => 'http://supfile.tk/login',
'callback' => 'http://supfile.tk/auth/social',
'providers' => [
'Twitter' => [
'enabled' => true,
Expand All @@ -20,8 +20,8 @@
'Google' => [
'enabled' => true,
'keys' => [
'id' => '329157288654-gsra1n9afce1mve7mbb7kejp6nudopuj.apps.googleusercontent.com',
'secret' => 'lxCb8JkN07Oz8m49eg7EfKws']
'id' => '329157288654-vk03drjkhl9kh9g9dn5trjpfn5k8h931.apps.googleusercontent.com',
'secret' => 'SzIRs_SJtfimZyZ4kZtaNeH-']
]
]
];
3 changes: 2 additions & 1 deletion config/routes.conf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
$routes['default'] = 'main';
$routes['home'] = 'main';
$routes['login'] = 'login';
$routes['auth'] = 'auth';
$routes['404'] = 'main';
51 changes: 51 additions & 0 deletions controllers/auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Hybridauth\Exception\Exception;
use Hybridauth\Hybridauth;
use Hybridauth\HttpClient;
use Hybridauth\Storage\Session;

$vue = $page ?? 'login';
if (!empty($page)) {
if ($page == 'social') {
try {
$hybridauth = new Hybridauth($config);

$storage = new Session();

if (isset($_GET['provider'])) {
$storage->set('provider', $_GET['provider']);
}

if ($provider = $storage->get('provider')) {
$hybridauth->disconnectAllAdapters();
$adapter = $hybridauth->authenticate($provider);
$storage->set('provider', null);
if ($adapter->isConnected()) {
$profile = $adapter->getUserProfile();
}
}

if (isset($_GET['logout'])) {
$adapter = $hybridauth->getAdapter($_GET['logout']);
$adapter->disconnect();
$hybridauth->disconnectAllAdapters();
}
//HttpClient\Util::redirect('http://supfile.tk');
} catch (Exception $e) {
echo $e->getMessage();
}

}
elseif ($page == 'login') {

} elseif ($page == 'register') {

}
} else {
header('Location: /auth/login');
}

$smarty->display(VIEWS . 'account/' . 'login' . '.tpl');

// password_hash($pass, PASSWORD_ARGON2I);
57 changes: 0 additions & 57 deletions controllers/login.php

This file was deleted.

3 changes: 2 additions & 1 deletion controllers/main.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

if ($action == 'home') {
$title = 'Yacht parts, spares and consumables, delivered anywhere in the world';
$title = '';
} else {
$action = 404;
}
Expand Down
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
require_once(CONFIG . 'conf.php');
require_once(LIB . 'vendor/autoload.php');
require_once(LIB . 'Router.php');
require_once(LIB . 'Db.php');
require_once(CONFIG . 'conf.hybridauth.php');
$Router = new Router();
$url = $Router->getUrl();
$action = $Router->getAction();
$page = $Router->getPage();
$smarty = new Smarty();

$db = new DB();
require_once CONTROLLERS . $Router->getController() . '.php';
139 changes: 139 additions & 0 deletions libraries/Db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php

class DB extends PDO
{

private static $instance;
private $hostname;
private $database;
private $username;
private $password;
private $db;
private $query;

public function __construct() {
try {
$this->hostname = DB_HOST;
$this->database = DB_NAME;
$this->username = DB_USER;
$this->password = DB_PASSWORD;
$this->db = parent::__construct('mysql:host=' . $this->hostname . ';dbname=' . $this->database, $this->username, $this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
parent::setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
throw new Exception('Unable to connect to database.' . $e->getMessage());
}
}

// Returns instance of object or creates it if it doesn't exist yet (singleton style)
public static function getInstance() {
if (!self::$instance) {
self::$instance = new DB();
}
return self::$instance;
}

// Destroying database link at the end of execution
public function __destruct() {
$this->db = null;
}

// No cloning allowed
private function __clone() {
}

public function result($query = false, $attr = false, $nofetch = false, $fetchtype = NULL) {
$return = false;
if ($query) {
try {
$stmt = parent::prepare($query);

if ($attr)
$return = $stmt->execute($attr);
else
$return = $stmt->execute();
} catch (PDOException $e) {
$error_message = $e->getMessage();
$file_error = $e->getFile();
$trace = $e->getTraceAsString();
err("Error: " . $error_message . " On File: " . $file_error . " Traceback: " . $trace);
}

if ($nofetch)
return $return;
else
return $stmt->fetch($fetchtype);
}
return false;
}

public function results($query = false, $attr = false, $nofetch = false, $fetchtype = NULL) {
if ($query) {
try {
$stmt = parent::prepare($query);

if ($attr) {
$return = $stmt->execute($attr);
} else {
$return = $stmt->execute();
}
} catch (PDOException $e) {
err("Error: " . $e->getMessage());
}

if ($nofetch)
return $return;
else
return $stmt->fetchAll($fetchtype);
}
return false;
}

/**
* @param bool $table
* @param bool $attr
* @return bool|null|string
*/
public function insert($table = false, $attr = false) {
if ($table && $attr) {
$names = join(array_keys($attr), ",");
$values = join(array_fill(0, count($attr), "?"), ",");
$attr = array_values($attr);
$result = null;
try {
$stmt = parent::prepare("INSERT INTO `" . $table . "` ($names) VALUES ($values)");
$result = $stmt->execute($attr);

if ($result)
$result = parent::lastInsertId();
} catch (PDOException $e) {
error_log("Error: " . $e->getMessage());
}

return $result;
}
return false;
}

public function update($table = false, $attr = false, $where = 'id') {
if ($table && $attr) {
$whereval = $attr[$where];
unset($attr[$where]);
$names = join(array_keys($attr), " = ?, ") . " = ?";

$attr = array_values($attr);
$attr[] = $whereval;
$result = null;
try {
$stmt = parent::prepare("UPDATE `" . $table . "` SET $names WHERE $where = ?");
// error_log("UPDATE `".$table."` SET $names WHERE $where = ?");
$result = $stmt->execute($attr);
} catch (PDOException $e) {
error_log("Error: " . $e->getMessage());
}

return $result;
}
return false;
}
}
32 changes: 32 additions & 0 deletions libraries/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @param $value
* @param null $title
*/
function err($value, $title = null) {
error_log('====================================================');
if (!is_null($title)) {
error_log('****************' . $title);
}
if (is_array($value) || is_object($value)) {
error_log(print_r($value, true));
} elseif (is_bool($value)) {
error_log($value ? 'true' : 'false');
} else {
error_log($value);
}
}

/**
* @param $value
* @param null $title
*/
function pr($value, $title = null) {
if (!is_null($title)) {
echo '<h1>' . $title . '</h1>';
}
echo '<pre>';
print_r($value);
echo '</pre>';
echo '<hr />';
}
File renamed without changes.
Loading

0 comments on commit a7048d9

Please sign in to comment.