-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
174 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
USE camagru; | ||
DROP TABLE `like`; | ||
DROP TABLE comment; | ||
DROP TABLE post; | ||
DROP TABLE user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
<?php | ||
if ($database !== NULL) | ||
$success = $database->initiate(); | ||
if ($userManager !== NULL && $success = $userManager->initiate()) | ||
$info = $info . "<p class='success'>Website is ok</p><br>"; | ||
else | ||
$success = false; | ||
ob_start(); | ||
?> | ||
<div> | ||
<h2>Setup tried</h2> | ||
<?php | ||
if ($success === true) | ||
$info = $info . "<p class='success'>Website is ok</p>"; | ||
?> | ||
</div> | ||
<?php $content = ob_get_clean(); ?> | ||
$info = $info . "<p class='error'>Error during database init</p><br>"; | ||
$content = ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
<?php | ||
if (isset($_POST) && isset($_POST["mail"]) && isset($_POST["submit"]) | ||
&& $_POST["submit"] === "Reset" | ||
&& !empty($user = $database->get_mail($_POST["mail"]))) | ||
&& !empty($user = $userManager->get_mail($_POST["mail"]))) | ||
{ | ||
if ($database->initiatePasswordReset($_POST["mail"])) | ||
$done = "<h2 class='success'>Reset account mail sent</h2>"; | ||
if ($userManager->initiatePasswordReset($_POST["mail"])) | ||
$info = $info . "<h2 class='success'>Reset account mail sent</h2>"; | ||
else | ||
$done = "<h2 class='error'>Unable to send reset mail, | ||
$info = $info . "<h2 class='error'>Unable to send reset mail, | ||
check if your mail is valid</h2>"; | ||
require ($_SERVER["DOCUMENT_ROOT"] . "/views/ask_password_reset.php"); | ||
} | ||
else if (isset($_GET["token"]) && isset($_GET["mail"])) | ||
{ | ||
if (!empty($user = $database->get_mail($_GET["mail"])[0]) | ||
&& $user["check_token"] === $_GET["token"]) | ||
echo $_GET["token"] . "<br>"; | ||
if (!empty($user = $userManager->get_mail($_GET["mail"])) | ||
&& $user[0]["check_token"] === $_GET["token"]) | ||
{ | ||
var_dump($user["reset_date"]); | ||
require ($_SERVER["DOCUMENT_ROOT"] . "/views/chose_new_password.php"); | ||
} | ||
var_dump($user[0]["reset_date"]); | ||
} | ||
else | ||
require ($_SERVER["DOCUMENT_ROOT"] . "/views/ask_password_reset.php"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
class DatabaseManager | ||
{ | ||
protected $PDO = NULL; | ||
protected $SITE_ADDRESS = NULL; | ||
|
||
public function __construct($DB_DSN, $DB_USER, $DB_PASSWORD, $SITE_ADDRESS) | ||
{ | ||
try | ||
{ | ||
$this->PDO = new PDO($DB_DSN, $DB_USER, $DB_PASSWORD, | ||
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); | ||
$this->SITE_ADDRESS = $SITE_ADDRESS; | ||
} | ||
catch (Exception $exception) | ||
{ | ||
throw new Exception("Cannot connect to database"); | ||
} | ||
} | ||
|
||
public function initiate() | ||
{ | ||
try | ||
{ | ||
$this->PDO->exec(" | ||
CREATE TABLE IF NOT EXISTS user ( | ||
id INT NOT NULL AUTO_INCREMENT UNIQUE, | ||
login VARCHAR(20) NOT NULL, | ||
password VARCHAR(128), | ||
mail VARCHAR(254), | ||
check_token VARCHAR(128), | ||
reset_token VARCHAR(128), | ||
creation_date TIMESTAMP NOT NULL DEFAULT now(), | ||
reset_date TIMESTAMP, | ||
is_verified INT NOT NULL DEFAULT 0, | ||
PRIMARY KEY (id)) | ||
ENGINE = InnoDB;"); | ||
|
||
$this->PDO->exec(" | ||
CREATE TABLE IF NOT EXISTS post ( | ||
id INT NOT NULL AUTO_INCREMENT UNIQUE, | ||
user_id INT NOT NULL, | ||
image VARCHAR(100), | ||
description VARCHAR(256), | ||
post_date TIMESTAMP NOT NULL DEFAULT now(), | ||
PRIMARY KEY (id), | ||
CONSTRAINT fk_user_id | ||
FOREIGN KEY (user_id) | ||
REFERENCES user (id)) | ||
ENGINE = InnoDB;"); | ||
|
||
$this->PDO->exec(" | ||
CREATE TABLE IF NOT EXISTS comment ( | ||
id INT NOT NULL AUTO_INCREMENT UNIQUE, | ||
post_id INT NOT NULL, | ||
`text` VARCHAR(256) NOT NULL, | ||
comment_date TIMESTAMP NOT NULL DEFAULT now(), | ||
PRIMARY KEY (id), | ||
CONSTRAINT fk_post_id | ||
FOREIGN KEY (post_id) | ||
REFERENCES post (id)) | ||
ENGINE = InnoDB;"); | ||
|
||
$this->PDO->exec(" | ||
CREATE TABLE IF NOT EXISTS `like` ( | ||
post_id INT NOT NULL, | ||
user_id INT NOT NULL, | ||
CONSTRAINT fk_like_post_id FOREIGN KEY (post_id) REFERENCES post(id), | ||
CONSTRAINT fk_like_user_id FOREIGN KEY (user_id) REFERENCES user(id)) | ||
ENGINE = InnoDB; | ||
"); | ||
return true; | ||
} | ||
catch (Exception $e) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
protected function generate_random_token() | ||
{ | ||
return bin2hex(openssl_random_pseudo_bytes(16)); | ||
} | ||
} |
Oops, something went wrong.