Skip to content

Commit

Permalink
starting mvc refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Razshal committed May 10, 2018
1 parent 6cf1f2e commit 146d384
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 45 deletions.
13 changes: 13 additions & 0 deletions controller/C_head.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
session_start();
include_once ($_SERVER["DOCUMENT_ROOT"] . "/model/get_database.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/config/database.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/controller/tools.php");

try {
if (isset($_SESSION) && isset($_SESSION["user"]) && $_SESSION["user"] != "")
if (empty(get_user($databasePDO, $_SESSION["user"])))
$_SESSION["user"] = "";
} catch (Exception $e) {
echo $databaseError;
}
15 changes: 15 additions & 0 deletions controller/C_signin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
include_once ($_SERVER["DOCUMENT_ROOT"] . "/model/checks.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/model/set_database.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/config/database.php");

if ($DB_ERROR === false && isset($_POST) && $_POST["submit"] === "Sign-in") {
$validMail = validNewMail($databasePDO, $_POST["mail"]);
$validPass = validNewPassword($_POST["password"]);
$validLogin = validNewLogin($databasePDO, $_POST["login"]);
if ($validMail && $validPass && $validLogin)
$querySuccess = newUser($databasePDO, $_POST["login"],
$_POST["mail"], $_POST["password"]);
}
else if (isset($_POST["submit"]))
$querySuccess = false;
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php include ("views/structure/head.php") ?>
<?php include ($_SERVER["DOCUMENT_ROOT"] . "/views/structure/head.php") ?>
<html lang="en">
<body>
<?php include ("views/structure/header.php") ?>
<?php include ($_SERVER["DOCUMENT_ROOT"] . "/views/structure/header.php") ?>
<main>
<h2>Welcome To Camagru</h2>
</main>
</body>
<?php include ("views/structure/footer.php") ?>
<?php include ($_SERVER["DOCUMENT_ROOT"] . "/views/structure/footer.php") ?>
</html>
5 changes: 3 additions & 2 deletions model/set_database.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

include_once ("/controller/tools.php");
include_once ("/config/site.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/controller/tools.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/config/site.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/config/site.php");

function sendUserCheckMail ($database, $login, $mail, $token) {
$token =
Expand Down
31 changes: 6 additions & 25 deletions views/signin.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
<?php
include_once ($_SERVER["DOCUMENT_ROOT"] . "/views/structure/head.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/model/checks.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/model/set_database.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/config/database.php");

$validMail = true;
$validPass = true;
$validLogin = true;
$querySuccess = 0;

if ($DB_ERROR === false && isset($_POST) && $_POST["submit"] === "Sign-in") {
$validMail = validNewMail($databasePDO, $_POST["mail"]);
$validPass = validNewPassword($_POST["password"]);
$validLogin = validNewLogin($databasePDO, $_POST["login"]);
if ($validMail && $validPass && $validLogin)
$querySuccess = newUser($databasePDO, $_POST["login"],
$_POST["mail"], $_POST["password"]);
}
else if (isset($_POST["submit"]))
$querySuccess = false;
?>
require_once ($_SERVER["DOCUMENT_ROOT"] . "/controller/C_signin.php"); ?>
<html lang="en">
<body>
<?php include("structure/header.php") ?>
Expand All @@ -28,17 +9,17 @@
<?php
if ($DB_ERROR !== false)
echo $DB_ERROR;
if (!$validMail)
if (isset($validMail) && !$validMail)
echo ("<h2 class='error'>Mail is already in use or not valid</h2>");
if (!$validLogin)
if (isset($validLogin) && !$validLogin)
echo ("<h2 class='error'>Login is already in use or not valid
(4 chars >= login <= 20 chars)</h2>");
if (!$validPass)
if (isset($validPass) && !$validPass)
echo ("<h2 class='error'>Password should be at least 8 chars and
contains at least one letter and one digit</h2>");
if ($querySuccess === false)
if (isset($querySuccess) && $querySuccess === false)
echo ("<h2 class='error'>Error during user creation, please retry</h2>");
else if ($querySuccess === true)
else if (isset($querySuccess) && $querySuccess === true)
echo ("<h2 class='success'>Account created</h2>");
?>
</div>
Expand Down
16 changes: 1 addition & 15 deletions views/structure/head.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
<?php
session_start();
include_once ($_SERVER["DOCUMENT_ROOT"] . "/model/get_database.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/config/database.php");
include_once ($_SERVER["DOCUMENT_ROOT"] . "/controller/tools.php");

try {
if (isset($_SESSION) && isset($_SESSION["user"]) && $_SESSION["user"] != "")
if (empty(get_user($databasePDO, $_SESSION["user"])))
$_SESSION["user"] = "";
} catch (Exception $e) {
echo $databaseError;
}

?>
<?php require_once ($_SERVER["DOCUMENT_ROOT"] . "/controller/C_head.php"); ?>
<!DOCTYPE html>
<html>
<head>
Expand Down

0 comments on commit 146d384

Please sign in to comment.