-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
101 lines (95 loc) · 3.05 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
session_start();
require_once "config/database.php";
require_once "config/site.php";
require_once "model/UserManager.php";
require_once "model/SessionManager.php";
require_once "model/PostManager.php";
require_once "model/SiteManager.php";
date_default_timezone_set("Europe/Paris");
/************* Managers init ************/
$title = "Camagru";
$content = "<h2>Welcome To Camagru</h2>";
try
{
$siteManager = new siteManager();
$userManager = new UserManager($DB_DSN, $DB_USER, $DB_PASSWORD,
$SITE_ADDRESS, $RESET_PASSWORD_TOKEN_VALIDITY);
$postManager = new PostManager($DB_DSN, $DB_USER, $DB_PASSWORD,
$SITE_ADDRESS, $RESET_PASSWORD_TOKEN_VALIDITY);
$sessionManager = new SessionManager($userManager);
}
catch (Exception $e)
{
$userManager = NULL;
$sessionManager = NULL;
$siteManager->strong_error_log($DB_ERROR);
$content = "";
}
if (!$sessionManager->is_logged_user_valid())
$sessionManager->log_out_user();
/************* Router ************/
if ($userManager != NULL && $sessionManager != NULL
&& isset($_GET) && isset($_GET["action"]))
{
switch($_GET["action"])
{
case 'login':
require 'controller/login.php';
break;
case 'logout':
$sessionManager->log_out_user();
header('location: index.php');
die();
case 'setup':
require 'config/setup.php';
break;
case 'signin':
require 'controller/signin.php';
break;
case 'verify':
if (isset($_GET["user"]) && isset($_GET["token"])
&& $userManager->verify_user($_GET["user"], $_GET["token"]))
$siteManager->success_log("Account activated");
else
$siteManager->error_log("Error wrong token/login");
break;
case 'reset':
require 'controller/password_reset.php';
break;
case 'account':
if ($sessionManager->is_logged_user_valid())
require 'controller/change_account.php';
else
require 'controller/login.php';
break;
case 'post':
if ($sessionManager->is_logged_user_valid())
require 'controller/post.php';
else
{
header('location: index.php?action=login');
die();
}
break;
case 'getUserPosts':
require 'controller/API_get_user_posts.php';
break;
case 'getFilters':
require 'controller/API_get_filters.php';
break;
case 'whoAmI':
require 'controller/API_who_am_i.php';
break;
case 'getAllPosts':
require 'controller/API_get_all_posts.php';
break;
case 'deletePost':
require 'controller/delete_post.php';
break;
default:
$content = "Error 404 : This page doesn't exists";
header('HTTP/1.1 404 Not Found');
}
}
require 'views/structure/template.php';