changed files to more updated version
This commit is contained in:
parent
53794ac310
commit
d50b864082
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,2 +0,0 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +0,0 @@
|
||||
################################################################################
|
||||
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
|
||||
################################################################################
|
||||
|
||||
/.vs
|
||||
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -1,24 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Listen for XDebug",
|
||||
"type": "php",
|
||||
"request": "launch",
|
||||
"port": 9000
|
||||
},
|
||||
{
|
||||
"name": "Launch currently open script",
|
||||
"type": "php",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"cwd": "${fileDirname}",
|
||||
"port": 9000
|
||||
}
|
||||
],
|
||||
"php.executablePath": "C:/xampp/php/php.exe",
|
||||
"php.suggest.basic": "false"
|
||||
}
|
||||
5
dev_mvc/.buildpath
Normal file
5
dev_mvc/.buildpath
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<buildpath>
|
||||
<buildpathentry kind="src" path=""/>
|
||||
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
|
||||
</buildpath>
|
||||
22
dev_mvc/.project
Normal file
22
dev_mvc/.project
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dev</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.php.core.PHPNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
class ActionHandler
|
||||
{
|
||||
static function doAction(){
|
||||
$action = '';
|
||||
|
||||
if(isset($_GET['action'])){
|
||||
$action = $_GET['action'];
|
||||
}
|
||||
if(!$action == ''){
|
||||
include_once("./model/actions/model_".$action.".php");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
class AssetHandler{
|
||||
static function printAsset($image, $doSize=false, $size=128){
|
||||
if($doSize){
|
||||
echo '<img src="./view/img/'.$image.'" width='.$size.' height='.$size.' >';
|
||||
}
|
||||
else{
|
||||
echo '<img src="./view/img/'.$image.'>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,286 +0,0 @@
|
||||
<?php
|
||||
Class Database{
|
||||
//Maakt verbinding met de database en returnt pdo opbject
|
||||
static function connectToDB(){
|
||||
//Defineer vars
|
||||
$sql_server = "172.21.0.3"; //docker sql container bridge ip
|
||||
$sql_username = "root";
|
||||
$sql_password = "jenk";
|
||||
$sql_database = "webforum";
|
||||
$dsn = "mysql:host=$sql_server;dbname=$sql_database";
|
||||
//Maak verbinding
|
||||
$con = new PDO($dsn, $sql_username, $sql_password);
|
||||
return $con;
|
||||
}
|
||||
//Controleert of het email adres al in de database voorkomt. Returnt true indien wel.
|
||||
static function checkUsedEmail($email){
|
||||
//Verbind met de database
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM users where email = :email");
|
||||
//Bind parameters
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
//Voer de query uit
|
||||
$query->execute();
|
||||
//Check de hoeveelheid rijen die de database returnt.
|
||||
if($query->rowCount() == 0){
|
||||
//Email adres is niet in gebruik, return false
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
//Email is al in gebruik of komt meer dan een keer voor. Beide gevallen zijn een probleem dus return true.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Controleert of de gebruikersnaam al in de database voorkomt. Returnt true indien wel.
|
||||
static function checkUsedUsername($username){
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM users where username = :username");
|
||||
//Bind parameters
|
||||
$query->bindParam(':username', $username, PDO::PARAM_STR, 256);
|
||||
//Voer de query uit
|
||||
$query->execute();
|
||||
//Check de hoeveelheid rijen die de database returnt.
|
||||
if($query->rowCount() == 0){
|
||||
//Username adres is niet in gebruik, return false
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
//Username is al in gebruik of komt meer dan een keer voor. Beide gevallen zijn een probleem dus return true.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Registreert een gebruiker. Neemt als invoer email, wachtwoord, gebruikersnaam. en email activation key. Nog niet volledig geimplementeerd
|
||||
static function registerUser($email, $password, $username){
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
//Initit db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("INSERT INTO users (username, email, password, reg_ip) VALUES (:username, :email, :password, :ip)");
|
||||
//Bind parameters
|
||||
$query->bindParam(':username', $username, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':password', $password, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':ip', $ip, PDO::PARAM_STR, 256);
|
||||
//Voer query uit
|
||||
$query->execute();
|
||||
}
|
||||
//Check of gegeven login info in de database voorkomt
|
||||
static function isLoginValid($email, $password){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM users where email = :email AND password = :password");
|
||||
//Bind params
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':password', $password, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 1){
|
||||
//login correct (komt voor in de db)
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
//Incorrect
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Vraag gebruikers ID op doormiddel van email en pass
|
||||
static function getUID($email, $password){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT id FROM users where email = :email AND password = :password");
|
||||
//Bind params
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':password', $password, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
return $result;
|
||||
}
|
||||
else{
|
||||
//something went wrong, return -1
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
static function getUsername($uid){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("SELECT username FROM users where id = :uid");
|
||||
$query->bindParam(':uid', $uid, PDO::PARAM_STR, 256);
|
||||
$query->execute();
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
return $result;
|
||||
}
|
||||
else{
|
||||
//something went wrong, return -1
|
||||
return "db_user_invalid";
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* ______ __ __ _____ _ _____ _______ _______ __ _______ _____ ____ _ _
|
||||
* | ____| \/ | /\ |_ _| | /\ / ____|__ __|_ _\ \ / /\|__ __|_ _/ __ \| \ | |
|
||||
* | |__ | \ / | / \ | | | | / \ | | | | | | \ \ / / \ | | | || | | | \| |
|
||||
* | __| | |\/| | / /\ \ | | | | / /\ \| | | | | | \ \/ / /\ \ | | | || | | | . ` |
|
||||
* | |____| | | |/ ____ \ _| |_| |____ / ____ \ |____ | | _| |_ \ / ____ \| | _| || |__| | |\ |
|
||||
* |______|_| |_/_/ \_\_____|______| /_/ \_\_____| |_| |_____| \/_/ \_\_| |_____\____/|_| \_|
|
||||
*
|
||||
*
|
||||
***/
|
||||
|
||||
//Kijk of de user activation key al bestaat in de databse.
|
||||
static function doesUserActivationKeyExist($activationKey){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM email_activation_keys WHERE activationkey = :activationKey");
|
||||
$query->bindParam(':activationKey', $activationKey, PDO::PARAM_STR, 256);
|
||||
$query->execute();
|
||||
if($query->rowCount() == 0){
|
||||
//bestaat nog niet
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
//bestaat al
|
||||
return true;
|
||||
}
|
||||
}
|
||||
static function registerActivationKey($users_id, $activationKey){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("INSERT INTO email_activation_keys (users_id, activationkey) VALUES (:users_id, :activationkey)");
|
||||
$query->bindParam(':users_id', $users_id);
|
||||
$query->bindParam(':activationkey', $activationKey);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Activeer gebruiker en verwijder activation key uit de activation key tabel
|
||||
static function activateUser($activationKey){
|
||||
$con = Database::connectToDb();
|
||||
$query = $con->prepare("SELECT users_id FROM email_activation_keys WHERE activationKey = :activationKey");
|
||||
$query->bindParam('activationKey', $activationKey);
|
||||
$query->execute();
|
||||
$result = -1;
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
}
|
||||
else{
|
||||
//activation key komt niet voor in de db, return -1
|
||||
return -1;
|
||||
}
|
||||
$id = $result;
|
||||
$query = null;
|
||||
$query = $con->prepare("UPDATE users SET active = 1 WHERE id = :id and active = 0");
|
||||
$query->bindParam(':id',$id,PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
/***
|
||||
* _____ ______ _____ _____ _____ ____ _ _ _______ ____ _ ________ _ _ _____
|
||||
* / ____| ____|/ ____/ ____|_ _/ __ \| \ | | |__ __/ __ \| |/ / ____| \ | |/ ____|
|
||||
* | (___ | |__ | (___| (___ | || | | | \| | | | | | | | ' /| |__ | \| | (___
|
||||
* \___ \| __| \___ \\___ \ | || | | | . ` | | | | | | | < | __| | . ` |\___ \
|
||||
* ____) | |____ ____) |___) |_| || |__| | |\ | | | | |__| | . \| |____| |\ |____) |
|
||||
* |_____/|______|_____/_____/|_____\____/|_| \_| |_| \____/|_|\_\______|_| \_|_____/
|
||||
*
|
||||
***/
|
||||
|
||||
|
||||
static function isSessionTokenInUse($token){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM usersessions where token = :token");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 0){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
static function registerNewSession($uid, $token, $expires){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("INSERT INTO usersessions (uid, token, expires) VALUES (:uid, :token, :expires)");
|
||||
//Bind params
|
||||
$query->bindParam(':uid', $uid, PDO::PARAM_INT);
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':expires', $expires, PDO::PARAM_STR);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
}
|
||||
static function isSessionValid($token, $uid){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM usersessions where token = :token AND uid = :uid AND expires > NOW()");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':uid', $uid, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 1){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static function invalidateSession($token){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("DELETE FROM usersessions WHERE token = :token");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
}
|
||||
static function invalidateSessionByUID($uid){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("DELETE FROM usersessions WHERE uid = :uid");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $uid, PDO::PARAM_INT);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
}
|
||||
static function deleteExpiredSessions(){
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("DELETE FROM usersessions WHERE expires < NOW()");
|
||||
$query->execute();
|
||||
}
|
||||
static function getSessionExpiryDate($token){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("SELECT expires FROM usersessions where token = :token");
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
$query->execute();
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
return $result;
|
||||
}
|
||||
else{
|
||||
//something went wrong, return an invalid date.
|
||||
return "2000-01-01 00:00:00";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
Class HUtils{
|
||||
const FETCHGET = 0;
|
||||
const FETCHPOST = 1;
|
||||
static function issetPost($arr_postvars){
|
||||
for ($i=0; $i <sizeof($arr_postvars) ; $i++)
|
||||
{
|
||||
@ -23,21 +21,6 @@ Class HUtils{
|
||||
static function sqlDateToPhpDate($date){
|
||||
return new DateTime($date);
|
||||
}
|
||||
static function getPage($fetchmethod){
|
||||
$p = "";
|
||||
if($fetchmethod == HUtils::FETCHGET){
|
||||
if(isset($_GET['p'])){
|
||||
$p = $_GET['p'];
|
||||
}
|
||||
}
|
||||
else if($fetchmethod == HUtils::FETCHPOST){
|
||||
if(isset($_POST['p']))
|
||||
{
|
||||
$p = $_POST['p'];
|
||||
}
|
||||
}
|
||||
return $p;
|
||||
}
|
||||
static function getSiteTitle(){
|
||||
return "hPHPForum";
|
||||
}
|
||||
|
||||
90
dev_mvc/controller/MVCController.php
Normal file
90
dev_mvc/controller/MVCController.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
class MVCController{
|
||||
private $model;
|
||||
private $viewmodel;
|
||||
private $view;
|
||||
private $viewOverridden = false;
|
||||
private $timesOverridden = 0;
|
||||
private static $mvcController;
|
||||
public static $viewData = [];
|
||||
function MVCController(){
|
||||
self::$mvcController = $this;
|
||||
//prepare current view and view model
|
||||
if(isset($_GET['p']) && $_GET['p'] != ''){
|
||||
$this->view = "./view/webcontent/content_".$_GET['p'].".php";
|
||||
$this->viewmodel = "./viewmodel/viewmodel_".$_GET['p'].".php";
|
||||
}
|
||||
else{
|
||||
$this->view = "./view/webcontent/content_home.php";
|
||||
$this->viewmodel = "./viewmodel/viewmodel_home.php";
|
||||
}
|
||||
|
||||
//prepare current action model
|
||||
if(isset($_POST['action'])){
|
||||
$this->model = "./model/actions/model_".$_POST['action'].".php";
|
||||
}
|
||||
else if(isset($_GET['action'])){
|
||||
$this->model = "./model/actions/model_".$_GET['action'].".php";
|
||||
}
|
||||
else{
|
||||
$this->model = "./model/actions/model_empty.php";
|
||||
}
|
||||
}
|
||||
static function getMVCController():MVCController
|
||||
{
|
||||
return self::$mvcController;
|
||||
}
|
||||
function overrideView($view_target):void
|
||||
{
|
||||
$this->view = "./view/webcontent/content_".$view_target.".php";
|
||||
$this->viewmodel = "./viewmodel/viewmodel_".$view_target.".php";
|
||||
$this->viewOverridden = true;
|
||||
}
|
||||
function executeAction():void
|
||||
{
|
||||
//check if action model is valid
|
||||
if(file_exists($this->model)){
|
||||
//execute action model
|
||||
include_once($this->model);
|
||||
}
|
||||
//model doesn't exist and will not be called
|
||||
else{
|
||||
//debug message
|
||||
echo("caught call on non-existant model file.");
|
||||
}
|
||||
|
||||
}
|
||||
function executeViewmodel():void
|
||||
{
|
||||
if(file_exists($this->viewmodel))
|
||||
{
|
||||
include_once($this->viewmodel);
|
||||
}
|
||||
}
|
||||
function executeModel():void
|
||||
{
|
||||
$this->executeAction();
|
||||
//check if the view was overridden by action.
|
||||
if($this->viewOverridden){
|
||||
//don't need to run the viewmodel twice if it was overridden by action
|
||||
$this->viewOverridden = false;
|
||||
}
|
||||
//run viewmodel
|
||||
$this->executeViewmodel();
|
||||
//run viewmodel again if overridden by viewmodel
|
||||
if($this->viewOverridden)
|
||||
{
|
||||
$this->executeViewmodel();
|
||||
}
|
||||
}
|
||||
function loadView(){
|
||||
if(file_exists($this->view)){
|
||||
include_once($this->view);
|
||||
}
|
||||
else{
|
||||
include_once("./view/webcontent/content_404.php");
|
||||
echo("view: ".$this->view." not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,121 +1,125 @@
|
||||
<?php
|
||||
require_once('./controller/db/Database.php');
|
||||
Class UserSession{
|
||||
public $uid = -1;
|
||||
public $token = "undefined";
|
||||
public $expires;
|
||||
public function UserSession($uid, $token = "undefined"){
|
||||
$this->uid = $uid;
|
||||
$this->token = $token;
|
||||
$this->setExpiry();
|
||||
//echo($loginSessionToken);
|
||||
$_SESSION['usersession'] = $this;
|
||||
setcookie('usersession', $this->token);
|
||||
setcookie('uid', $this->uid);
|
||||
}
|
||||
public function setSessionToken($token){
|
||||
$this->token = $token;
|
||||
}
|
||||
public function getSessionToken(){
|
||||
return $this->token;
|
||||
}
|
||||
public function getFormattedExpiry(){
|
||||
return $this->expires->format('Y-m-d H:i:s');
|
||||
}
|
||||
public function setExpiry(){
|
||||
$this->expires = new DateTime();
|
||||
$this->expires->modify("+ 1 hour");
|
||||
}
|
||||
public static function generateToken(){
|
||||
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
$token = "";
|
||||
for ($i=0; $i < 32 ; $i++) {
|
||||
$token .= $chars[rand(0, strlen($chars) - 1)];
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
public static function isSessionValid(){
|
||||
if(isset($_SESSION['usersession'])){
|
||||
if(!Database::isSessionValid($_SESSION['usersession']->token, $_SESSION['usersession']->uid)){
|
||||
return false;
|
||||
}
|
||||
if(!UserSession::isSessionExpired($_SESSION['usersession'])){
|
||||
//check if session also exists in database
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(isset($_COOKIE['usersession'])){
|
||||
$token = $_COOKIE['usersession'];
|
||||
$uid = $_COOKIE['uid'];
|
||||
if(Database::isSessionValid($token,$uid)){
|
||||
$session = new UserSession($uid, $token);
|
||||
$session->expires = new DateTime(Database::getSessionExpiryDate($token));
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
if(!UserSession::isSessionExpired($session)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function getSession()
|
||||
{
|
||||
return $_SESSION['usersession'];
|
||||
}
|
||||
public static function isSessionExpired($session){
|
||||
//session is expired
|
||||
if(new DateTime() > $session->expires){
|
||||
return true;
|
||||
}
|
||||
//session is not expired
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function isUserSignedIn(){
|
||||
/*
|
||||
if(UserSession::isSessionValid()){
|
||||
if(!UserSession::isSessionExpired(UserSession::getSession())){
|
||||
if(Database::isSessionValid(UserSession::getSession()->token, UserSession::getSession()->uid)){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
//session exists, no need to do anything
|
||||
if(isset($_SESSION['usersession'])){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
if(isset($_COOKIE['usersession'])){
|
||||
//check if the session exists in the database
|
||||
if(Database::isSessionTokenInUse($_COOKIE['usersession'])){
|
||||
//check if database expiration datetime is still valid
|
||||
$expirationDateTime = Database::getSessionExpiryDate($_COOKIE['usersession']);
|
||||
if(new DateTime($expirationDateTime) >= new DateTime()){
|
||||
//user is signed in. Restore session
|
||||
$userSession = new UserSession($_COOKIE['uid'], $_COOKIE['usersession']);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
//remove session from the database
|
||||
Database::invalidateSession($_COOKIE['usersession']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//session either doesn't exist, doesn't exist in cookie, doesn't exist in database, or is expired in the database.
|
||||
return false;
|
||||
}
|
||||
public $uid = -1;
|
||||
public $token = "undefined";
|
||||
public $expires;
|
||||
public static $session;
|
||||
public function UserSession($uid, $token = "undefined"){
|
||||
$this->uid = $uid;
|
||||
$this->token = $token;
|
||||
$this->setExpiry();
|
||||
//echo($loginSessionToken);
|
||||
$_SESSION['usersession'] = $this;
|
||||
setcookie('usersession', $this->token);
|
||||
setcookie('uid', $this->uid);
|
||||
}
|
||||
public function setSessionToken($token){
|
||||
$this->token = $token;
|
||||
}
|
||||
public function getSessionToken(){
|
||||
return $this->token;
|
||||
}
|
||||
public function getFormattedExpiry(){
|
||||
return $this->expires->format('Y-m-d H:i:s');
|
||||
}
|
||||
public function setExpiry(){
|
||||
$this->expires = new DateTime();
|
||||
$this->expires->modify("+ 1 hour");
|
||||
}
|
||||
public static function generateToken(){
|
||||
$chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
$token = "";
|
||||
for ($i=0; $i < 32 ; $i++) {
|
||||
$token .= $chars[rand(0, strlen($chars) - 1)];
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
public static function isSessionValid(){
|
||||
if(isset($_SESSION['usersession'])){
|
||||
if(!Database::isSessionValid($_SESSION['usersession']->token, $_SESSION['usersession']->uid)){
|
||||
return false;
|
||||
}
|
||||
if(!UserSession::isSessionExpired($_SESSION['usersession'])){
|
||||
//check if session also exists in database
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(isset($_COOKIE['usersession'])){
|
||||
$token = $_COOKIE['usersession'];
|
||||
$uid = $_COOKIE['uid'];
|
||||
if(Database::isSessionValid($token,$uid)){
|
||||
$session = new UserSession($uid, $token);
|
||||
$session->expires = new DateTime(Database::getSessionExpiryDate($token));
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
if(!UserSession::isSessionExpired($session)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function getSession()
|
||||
{
|
||||
if(isset($_SESSION['usersession'])){
|
||||
return $_SESSION['usersession'];
|
||||
}
|
||||
}
|
||||
public static function isSessionExpired($session){
|
||||
//session is expired
|
||||
if(new DateTime() > $session->expires){
|
||||
return true;
|
||||
}
|
||||
//session is not expired
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function isUserSignedIn(){
|
||||
/*
|
||||
if(UserSession::isSessionValid()){
|
||||
if(!UserSession::isSessionExpired(UserSession::getSession())){
|
||||
if(Database::isSessionValid(UserSession::getSession()->token, UserSession::getSession()->uid)){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
//session exists, no need to do anything
|
||||
if(isset($_SESSION['usersession'])){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
if(isset($_COOKIE['usersession'])){
|
||||
//check if the session exists in the database
|
||||
if(Database::isSessionTokenInUse($_COOKIE['usersession'])){
|
||||
//check if database expiration datetime is still valid
|
||||
$expirationDateTime = Database::getSessionExpiryDate($_COOKIE['usersession']);
|
||||
if(new DateTime($expirationDateTime) >= new DateTime()){
|
||||
//user is signed in. Restore session
|
||||
$userSession = new UserSession($_COOKIE['uid'], $_COOKIE['usersession']);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
//remove session from the database
|
||||
Database::invalidateSession($_COOKIE['usersession']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//session either doesn't exist, doesn't exist in cookie, doesn't exist in database, or is expired in the database.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
class Reply{
|
||||
public $id;
|
||||
public $user;
|
||||
public $thread;
|
||||
public $text;
|
||||
function Reply($id, $user, $thread, $text){
|
||||
$this->id = $id;
|
||||
$this->user = $user;
|
||||
$this->thread = $thread;
|
||||
$this->text = $text;
|
||||
}
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
public function setId($id){
|
||||
$this->id = $id;
|
||||
}
|
||||
public function getUser(){
|
||||
return $this->user;
|
||||
}
|
||||
public function setUser($user){
|
||||
$this->user = $user;
|
||||
}
|
||||
public function getThread(){
|
||||
return $this->thread;
|
||||
}
|
||||
public function setThread($thread){
|
||||
$this->thread = $thread;
|
||||
}
|
||||
public function getText(){
|
||||
return $this->text;
|
||||
}
|
||||
public function setText($text){
|
||||
$this->text = $text;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
class Thread{
|
||||
static $threadArray = [];
|
||||
public $id;
|
||||
public $titel;
|
||||
public $text;
|
||||
public $user;
|
||||
public $board;
|
||||
public function Thread($id, $titel, $text, $user){
|
||||
$this->id = $id;
|
||||
$this->titel = $titel;
|
||||
$this->text = $text;
|
||||
$this->user = $user;
|
||||
array_push(Thread::$threadArray, $this);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
class User{
|
||||
static $userArray = [];
|
||||
public $id;
|
||||
public $username;
|
||||
public $email;
|
||||
public function User($id, $username, $email, $password){
|
||||
$this->id = $id;
|
||||
$this->username = $username;
|
||||
$this->email = $email;
|
||||
$this->password = $password;
|
||||
array_push(User::$userArray, $this);
|
||||
}
|
||||
public function getId(){
|
||||
return $this->id;
|
||||
}
|
||||
public function setId($id){
|
||||
$this->id = $id;
|
||||
}
|
||||
public function getUsername(){
|
||||
return $this->username;
|
||||
}
|
||||
public function setUsername($username){
|
||||
$this->username = $username;
|
||||
}
|
||||
public function getEmail(){
|
||||
return $this->email;
|
||||
}
|
||||
public function setEmail($email){
|
||||
$this->email = $email;
|
||||
}
|
||||
}
|
||||
?>
|
||||
12
dev_mvc/controller/db/DBBoard.php
Normal file
12
dev_mvc/controller/db/DBBoard.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
require_once './controller/db/Database.php';
|
||||
class DBBoard extends Database{
|
||||
static function getBoards():array
|
||||
{
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM board");
|
||||
$query->execute();
|
||||
return $query->fetchAll(PDO::FETCH_BOTH);
|
||||
}
|
||||
|
||||
}
|
||||
39
dev_mvc/controller/db/DBReply.php
Normal file
39
dev_mvc/controller/db/DBReply.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once './controller/db/Database.php';
|
||||
|
||||
class DBReply extends Database{
|
||||
static function createReply($uid, $threadID, $content){
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("INSERT INTO reply (thread_ID, users_ID, content) VALUES (:tid, :uid, :content);");
|
||||
$query->bindParam(":uid", $uid);
|
||||
$query->bindParam(":tid", $threadID);
|
||||
$query->bindParam(":content", $content);
|
||||
echo "$uid, $threadID, $content";
|
||||
$query->execute();
|
||||
}
|
||||
static function getReplyByID($id):array
|
||||
{
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM reply WHERE id = :id");
|
||||
$query->bindParam(":id", $id);
|
||||
$query->execute();
|
||||
return $query->fetch(PDO::FETCH_BOTH);
|
||||
|
||||
}
|
||||
static function getRepliesByThreadID($tid):array
|
||||
{
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM reply WHERE thread_ID = :tid");
|
||||
$query->bindParam(":tid", $tid);
|
||||
$query->execute();
|
||||
return $query->fetchAll(PDO::FETCH_BOTH);
|
||||
}
|
||||
static function getLastReplyByThreadID():array
|
||||
{
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM reply WHERE thread_ID = :tid ORDER BY date_created DESC LIMIT 1");
|
||||
$query->bindParam(":tid", $tid);
|
||||
$query->execute();
|
||||
return $query->fetch(PDO::FETCH_BOTH);
|
||||
}
|
||||
}
|
||||
37
dev_mvc/controller/db/DBThread.php
Normal file
37
dev_mvc/controller/db/DBThread.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once './model/forum/Thread.php';
|
||||
class DBThread extends Database {
|
||||
static function getThreadByID($id){
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM thread WHERE ID = :id");
|
||||
$query->bindParam(":id", $id);
|
||||
$query->execute();
|
||||
return $query->fetch(PDO::FETCH_BOTH);
|
||||
}
|
||||
static function getThreadsByBoard($boardID){
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM thread WHERE board_ID = :boardID");
|
||||
$query->bindParam(":boardID", $boardID);
|
||||
$query->execute();
|
||||
return $query->fetchAll(PDO::FETCH_BOTH);
|
||||
}
|
||||
static function createThread($threadObject){
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare( "INSERT INTO thread" .
|
||||
"(users_ID, board_ID, title, text)" .
|
||||
"VALUES (:uid, :bid, :title, :content);");
|
||||
|
||||
$uid = $threadObject->getUserID();
|
||||
$bid = $threadObject->getBoardID();
|
||||
$title = $threadObject->getTitle();
|
||||
$content = $threadObject->getContent();
|
||||
|
||||
$query->bindParam(":uid", $uid);
|
||||
$query->bindParam(":bid", $bid);
|
||||
$query->bindParam(":title", $title);
|
||||
$query->bindParam(":content", $content);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
134
dev_mvc/controller/db/DBUser.php
Normal file
134
dev_mvc/controller/db/DBUser.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
class DBUser extends Database
|
||||
{
|
||||
static function isUserActive($uid){
|
||||
$user = self::getUserByUID($uid);
|
||||
if($user['active']){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static function getUserByUID($uid){
|
||||
$con = self::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM users WHERE ID = :uid");
|
||||
$query->bindParam(":uid", $uid);
|
||||
$query->execute();
|
||||
return $query->fetch(PDO::FETCH_BOTH);
|
||||
}
|
||||
|
||||
|
||||
//Controleert of het email adres al in de database voorkomt. Returnt true indien wel.
|
||||
static function checkUsedEmail($email){
|
||||
//Verbind met de database
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM users where email = :email");
|
||||
//Bind parameters
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
//Voer de query uit
|
||||
$query->execute();
|
||||
//Check de hoeveelheid rijen die de database returnt.
|
||||
if($query->rowCount() == 0){
|
||||
//Email adres is niet in gebruik, return false
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
//Email is al in gebruik of komt meer dan een keer voor. Beide gevallen zijn een probleem dus return true.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Controleert of de gebruikersnaam al in de database voorkomt. Returnt true indien wel.
|
||||
static function checkUsedUsername($username){
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM users where username = :username");
|
||||
//Bind parameters
|
||||
$query->bindParam(':username', $username, PDO::PARAM_STR, 256);
|
||||
//Voer de query uit
|
||||
$query->execute();
|
||||
//Check de hoeveelheid rijen die de database returnt.
|
||||
if($query->rowCount() == 0){
|
||||
//Username adres is niet in gebruik, return false
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
//Username is al in gebruik of komt meer dan een keer voor. Beide gevallen zijn een probleem dus return true.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//Registreert een gebruiker. Neemt als invoer email, wachtwoord, gebruikersnaam. en email activation key. Nog niet volledig geimplementeerd
|
||||
static function registerUser($email, $password, $username){
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
//Initit db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("INSERT INTO users (username, email, password, reg_ip) VALUES (:username, :email, :password, :ip)");
|
||||
//Bind parameters
|
||||
$query->bindParam(':username', $username, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':password', $password, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':ip', $ip, PDO::PARAM_STR, 256);
|
||||
//Voer query uit
|
||||
$query->execute();
|
||||
}
|
||||
//Check of gegeven login info in de database voorkomt
|
||||
static function isLoginValid($email, $password){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM users where email = :email AND password = :password");
|
||||
//Bind params
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':password', $password, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 1){
|
||||
//login correct (komt voor in de db)
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
//Incorrect
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//Vraag gebruikers ID op doormiddel van email en pass
|
||||
static function getUID($email, $password){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT id FROM users where email = :email AND password = :password");
|
||||
//Bind params
|
||||
$query->bindParam(':email', $email, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':password', $password, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
return $result;
|
||||
}
|
||||
else{
|
||||
//something went wrong, return -1
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
static function getUsername($uid){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("SELECT username FROM users where id = :uid");
|
||||
$query->bindParam(':uid', $uid, PDO::PARAM_STR, 256);
|
||||
$query->execute();
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
return $result;
|
||||
}
|
||||
else{
|
||||
//something went wrong, return -1
|
||||
return "db_user_invalid";
|
||||
}
|
||||
}
|
||||
}
|
||||
172
dev_mvc/controller/db/Database.php
Normal file
172
dev_mvc/controller/db/Database.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
Class Database{
|
||||
static function connectToDB(){
|
||||
//Defineer vars
|
||||
$sql_server = "localhost";
|
||||
$sql_username = "root";
|
||||
$sql_password = "kankerlow";
|
||||
$sql_database = "webforum";
|
||||
$dsn = "mysql:host=$sql_server;dbname=$sql_database";
|
||||
//Maak verbinding
|
||||
$con = new PDO($dsn, $sql_username, $sql_password);
|
||||
return $con;
|
||||
}
|
||||
|
||||
/***
|
||||
* ______ __ __ _____ _ _____ _______ _______ __ _______ _____ ____ _ _
|
||||
* | ____| \/ | /\ |_ _| | /\ / ____|__ __|_ _\ \ / /\|__ __|_ _/ __ \| \ | |
|
||||
* | |__ | \ / | / \ | | | | / \ | | | | | | \ \ / / \ | | | || | | | \| |
|
||||
* | __| | |\/| | / /\ \ | | | | / /\ \| | | | | | \ \/ / /\ \ | | | || | | | . ` |
|
||||
* | |____| | | |/ ____ \ _| |_| |____ / ____ \ |____ | | _| |_ \ / ____ \| | _| || |__| | |\ |
|
||||
* |______|_| |_/_/ \_\_____|______| /_/ \_\_____| |_| |_____| \/_/ \_\_| |_____\____/|_| \_|
|
||||
*
|
||||
*
|
||||
***/
|
||||
|
||||
//Kijk of de user activation key al bestaat in de databse.
|
||||
static function doesUserActivationKeyExist($activationKey){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("SELECT * FROM email_activation_keys WHERE activationkey = :activationKey");
|
||||
$query->bindParam(':activationKey', $activationKey, PDO::PARAM_STR, 256);
|
||||
$query->execute();
|
||||
if($query->rowCount() == 0){
|
||||
//bestaat nog niet
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
//bestaat al
|
||||
return true;
|
||||
}
|
||||
}
|
||||
static function registerActivationKey($users_id, $activationKey){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("INSERT INTO email_activation_keys (users_id, activationkey) VALUES (:users_id, :activationkey)");
|
||||
$query->bindParam(':users_id', $users_id);
|
||||
$query->bindParam(':activationkey', $activationKey);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Activeer gebruiker en verwijder activation key uit de activation key tabel
|
||||
static function activateUser($activationKey){
|
||||
$con = Database::connectToDb();
|
||||
$query = $con->prepare("SELECT users_id FROM email_activation_keys WHERE activationKey = :activationKey");
|
||||
$query->bindParam('activationKey', $activationKey);
|
||||
$query->execute();
|
||||
$result = -1;
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
}
|
||||
else{
|
||||
//activation key komt niet voor in de db, return -1
|
||||
return -1;
|
||||
}
|
||||
$id = $result;
|
||||
$query = null;
|
||||
$query = $con->prepare("UPDATE users SET active = 1 WHERE id = :id and active = 0");
|
||||
$query->bindParam(':id',$id,PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
}
|
||||
|
||||
/***
|
||||
* _____ ______ _____ _____ _____ ____ _ _ _______ ____ _ ________ _ _ _____
|
||||
* / ____| ____|/ ____/ ____|_ _/ __ \| \ | | |__ __/ __ \| |/ / ____| \ | |/ ____|
|
||||
* | (___ | |__ | (___| (___ | || | | | \| | | | | | | | ' /| |__ | \| | (___
|
||||
* \___ \| __| \___ \\___ \ | || | | | . ` | | | | | | | < | __| | . ` |\___ \
|
||||
* ____) | |____ ____) |___) |_| || |__| | |\ | | | | |__| | . \| |____| |\ |____) |
|
||||
* |_____/|______|_____/_____/|_____\____/|_| \_| |_| \____/|_|\_\______|_| \_|_____/
|
||||
*
|
||||
***/
|
||||
|
||||
|
||||
static function isSessionTokenInUse($token){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM usersessions where token = :token");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 0){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
static function registerNewSession($uid, $token, $expires){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("INSERT INTO usersessions (uid, token, expires) VALUES (:uid, :token, :expires)");
|
||||
//Bind params
|
||||
$query->bindParam(':uid', $uid, PDO::PARAM_INT);
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':expires', $expires, PDO::PARAM_STR);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
}
|
||||
static function isSessionValid($token, $uid){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("SELECT * FROM usersessions where token = :token AND uid = :uid AND expires > NOW()");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
$query->bindParam(':uid', $uid, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
//Check hoeveelheid teruggestuurde rijen
|
||||
if($query->rowCount() == 1){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static function invalidateSession($token){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("DELETE FROM usersessions WHERE token = :token");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
}
|
||||
static function invalidateSessionByUID($uid){
|
||||
//Init db connection
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("DELETE FROM usersessions WHERE uid = :uid");
|
||||
//Bind params
|
||||
$query->bindParam(':token', $uid, PDO::PARAM_INT);
|
||||
//Voer query it
|
||||
$query->execute();
|
||||
}
|
||||
static function deleteExpiredSessions(){
|
||||
$con = Database::connectToDB();
|
||||
//Bereid query voor
|
||||
$query = $con->prepare("DELETE FROM usersessions WHERE expires < NOW()");
|
||||
$query->execute();
|
||||
}
|
||||
static function getSessionExpiryDate($token){
|
||||
$con = Database::connectToDB();
|
||||
$query = $con->prepare("SELECT expires FROM usersessions where token = :token");
|
||||
$query->bindParam(':token', $token, PDO::PARAM_STR, 256);
|
||||
$query->execute();
|
||||
if($query->rowCount() == 1){
|
||||
//login correct, return uid
|
||||
$result = $query->fetch(PDO::FETCH_COLUMN);
|
||||
return $result;
|
||||
}
|
||||
else{
|
||||
//something went wrong, return an invalid date.
|
||||
return "2000-01-01 00:00:00";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,33 +1,9 @@
|
||||
<?php
|
||||
/*Code door Andreas Schaafsma ITA4-1b
|
||||
*
|
||||
* Notities voor bij nakijken
|
||||
* Model wordt opgevraagd via POST (of via GET doormiddel van de ActionHandler controller.)
|
||||
* MAIL is werkend en stuurt een verificatiecode op zie: model_do_register
|
||||
* Activeringscode wordt correct opgeslagen in de database maar de pagina voor activeren is nog niet geimplementeerd.
|
||||
* Alle regeling van de database connectie zit in ./controller/Database.php doormiddel van static class members om alles makkelijk te groeperen
|
||||
* Er is ook een rudimentair login token systeem om ervoor te zorgen dat gebruikers ingelogd blijven zelfs als de $_SESSION[] vervalt.
|
||||
* Deze login status verdwijnt weer na ongeveer een uurtje.
|
||||
*
|
||||
*/
|
||||
//include class lib.
|
||||
include_once("./controller/Database.php");
|
||||
include_once("./controller/UserSession.php");
|
||||
include_once("./controller/HUtils.php");
|
||||
include_once("./controller/ActionHandler.php");
|
||||
//Start session.
|
||||
//date_default_timezone_set('Europe/Amsterdam');
|
||||
require_once('./controller/MVCController.php');
|
||||
require_once('./controller/UserSession.php');
|
||||
session_start();
|
||||
//Execute Actie zo nodig.
|
||||
ActionHandler::doAction();
|
||||
//Store de geselecteerde model in variabele $model
|
||||
$model=HUtils::getPage(HUtils::FETCHPOST);
|
||||
//Model side operaties die afgerond moeten worden voor de paginacontent in wordt geladen
|
||||
$path = "./model/model_".$model.".php";
|
||||
if($model != ""){
|
||||
if(file_exists($path)){
|
||||
include_once($path);
|
||||
}
|
||||
}
|
||||
//laad de pagina view
|
||||
include("./view/pagecontent/content_page.php");
|
||||
$mvcController = new MVCController();
|
||||
$mvcController->executeModel();
|
||||
include_once("./view/content_pagetemplate.php");
|
||||
?>
|
||||
15
dev_mvc/model/actions/model_create_reply.php
Normal file
15
dev_mvc/model/actions/model_create_reply.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once './controller/UserSession.php';
|
||||
require_once('./controller/HUtils.php');
|
||||
require_once './controller/db/DBReply.php';
|
||||
require_once './model/forum/Reply.php';
|
||||
//dit bestand bestaat grotendeels uit dummy code.
|
||||
//Ik heb onvoldoende tijd gehad tijdens de afgelopen paar weken en het was extreem druk in de klas tijdens de les.
|
||||
$uid = $_SESSION['usersession']->uid;
|
||||
if(HUtils::issetPost(['thread', 'content']));
|
||||
{
|
||||
$reply = new Reply(-1, $_POST['thread'], $uid, $_POST['content']);
|
||||
print_r($reply);
|
||||
DBReply::createReply($reply->getUserid(), $reply->getThreadID(), $reply->getContent());
|
||||
}
|
||||
?>
|
||||
14
dev_mvc/model/actions/model_create_thread.php
Normal file
14
dev_mvc/model/actions/model_create_thread.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require_once './controller/UserSession.php';
|
||||
require_once('./controller/HUtils.php');
|
||||
require_once './controller/db/DBThread.php';
|
||||
require_once './model/forum/Thread.php';
|
||||
//dit bestand bestaat grotendeels uit dummy code.
|
||||
//Ik heb onvoldoende tijd gehad tijdens de afgelopen paar weken en het was extreem druk in de klas tijdens de les.
|
||||
$uid = $_SESSION['usersession']->uid;
|
||||
if(HUtils::issetPost(['title', 'content', 'board']));
|
||||
{
|
||||
$thread = new Thread(-1, $uid, $_POST['board'], $_POST['title'], $_POST['content']);
|
||||
DBThread::createThread($thread);
|
||||
}
|
||||
?>
|
||||
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
session_destroy();
|
||||
session_start();
|
||||
?>
|
||||
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
//Include classes
|
||||
include_once("./controller/Database.php");
|
||||
include_once("./controller/HUtils.php");
|
||||
require_once("./controller/db/Database.php");
|
||||
require_once("./controller/db/DBUser.php");
|
||||
require_once("./controller/HUtils.php");
|
||||
if(HUtils::issetPost(['email', 'pass', 'pass2', 'name'])){
|
||||
$email = $_POST['email'];
|
||||
$pass = $_POST['pass'];
|
||||
@ -9,15 +10,15 @@ if(HUtils::issetPost(['email', 'pass', 'pass2', 'name'])){
|
||||
$name = $_POST['name'];
|
||||
if($pass == $pass2){
|
||||
//Check of email aanwezig is in de database
|
||||
if(!Database::checkUsedEmail($email) && !Database::checkUsedUsername($name)){
|
||||
if(!DBUser::checkUsedEmail($email) && !DBUser::checkUsedUsername($name)){
|
||||
$verificationKey = HUtils::generateRandomKey();
|
||||
while(Database::doesUserActivationKeyExist($verificationKey)){
|
||||
while(DBUser::doesUserActivationKeyExist($verificationKey)){
|
||||
$verificationKey = HUtils::generateRandomKey();
|
||||
}
|
||||
//TO DO: Create verification key
|
||||
Database::registerUser($email, $pass, $name);
|
||||
$uid = Database::getUID($email, $pass);
|
||||
Database::registerActivationKey($uid,$verificationKey);
|
||||
DBUser::registerUser($email, $pass, $name);
|
||||
$uid = DBUser::getUID($email, $pass);
|
||||
DBUser::registerActivationKey($uid,$verificationKey);
|
||||
$message = 'Please follow the link to verify your account: http://localhost/webforum_redux/hforumphp/dev_mvc/index.php?p=verify&key='.$verificationKey;
|
||||
$headers = 'From: webmaster@example.com' . "\r\n" .
|
||||
'Reply-To: webmaster@example.com' . "\r\n" .
|
||||
3
dev_mvc/model/actions/model_empty.php
Normal file
3
dev_mvc/model/actions/model_empty.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
?>
|
||||
59
dev_mvc/model/actions/model_login.php
Normal file
59
dev_mvc/model/actions/model_login.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
$debuginfo = false;
|
||||
require_once("./controller/UserSession.php");
|
||||
require_once("./controller/db/Database.php");
|
||||
require_once("./controller/db/DBUser.php");
|
||||
require_once("./controller/HUtils.php");
|
||||
$skipoverride = false;
|
||||
if(!UserSession::isUserSignedIn()){
|
||||
if(HUtils::issetPost(['email','password'])){
|
||||
if(DBUser::isLoginValid($_POST['email'], $_POST['password'])){
|
||||
//obtain UID
|
||||
$uid = DBUser::getUID($_POST['email'], $_POST['password']);
|
||||
if($uid != -1){
|
||||
if(DBUser::isUserActive($uid)){
|
||||
//obtain username
|
||||
//$username = DBUser::getUsername($uid);
|
||||
//gen unique session token
|
||||
$token = UserSession::generateToken();
|
||||
//regen if already in use
|
||||
while(Database::isSessionTokenInUse($token)){
|
||||
$token = UserSession::generateToken();
|
||||
}
|
||||
$a = new UserSession($uid, $token);
|
||||
if($debuginfo){
|
||||
echo $a->getSessionToken();
|
||||
echo "<br>";
|
||||
echo $a->uid;
|
||||
echo "<br>";
|
||||
echo $a->username;
|
||||
}
|
||||
//clean up expired sessions from ANY users
|
||||
Database::deleteExpiredSessions();
|
||||
Database::registerNewSession($a->uid, $a->token, $a->getFormattedExpiry());
|
||||
//logged in, time to continue with other stuff
|
||||
}
|
||||
else{
|
||||
MVCController::getMVCController()->overrideView("account_inactive");
|
||||
$skipoverride = true;
|
||||
echo('ree');
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo "uid returned -1 from db interface";
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo("login invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
//we're done, don't even need to log in, session already active
|
||||
}
|
||||
|
||||
if(!UserSession::isUserSignedIn() &&!$skipoverride){
|
||||
MVCController::getMVCController()->overrideView("error_login");
|
||||
}
|
||||
|
||||
?>
|
||||
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
require_once('./controller/db/Database.php');
|
||||
$_SESSION['usersession'] = null;
|
||||
Database::invalidateSession($_COOKIE['usersession']);
|
||||
session_destroy();
|
||||
?>
|
||||
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
require('./model/User.php');
|
||||
|
||||
class Thread{
|
||||
private $id;
|
||||
private $title;
|
||||
private $content;
|
||||
function Thread(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
13
dev_mvc/model/forum/Board.php
Normal file
13
dev_mvc/model/forum/Board.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
class Board {
|
||||
public $id;
|
||||
public $name;
|
||||
public $permLevel;
|
||||
function Board($id, $name, $permLevel){
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->permLevel = $permLevel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
102
dev_mvc/model/forum/Reply.php
Normal file
102
dev_mvc/model/forum/Reply.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
class Reply {
|
||||
public $id;
|
||||
public $threadID;
|
||||
public $userID;
|
||||
public $content;
|
||||
public $date;
|
||||
public $owner;
|
||||
|
||||
function Reply($id, $threadID, $userID, $content, $date = null){
|
||||
$this->id = $id;
|
||||
$this->threadID = $threadID;
|
||||
$this->userID = $userID;
|
||||
$this->content = $content;
|
||||
$dateTime = new DateTime($date);
|
||||
$this->date = $dateTime;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOwner():User {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $owner
|
||||
*/
|
||||
public function setOwner($owner) {
|
||||
$this->owner = $owner;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getThreadID() {
|
||||
return $this->threadID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUserID() {
|
||||
return $this->userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDate() {
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $threadID
|
||||
*/
|
||||
public function setThreadID($threadID) {
|
||||
$this->threadID = $threadID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $userID
|
||||
*/
|
||||
public function setUserID($userID) {
|
||||
$this->userID = $userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $content
|
||||
*/
|
||||
public function setContent($content) {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $date
|
||||
*/
|
||||
public function setDate($date) {
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
143
dev_mvc/model/forum/Thread.php
Normal file
143
dev_mvc/model/forum/Thread.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
class Thread {
|
||||
private $id;
|
||||
private $title;
|
||||
private $boardID;
|
||||
private $userID;
|
||||
private $content;
|
||||
private $date_created;
|
||||
private $replies = [];
|
||||
private $lastReplyDate;
|
||||
private $owner;
|
||||
|
||||
|
||||
function Thread($id, $userID, $boardID, $title, $content, $date_created = null) {
|
||||
$this->id = $id;
|
||||
$this->title = $title;
|
||||
$this->boardID = $boardID;
|
||||
$this->userID = $userID;
|
||||
$this->content = $content;
|
||||
|
||||
$dateTime = new DateTime($date_created);
|
||||
$this->date_created = $dateTime;
|
||||
|
||||
/*
|
||||
if(isset($threadData)){
|
||||
$this->id = $threadData['id'];
|
||||
$this->title = $threadData['title'];
|
||||
$this->boardID = $threadData['boardID'];
|
||||
$this->userID = $threadData['userID'];
|
||||
$this->content = $threadData['content'];
|
||||
}
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* @return multitype:
|
||||
*/
|
||||
public function getReplies() {
|
||||
return $this->replies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOwner():User {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param multitype: $replies
|
||||
*/
|
||||
public function setReplies($replies) {
|
||||
$this->replies = $replies;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $owner
|
||||
*/
|
||||
public function setOwner($owner) {
|
||||
$this->owner = $owner;
|
||||
}
|
||||
public function getId():int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string $title
|
||||
*/
|
||||
public function getTitle():string {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int $boardID
|
||||
*/
|
||||
public function getBoardID():int {
|
||||
return $this->boardID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int $userID
|
||||
*/
|
||||
public function getUserID():int {
|
||||
return $this->userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string $content
|
||||
*/
|
||||
public function getContent():string {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*/
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $boardID
|
||||
*/
|
||||
public function setBoardID($boardID) {
|
||||
$this->boardID = $boardID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $userID
|
||||
*/
|
||||
public function setUserID($userID) {
|
||||
$this->userID = $userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
*/
|
||||
public function setContent($content) {
|
||||
$this->content = $content;
|
||||
}
|
||||
/**
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getDate_created() {
|
||||
return $this->date_created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $date_created
|
||||
*/
|
||||
public function setDate_created($date_created) {
|
||||
$this->date_created = $date_created;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
138
dev_mvc/model/forum/User.php
Normal file
138
dev_mvc/model/forum/User.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
class User {
|
||||
public $id;
|
||||
public $username;
|
||||
public $email;
|
||||
public $password;
|
||||
public $reg_date;
|
||||
public $login_date;
|
||||
public $reg_ip;
|
||||
public $permissions;
|
||||
function User($id, $username, $email, $password, $reg_date, $login_date, $reg_ip, $permissions){
|
||||
$this->id = $id;
|
||||
$this->username = $username;
|
||||
$this->email = $email;
|
||||
$this->password = $password;
|
||||
$this->reg_date = $reg_date;
|
||||
$this->login_date = $login_date;
|
||||
$this->reg_ip=$reg_ip;
|
||||
$this->permissions=$permissions;
|
||||
}
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUsername() {
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEmail() {
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReg_date() {
|
||||
return $this->reg_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLogin_date() {
|
||||
return $this->login_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReg_ip() {
|
||||
return $this->reg_ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPermissions() {
|
||||
return $this->permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
*/
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $username
|
||||
*/
|
||||
public function setUsername($username) {
|
||||
$this->username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $email
|
||||
*/
|
||||
public function setEmail($email) {
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $password
|
||||
*/
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $reg_date
|
||||
*/
|
||||
public function setReg_date($reg_date) {
|
||||
$this->reg_date = $reg_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $login_date
|
||||
*/
|
||||
public function setLogin_date($login_date) {
|
||||
$this->login_date = $login_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $reg_ip
|
||||
*/
|
||||
public function setReg_ip($reg_ip) {
|
||||
$this->reg_ip = $reg_ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $permissions
|
||||
*/
|
||||
public function setPermissions($permissions) {
|
||||
$this->permissions = $permissions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
//dit bestand bestaat grotendeels uit dummy code.
|
||||
//Ik heb onvoldoende tijd gehad tijdens de afgelopen paar weken en het was extreem druk in de klas tijdens de les.
|
||||
if(HUtils::issetPost(['topic_title', 'topic_content', 'topic_author']));
|
||||
{
|
||||
$topic_title = $_GET['topic_title'];
|
||||
$topic_content = $_GET['topic_content'];
|
||||
$topic_author = $_GET['topic_author'];
|
||||
Database::createThread($topic_title, $topic_content, $topic_author);
|
||||
}
|
||||
?>
|
||||
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
$debuginfo = false;
|
||||
include_once("./controller/UserSession.php");
|
||||
include_once("./controller/Database.php");
|
||||
include_once("./controller/HUtils.php");
|
||||
if(!UserSession::isUserSignedIn()){
|
||||
if(HUtils::issetPost(['email','password'])){
|
||||
if(Database::isLoginValid($_POST['email'], $_POST['password'])){
|
||||
//obtain UID
|
||||
$uid = Database::getUID($_POST['email'], $_POST['password']);
|
||||
if($uid != -1){
|
||||
//obtain username
|
||||
$username = Database::getUsername($uid);
|
||||
//gen unique session token
|
||||
$token = UserSession::generateToken();
|
||||
//regen if already in use
|
||||
while(Database::isSessionTokenInUse($token)){
|
||||
$token = UserSession::generateToken();
|
||||
}
|
||||
$a = new UserSession($uid, $token);
|
||||
if($debuginfo){
|
||||
echo $a->getSessionToken();
|
||||
echo "<br>";
|
||||
echo $a->uid;
|
||||
echo "<br>";
|
||||
echo $a->username;
|
||||
}
|
||||
//clean up expired sessions from ANY users
|
||||
Database::deleteExpiredSessions();
|
||||
Database::registerNewSession($a->uid, $a->token, $a->getFormattedExpiry());
|
||||
//logged in, time to continue with other stuff
|
||||
}
|
||||
else{
|
||||
echo "uid returned -1 from db interface";
|
||||
}
|
||||
}
|
||||
else{
|
||||
echo("login invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
//we're done, don't even need to log in, session already active
|
||||
}
|
||||
?>
|
||||
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
$host="172.21.0.3"; //docker sql container bridge ip
|
||||
|
||||
$root="root";
|
||||
$root_password="jenk"; //testdb password
|
||||
|
||||
$user='forumadmin';
|
||||
$pass='doesntmatter';
|
||||
$db="webforum";
|
||||
|
||||
try {
|
||||
$dbh = new PDO("mysql:host=$host", $root, $root_password);
|
||||
|
||||
$dbh->exec("CREATE DATABASE `$db`;
|
||||
CREATE USER '$user'@'localhost' IDENTIFIED BY '$pass';
|
||||
GRANT ALL ON `$db`.* TO '$user'@'localhost';
|
||||
FLUSH PRIVILEGES;")
|
||||
or die(print_r($dbh->errorInfo(), true));
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("DB ERROR: ". $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$dsn = "mysql:host=$host;dbname=$db";
|
||||
//Maak verbinding
|
||||
$con = new PDO($dsn, $root, $root_password);
|
||||
$con->exec("CREATE TABLE `board` (
|
||||
`ID` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(256) NOT NULL,
|
||||
`description` text NOT NULL,
|
||||
`permLevel` int(16) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1");
|
||||
$con->exec("CREATE TABLE `email_activation_keys` (
|
||||
`id` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`users_id` int(16) NOT NULL,
|
||||
`activationkey` varchar(256) NOT NULL,
|
||||
PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1");
|
||||
$con->exec("CREATE TABLE `reply` (
|
||||
`ID` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`thread_ID` int(16) NOT NULL,
|
||||
`users_ID` int(16) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1");
|
||||
$con->exec("CREATE TABLE `thread` (
|
||||
`ID` int(16) NOT NULL AUTO_INCREMENT,
|
||||
`users_ID` int(16) NOT NULL,
|
||||
`board_ID` int(16) NOT NULL,
|
||||
`title` varchar(256) NOT NULL,
|
||||
`text` text NOT NULL,
|
||||
`date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1");
|
||||
$con->exec("CREATE TABLE `users` (
|
||||
`ID` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(256) NOT NULL,
|
||||
`email` varchar(256) NOT NULL,
|
||||
`password` varchar(256) NOT NULL,
|
||||
`reg_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`login_date` datetime NOT NULL,
|
||||
`reg_ip` varchar(256) NOT NULL,
|
||||
`permissions` int(11) NOT NULL DEFAULT '-1',
|
||||
`active` tinyint(1) DEFAULT '0',
|
||||
PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1");
|
||||
$con->exec("CREATE TABLE `usersessions` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`uid` int(11) NOT NULL,
|
||||
`token` varchar(256) NOT NULL,
|
||||
`expires` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1");
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
die("DB ERROR: ". $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
phpinfo();
|
||||
|
||||
?>
|
||||
25
dev_mvc/view/content_pagetemplate.php
Normal file
25
dev_mvc/view/content_pagetemplate.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require_once("./controller/MVCController.php");
|
||||
require_once("index.php");
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="./view/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="row">
|
||||
<?php
|
||||
include_once("./view/webcontent/content_header.php");
|
||||
?>
|
||||
</header>
|
||||
<div class="main">
|
||||
<?php
|
||||
$mvcController->loadView();
|
||||
?>
|
||||
</div>
|
||||
<footer>
|
||||
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,4 +1,123 @@
|
||||
*{
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
html, body{
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background-color: #333333;
|
||||
}
|
||||
body{
|
||||
|
||||
}
|
||||
|
||||
loginForm{
|
||||
|
||||
}
|
||||
.logo{
|
||||
height: 100px;
|
||||
width: 100px;
|
||||
box-sizing: border-box;
|
||||
border-radius: 10px;
|
||||
justify-self: left;
|
||||
font-size: 50pt;
|
||||
padding: 10pt;
|
||||
color: white;
|
||||
margin-right: 10px;
|
||||
/* Permalink - use to edit and share this gradient: https://colorzilla.com/gradient-editor/#1e5799+0,45427a+100 */
|
||||
background: #1e5799; /* Old browsers */
|
||||
background: -moz-linear-gradient(-45deg, #1e5799 0%, #45427a 100%); /* FF3.6-15 */
|
||||
background: -webkit-linear-gradient(-45deg, #1e5799 0%,#45427a 100%); /* Chrome10-25,Safari5.1-6 */
|
||||
background: linear-gradient(135deg, #1e5799 0%,#45427a 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
|
||||
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#45427a',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
|
||||
|
||||
-webkit-touch-callout: none; /* iOS Safari */
|
||||
-webkit-user-select: none; /* Safari */
|
||||
-khtml-user-select: none; /* Konqueror HTML */
|
||||
-moz-user-select: none; /* Firefox */
|
||||
-ms-user-select: none; /* Internet Explorer/Edge */
|
||||
user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */
|
||||
box-shadow: 0px 0px 20px black;
|
||||
}
|
||||
.row{
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-basis: auto;
|
||||
}
|
||||
header{
|
||||
margin-top: 10px;
|
||||
}
|
||||
nav{
|
||||
border-radius: 10px;
|
||||
display:flex;
|
||||
flex-direction: flex-row;
|
||||
flex-basis: auto;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
background-color: gray;
|
||||
width: 80%;
|
||||
height: 100px;
|
||||
max-height: 100px;
|
||||
|
||||
|
||||
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
align-self: center;
|
||||
justify-self: center;
|
||||
box-shadow: 0px 0px 20px black;
|
||||
}
|
||||
nav a{
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
text-decoration: none;
|
||||
font-size: 20pt;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
}
|
||||
.main{
|
||||
border-radius: 15px;
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-grow: 0;
|
||||
flex-shrink: 1;
|
||||
background-color: white;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0px 0px 20px black;
|
||||
}
|
||||
input{
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
}
|
||||
textarea{
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
resize: none;
|
||||
width: 50vw;
|
||||
height: 20vw;
|
||||
}
|
||||
table {
|
||||
font-family: arial, sans-serif;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
width: 80vw;
|
||||
}
|
||||
|
||||
td, th {
|
||||
border: 1px solid #dddddd;
|
||||
text-align: left;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
tr:nth-child(even) {
|
||||
background-color: #dddddd;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 57 KiB |
@ -1,3 +0,0 @@
|
||||
<article>
|
||||
<h1>This page does not exist!</h1>
|
||||
</article>
|
||||
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
if(UserSession::isUserSignedIn()){
|
||||
include("./view/pagecontent/login/content_login_succesful.php");
|
||||
}else{
|
||||
include("./view/pagecontent/login/content_login_unsuccesful.php");
|
||||
}
|
||||
?>
|
||||
@ -1,3 +0,0 @@
|
||||
<article>
|
||||
<h1>You've been succesfully logged out</h1>
|
||||
</article>
|
||||
@ -1,3 +0,0 @@
|
||||
<article>
|
||||
<h1>Successfully registered!</h1>
|
||||
</article>
|
||||
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
?>
|
||||
@ -1,3 +0,0 @@
|
||||
<article>
|
||||
<h1>You're still signed in thanks to our cookies!</h1>
|
||||
</article>
|
||||
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
if(UserSession::isUserSignedIn()){
|
||||
include("./view/pagecontent/header/content_header_signedin.php");
|
||||
}else{
|
||||
include("./view/pagecontent/header/content_header_signedout.php");
|
||||
}
|
||||
?>
|
||||
@ -1,3 +0,0 @@
|
||||
<article>
|
||||
<h1>Welkom op hForumPHP. Log in of registreer om iets te doen.</h1>
|
||||
</article>
|
||||
@ -1,11 +0,0 @@
|
||||
<article>
|
||||
<form action="?p=showtopics" method="post">
|
||||
E-mail: <input type="text" name="email"><br>
|
||||
Password: <input type="password" name="password"><br>
|
||||
<input type="hidden" name="p" value="do_login" />
|
||||
<input type="submit">
|
||||
</form>
|
||||
</article>
|
||||
<?php
|
||||
|
||||
?>
|
||||
@ -1,35 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>
|
||||
<?=HUtils::getSiteTitle();?>
|
||||
</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="./view/css/main.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<?php
|
||||
include_once("./view/pagecontent/content_header.php");
|
||||
?>
|
||||
</header>
|
||||
<main>
|
||||
<?php
|
||||
//Store de geselecteerde pagina in variabele $page
|
||||
$page=HUtils::getPage(HUtils::FETCHGET);
|
||||
//Laad de juiste view
|
||||
$path = "./view/pagecontent/content_".$page.".php";
|
||||
if($page != ""){
|
||||
if(file_exists($path)){
|
||||
include_once($path);
|
||||
}
|
||||
else{
|
||||
include_once("./view/pagecontent/content_404.php");
|
||||
}
|
||||
}
|
||||
?>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,12 +0,0 @@
|
||||
<script type="text/javascript" src="./view/js/checkform.js"></script>
|
||||
<article>
|
||||
<form action="?p=attempt_register" method="post">
|
||||
Username: <input type="text" name="name" id="name" onkeyup="checkInputs()"><br>
|
||||
E-mail: <input type="text" name="email" id="email" onkeyup="checkInputs()"><br>
|
||||
Password: <input type="password" name="pass" id="pass" onkeyup="checkInputs()"><br>
|
||||
Verify Password: <input type="password" name="pass2" id="pass2" onkeyup="checkInputs()"><br>
|
||||
<input type="hidden" name="p" value="do_register" />
|
||||
<input type="submit" id="submitButton" disabled>
|
||||
</form>
|
||||
<div id="jsSignupAlert"></div>
|
||||
</article>
|
||||
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
if(UserSession::isUserSignedIn()){
|
||||
echo "LIST OF BOARDS LMAO";
|
||||
}
|
||||
else{
|
||||
echo "You must be signed in to view this page.";
|
||||
}
|
||||
?>
|
||||
@ -1,17 +0,0 @@
|
||||
<h1>TOPICS:</h1>
|
||||
<?php
|
||||
//Gedeeltelijk dummy code omdat de database nog niet zo ver is. Verder al wel functioneel. Gebrukersnamen worden ingeladen.
|
||||
if(UserSession::isUserSignedIn()){
|
||||
//$topics = Database::GetTopicList();
|
||||
$topics = [ [0, "Hoeveel ICTers heb je nodig om een forum te bouwen?", 2],
|
||||
[1, "LOREM IPSUM DOLOR", 3]];
|
||||
for($i = 0; $i < sizeof($topics); $i++){
|
||||
echo '<a href="?p=showthread&topic='.$i.'">'.$topics[$i][1].'</a> - Gestart door: '.Database::getUsername($topics[$i][2]);
|
||||
echo '<br>';
|
||||
|
||||
}
|
||||
//test
|
||||
//echo('aaa');
|
||||
}
|
||||
|
||||
?>
|
||||
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
if(isset($completed)){
|
||||
echo("account activated!");
|
||||
}
|
||||
else{
|
||||
echo("account activation went wrong!
|
||||
<br> Go here: <a href='?p=resend_email'>Resend email verification</a>
|
||||
<br>
|
||||
|
||||
");
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
include_once("./controller/AssetHandler.php");
|
||||
AssetHandler::printAsset("logo.png", true, 128);
|
||||
?>
|
||||
<nav>
|
||||
<a href="?action=signout">log out</a> <a href="?p=">home</a> <a href="?p=create_topic">create thread</a> <a href="?action=destroy">simulate $_SESSION expiry</a>
|
||||
</nav>
|
||||
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
include_once("./controller/AssetHandler.php");
|
||||
AssetHandler::printAsset("logo.png", true, 128);
|
||||
?>
|
||||
<nav>
|
||||
<a href="?p=login">log in</a> <a href="?p=register">register</a> <a href="?p=">home</a>
|
||||
</nav>
|
||||
@ -1,3 +0,0 @@
|
||||
<article>
|
||||
<h1>Successfully logged in!</h1>
|
||||
</article>
|
||||
@ -1,3 +0,0 @@
|
||||
<article>
|
||||
<h1>UNEXPECTED LOGIN ERROR. OUR CODEMONKEYS DID SOMETHING VERY WRONG :(</h1>
|
||||
</article>
|
||||
@ -1,8 +0,0 @@
|
||||
<div>
|
||||
<form action="" method="post">
|
||||
E-mail: <input type="text" name="email">
|
||||
Password: <input type="password" name="password">
|
||||
<input type="hidden" name="p" value="do_login"/>
|
||||
<input type="submit">
|
||||
</form>
|
||||
</div>
|
||||
6
dev_mvc/view/webcontent/content_404.php
Normal file
6
dev_mvc/view/webcontent/content_404.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
<h1>
|
||||
404
|
||||
</h1>
|
||||
5
dev_mvc/view/webcontent/content_account_inactive.php
Normal file
5
dev_mvc/view/webcontent/content_account_inactive.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
?>
|
||||
<h1>
|
||||
Your account appears to be inactive. Check your email for the verification mail.
|
||||
</h1>
|
||||
7
dev_mvc/view/webcontent/content_boards.php
Normal file
7
dev_mvc/view/webcontent/content_boards.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
require_once './model/forum/Thread.php';
|
||||
require_once './model/forum/User.php';
|
||||
foreach (MVCController::$viewData['boards'] as $board){
|
||||
include './view/webcontent/modules/modules_boards/module_boardtable.php';
|
||||
}
|
||||
?>
|
||||
6
dev_mvc/view/webcontent/content_createreply.php
Normal file
6
dev_mvc/view/webcontent/content_createreply.php
Normal file
@ -0,0 +1,6 @@
|
||||
<form action="./?p=showthread&thread=<?=MVCController::$viewData['threadid'];?>" method="post">
|
||||
<textarea placeholder="post content" name="content"></textarea><br>
|
||||
<input type="submit" value="Create Reply">
|
||||
<input type="hidden" name="thread" value="<?=MVCController::$viewData['threadid'];?>">
|
||||
<input type="hidden" name="action" value="create_reply">
|
||||
</form>
|
||||
7
dev_mvc/view/webcontent/content_createthread.php
Normal file
7
dev_mvc/view/webcontent/content_createthread.php
Normal file
@ -0,0 +1,7 @@
|
||||
<form action="./" method="post">
|
||||
<input type="text" placeholder="Title" name="title"><br>
|
||||
<textarea placeholder="post content" name="content"></textarea><br>
|
||||
<input type="submit" value="Create Thread">
|
||||
<input type="hidden" name="board" value="<?= isset($_GET['board']) ? $_GET['board'] : "-1" ?>">
|
||||
<input type="hidden" name="action" value="create_thread">
|
||||
</form>
|
||||
4
dev_mvc/view/webcontent/content_error_login.php
Normal file
4
dev_mvc/view/webcontent/content_error_login.php
Normal file
@ -0,0 +1,4 @@
|
||||
Incorrect Email or Password.
|
||||
<?php
|
||||
include_once('./view/webcontent/content_signin.php');
|
||||
?>
|
||||
9
dev_mvc/view/webcontent/content_header.php
Normal file
9
dev_mvc/view/webcontent/content_header.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
require_once('./controller/UserSession.php');
|
||||
if(UserSession::isUserSignedIn()){
|
||||
include('./view/webcontent/header/header_signedin.php');
|
||||
}
|
||||
else{
|
||||
include('./view/webcontent/header/header_signedout.php');
|
||||
}
|
||||
?>
|
||||
3
dev_mvc/view/webcontent/content_home.php
Normal file
3
dev_mvc/view/webcontent/content_home.php
Normal file
@ -0,0 +1,3 @@
|
||||
<h1>
|
||||
Please sign in to access our forum
|
||||
</h1>
|
||||
12
dev_mvc/view/webcontent/content_register.php
Normal file
12
dev_mvc/view/webcontent/content_register.php
Normal file
@ -0,0 +1,12 @@
|
||||
<script type="text/javascript" src="./view/js/checkform.js"></script>
|
||||
<article>
|
||||
<form action="?p=attempt_register" method="post">
|
||||
<input type="text" name="name" id="name" placeholder="Username" onkeyup="checkInputs()"><br>
|
||||
<input type="text" name="email" id="email" placeholder="E-mail" onkeyup="checkInputs()"><br>
|
||||
<input type="password" name="pass" id="pass" placeholder="Password" onkeyup="checkInputs()"><br>
|
||||
<input type="password" name="pass2" id="pass2" placeholder="Verify Password" onkeyup="checkInputs()"><br>
|
||||
<input type="hidden" name="action" value="do_register" />
|
||||
<input type="submit" id="submitButton" disabled>
|
||||
</form>
|
||||
<div id="jsSignupAlert"></div>
|
||||
</article>
|
||||
1
dev_mvc/view/webcontent/content_reply.php
Normal file
1
dev_mvc/view/webcontent/content_reply.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
||||
45
dev_mvc/view/webcontent/content_showthread.php
Normal file
45
dev_mvc/view/webcontent/content_showthread.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
require_once './model/forum/Thread.php';
|
||||
require_once './model/forum/Reply.php';
|
||||
require_once './model/forum/User.php';
|
||||
//$thread = new Thread();
|
||||
$thread = MVCController::$viewData['thread'];
|
||||
$replies = $thread->getReplies();
|
||||
?>
|
||||
<table>
|
||||
<h1>
|
||||
<?=$thread->getTitle()?>
|
||||
</h1>
|
||||
<tr>
|
||||
<th width="10%">user</th>
|
||||
<th width="80%">content</th>
|
||||
<th width="10%">date</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?=$thread->getOwner()->getUsername();?>
|
||||
</td>
|
||||
<td>
|
||||
<?=$thread->getContent()?>
|
||||
</td>
|
||||
<td>
|
||||
<?=$thread->getDate_created()->format("Y M d H:i:s")?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($replies as $reply){
|
||||
$owner = $reply->getOwner()->getUsername();
|
||||
$content = $reply->getContent();
|
||||
$date_created = $reply->getDate()->format("Y M d H:i:s");
|
||||
echo("<tr>");
|
||||
echo("<td>$owner</td>");
|
||||
echo("<td>$content</td>");
|
||||
echo("<td>$date_created</td>");
|
||||
echo("</tr>");
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php
|
||||
$threadID = $thread->getId();
|
||||
echo "<a href=\"?p=createreply&thread=$threadID\">Create Reply</a>"
|
||||
?>
|
||||
6
dev_mvc/view/webcontent/content_signin.php
Normal file
6
dev_mvc/view/webcontent/content_signin.php
Normal file
@ -0,0 +1,6 @@
|
||||
<form action="./" method="post">
|
||||
<input type="text" placeholder="Email" name="email"><br>
|
||||
<input type="password" placeholder="password" name="password"><br>
|
||||
<input type="submit" value="Sign in">
|
||||
<input type="hidden" name="action" value="login">
|
||||
</form>
|
||||
1
dev_mvc/view/webcontent/content_signout.php
Normal file
1
dev_mvc/view/webcontent/content_signout.php
Normal file
@ -0,0 +1 @@
|
||||
Signed out succesfully!
|
||||
2
dev_mvc/view/webcontent/content_verify.php
Normal file
2
dev_mvc/view/webcontent/content_verify.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo("questionmark");
|
||||
7
dev_mvc/view/webcontent/header/header_signedin.php
Normal file
7
dev_mvc/view/webcontent/header/header_signedin.php
Normal file
@ -0,0 +1,7 @@
|
||||
<div class="logo">
|
||||
hF
|
||||
</div>
|
||||
<nav>
|
||||
<a href="./">Home</a>
|
||||
<a href="?action=signout">Sign out</a>
|
||||
</nav>
|
||||
8
dev_mvc/view/webcontent/header/header_signedout.php
Normal file
8
dev_mvc/view/webcontent/header/header_signedout.php
Normal file
@ -0,0 +1,8 @@
|
||||
<div class="logo">
|
||||
hF
|
||||
</div>
|
||||
<nav>
|
||||
<a href="./">Home</a>
|
||||
<a href="?p=register">Register</a>
|
||||
<a href="?p=signin">Sign in</a>
|
||||
</nav>
|
||||
@ -0,0 +1,48 @@
|
||||
<h2><?=$board->name?></h2>
|
||||
<a href="?p=createthread&board=<?=$board->id?>">Create Thread</a>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Thread</th>
|
||||
<th width=10%>Started by</th>
|
||||
<th width=15%>Last reply</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach (MVCController::$viewData['threads'] as $thread){
|
||||
if($thread->getBoardID() == $board->id){
|
||||
$currentRow = [];
|
||||
$currentRow['threadID'] = $thread->getID();
|
||||
$currentRow['threadTitle'] = $thread->getTitle();
|
||||
foreach(MVCController::$viewData['users'] as $user){
|
||||
if($user->getID() == $thread->getUserID()){
|
||||
$currentRow['username'] = $user->getUsername();
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach(MVCController::$viewData['replies'] as $reply){
|
||||
if(isset($reply)){
|
||||
if($reply->getThreadID() == $thread->getId())
|
||||
{
|
||||
break;
|
||||
}else{
|
||||
$currentRow['lastUpdated'] = $thread->getDate_created()->format("Y M d H:i:s");
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="?p=showthread&thread=<?=$currentRow['threadID']?>"><?=$currentRow['threadTitle']?></a>
|
||||
</td>
|
||||
<td>
|
||||
<?=$currentRow['username'] ?>
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<?=$currentRow['lastUpdated']?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
47
dev_mvc/viewmodel/viewmodel_boards.php
Normal file
47
dev_mvc/viewmodel/viewmodel_boards.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
require_once './controller/db/DBBoard.php';
|
||||
require_once './controller/db/DBThread.php';
|
||||
require_once './controller/db/DBUser.php';
|
||||
require_once './model/forum/Board.php';
|
||||
require_once './model/forum/Thread.php';
|
||||
require_once './model/forum/User.php';
|
||||
require_once './model/forum/Reply.php';
|
||||
|
||||
$boardTable = DBBoard::getBoards();
|
||||
$threadsTable = [];
|
||||
$usersTable = [];
|
||||
$boards = [];
|
||||
$threads = [];
|
||||
$users = [];
|
||||
foreach ($boardTable as $row)
|
||||
{
|
||||
$threadsTable = array_merge($threadsTable, DBThread::getThreadsByBoard($row['ID']));
|
||||
array_push($boards, new Board($row['ID'], $row['name'], $row['permLevel']));
|
||||
}
|
||||
foreach($threadsTable as $row)
|
||||
{
|
||||
|
||||
array_push($threads, new Thread($row['ID'],$row['users_ID'],$row['board_ID'],$row['title'],$row['text'],$row['date_created']));
|
||||
array_push($usersTable, DBUser::getUserByUID($row['users_ID']));
|
||||
|
||||
}
|
||||
foreach($usersTable as $row){
|
||||
$skipUser = false;
|
||||
foreach($users as $user){
|
||||
if($row['ID'] == $user->getId()){
|
||||
$skipUser = true;
|
||||
}
|
||||
}
|
||||
if(!$skipUser){
|
||||
array_push($users, new User($row['ID'], $row['username'], $row['email'], $row['password'], $row['reg_date'], $row['login_date'], $row['reg_ip'], $row['permissions']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//MVCController::$viewData['boards'] = [new Board(0, "General", 0),new Board(1, "Admin board", 10)];
|
||||
MVCController::$viewData['boards'] = $boards;
|
||||
MVCController::$viewData['threads'] = $threads;
|
||||
MVCController::$viewData['users'] = $users;
|
||||
MVCController::$viewData['replies'] = [new Reply(0, 0, 0, "op is gay","01-01-1990")];
|
||||
?>
|
||||
5
dev_mvc/viewmodel/viewmodel_createreply.php
Normal file
5
dev_mvc/viewmodel/viewmodel_createreply.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
if(isset($_GET['thread'])){
|
||||
MVCController::$viewData['threadid'] = $_GET['thread'];
|
||||
}
|
||||
?>
|
||||
6
dev_mvc/viewmodel/viewmodel_home.php
Normal file
6
dev_mvc/viewmodel/viewmodel_home.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
require_once './controller/UserSession.php';
|
||||
require_once './controller/MVCController.php';
|
||||
if(UserSession::isUserSignedIn()){
|
||||
MVCController::getMVCController()->overrideView("boards");
|
||||
}
|
||||
37
dev_mvc/viewmodel/viewmodel_showthread.php
Normal file
37
dev_mvc/viewmodel/viewmodel_showthread.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once './controller/db/DBThread.php';
|
||||
require_once './controller/db/DBReply.php';
|
||||
require_once './controller/db/DBUser.php';
|
||||
require_once './model/forum/User.php';
|
||||
require_once './model/forum/Reply.php';
|
||||
if(isset($_GET['thread'])) {
|
||||
$threadid = $_GET['thread'];
|
||||
} else {
|
||||
$threadid = - 1;
|
||||
}
|
||||
// Get what we need from the database
|
||||
$threadData = DBThread::getThreadByID($threadid);
|
||||
$thread = new Thread($threadData['ID'], $threadData['users_ID'], $threadData['board_ID'], $threadData['title'], $threadData['text'], $threadData['date_created']);
|
||||
$replyData = DBReply::getRepliesByThreadID($threadid);
|
||||
// array to store our reply objects in
|
||||
$replies = [ ];
|
||||
// create reply objects from database rows
|
||||
foreach ($replyData as $row) {
|
||||
$reply = new Reply($row['ID'], $row['thread_ID'], $row['users_ID'], $row['content'], $row['date_created']);
|
||||
array_push($replies, $reply);
|
||||
$replyOwnerData = DBUser::getUserByUID($reply->getUserID());
|
||||
$replyOwner = new User($replyOwnerData['ID'], $replyOwnerData['username'], $replyOwnerData['email'], $replyOwnerData['password'], $replyOwnerData['reg_date'], $replyOwnerData['login_date'], $replyOwnerData['reg_ip'], $replyOwnerData['permissions']);
|
||||
$reply->setOwner($replyOwner);
|
||||
}
|
||||
|
||||
// get the person who started the thread
|
||||
$threadOwnerData = DBUser::getUserByUID($thread->getUserID());
|
||||
// create user object
|
||||
$threadOwner = new User($threadOwnerData['ID'], $threadOwnerData['username'], $threadOwnerData['email'], $threadOwnerData['password'], $threadOwnerData['reg_date'], $threadOwnerData['login_date'], $threadOwnerData['reg_ip'], $threadOwnerData['permissions']);
|
||||
// assign owner and replies
|
||||
$thread->setReplies($replies);
|
||||
$thread->setOwner($threadOwner);
|
||||
|
||||
// Store data so it can be used in the view
|
||||
MVCController::$viewData['thread'] = $thread;
|
||||
?>
|
||||
5
dev_mvc/viewmodel/viewmodel_signout.php
Normal file
5
dev_mvc/viewmodel/viewmodel_signout.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
require_once('./controller/db/Database.php');
|
||||
Database::invalidateSession($_COOKIE['usersession']);
|
||||
session_destroy();
|
||||
?>
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
include_once("./controller/Database.php");
|
||||
require_once './controller/db/Database.php';
|
||||
require_once './controller/db/DBUser.php';
|
||||
$key = '';
|
||||
if(isset($_GET['key'])){
|
||||
$key = $_GET['key'];
|
||||
@ -1,4 +0,0 @@
|
||||
<?php
|
||||
$sSiteTitle = "hPHPForum alpha 1.0";
|
||||
$p = "";
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user