Initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Controllers;
|
||||
|
||||
class ErrorController {
|
||||
|
||||
public function notFound(){
|
||||
|
||||
echo 'not found';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Controllers;
|
||||
|
||||
class IndexController {
|
||||
|
||||
private $tpl;
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
public function main() {
|
||||
|
||||
$this->tpl = new \utils\template(VIEW . 'index.tpl');
|
||||
$this->tpl->render(["test"=>"foo"]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Controllers;
|
||||
|
||||
class PageController {
|
||||
|
||||
private $file;
|
||||
private $userData;
|
||||
private $util;
|
||||
public function __construct() {
|
||||
|
||||
$this->util = new \utils\util();
|
||||
$this->file = new \models\fileModel();
|
||||
$this->userData = $_SESSION['userData'];
|
||||
if(!isset($this->userData)) $this->util->alertExit("Login Dulu bang!!");
|
||||
}
|
||||
|
||||
public function samplePage() {
|
||||
|
||||
$this->file->copyFile(ROOT . 'public/sample.html', ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.html');
|
||||
$this->file->copyFile(ROOT . 'public/sample.js', ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.js');
|
||||
$this->file->copyFile(ROOT . 'public/sample.css', ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.css');
|
||||
$this->util->alertExit("Create Success");
|
||||
|
||||
}
|
||||
|
||||
public function viewPage() {
|
||||
|
||||
$tpl = new \utils\template(VIEW . 'page.tpl');
|
||||
$tpl->render([
|
||||
"script" => './user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.js',
|
||||
"css" => './user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.css',
|
||||
"html" => $this->file->getFile(ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.html')
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
|
||||
if(!in_array($_REQUEST['type'], ['html', 'js', 'css'])) $this->util->alertExit("Invalid type");
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
|
||||
$this->file->createFile(ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.' . $_POST['type'], $_POST['data']);
|
||||
$this->util->alertExit("Edit Success");
|
||||
}
|
||||
|
||||
$tpl = new \utils\template(VIEW . 'textarea.tpl');
|
||||
$tpl->render(["type" => $_GET['type'], "data" => $this->file->getFile(ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.' . $_GET['type'])]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Controllers;
|
||||
|
||||
class UserController {
|
||||
|
||||
private $file;
|
||||
private $user;
|
||||
private $util;
|
||||
public function __construct() {
|
||||
|
||||
$this->util = new \utils\util();
|
||||
$this->file = new \models\fileModel();
|
||||
$this->user = new \models\userModel($this->file);
|
||||
}
|
||||
|
||||
public function login() {
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
|
||||
$_POST['username'] = str_replace(array('.', '/', '\\'), '_', $_POST['username']);
|
||||
if(empty($_POST['username']) || empty($_POST['password']))
|
||||
|
||||
$this->util->alertExit("username or password is empty");
|
||||
|
||||
$userData = $this->user->getUserByUsername($_POST['username']);
|
||||
$hPassword = hash("sha256", $_POST['password']);
|
||||
if($userData['password'] == $hPassword)
|
||||
|
||||
$_SESSION['userData'] = $userData;
|
||||
|
||||
else
|
||||
|
||||
$this->util->alertExit("username or password is wrong");
|
||||
|
||||
$this->util->alertExit("Login Success");
|
||||
}
|
||||
$tpl = new \utils\template(VIEW . 'login.tpl');
|
||||
$tpl->render([]);
|
||||
|
||||
}
|
||||
|
||||
public function register() {
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
||||
|
||||
$_POST['username'] = str_replace(array('.', '/', '\\'), '_', $_POST['username']);
|
||||
if(empty($_POST['username']) || empty($_POST['password']))
|
||||
|
||||
$this->util->alertExit("username or password is empty");
|
||||
|
||||
if(strlen($_POST['username']) < 10)
|
||||
|
||||
$this->util->alertExit("username length must be greater than 10");
|
||||
|
||||
$userData = $this->user->getUserByUsername($_POST['username']);
|
||||
if($userData != null)
|
||||
|
||||
$this->util->alertExit("username already exists");
|
||||
|
||||
$this->user->createUser($_POST['username'], $_POST['password']);
|
||||
$this->util->alertExit("Register Success");
|
||||
}
|
||||
$tpl = new \utils\template(VIEW . 'register.tpl');
|
||||
$tpl->render([]);
|
||||
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
|
||||
session_destroy();
|
||||
$this->util->alertExit("Logout Success");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user