changed files to more updated version
This commit is contained in:
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,12 +0,0 @@
|
||||
<?php
|
||||
include_once("./controller/Database.php");
|
||||
$key = '';
|
||||
if(isset($_GET['key'])){
|
||||
$key = $_GET['key'];
|
||||
}
|
||||
|
||||
if(Database::doesUserActivationKeyExist($key)){
|
||||
Database::activateUser($key);
|
||||
}
|
||||
$completed = true;
|
||||
?>
|
||||
@@ -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
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user