-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
129 lines (112 loc) · 3.52 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
session_start();
require "vendor/autoload.php";
require "controllers/users.php";
require "controllers/posts.php";
$router = new AltoRouter();
$router->map('GET',"/Mysocial/",function()
{
require 'view/login.php';
});
$router->map('POST',"/Mysocial/",function()
{
$initController = new users();
if ( !empty($_POST["email"]) && !empty($_POST["password"])) {
$callController = $initController->check($_POST["email"],$_POST["password"]);
if($callController){
$_SESSION["email"] = $_POST["email"];
$_SESSION["password"] = $_POST["password"];
}
else {
$msg = "Wrong password or Email";
echo "<div class ='error'>".$msg."</div>";
}
}
else {
$msg = "Fill all input field";
echo "<div class ='error'>".$msg."</div>";
}
if ($_SESSION["email"] == $_POST["email"] && $_SESSION["password"] == $_POST["password"] ) {
header('location:/Mysocial/profile');
}
else {
require 'view/login.php';
}
});
$router->map('GET',"/Mysocial/Signin",function()
{
require 'view/signin.php';
});
$router->map('POST',"/Mysocial/Signin",function()
{
if (!empty($_POST["name"]) && !empty($_POST["fname"]) && !empty($_POST["email"]) && !empty($_POST["phone"]) && !empty($_POST["address"]) && !empty($_POST["password"]) && !empty($_POST["birth"]) && !empty($_POST["gender"])) {
function cleaner($value){
$value = htmlentities(strip_tags($value));
$value = trim($value);
$value = ucfirst(strtolower($value));
return $value;
}
$name = cleaner($_POST["name"]);
$fname = cleaner($_POST["fname"]);
$email = cleaner($_POST["email"]);
$phone = cleaner($_POST["phone"]);
$address = cleaner($_POST["address"]);
$password = htmlentities(md5($_POST["password"]));
$birth = cleaner($_POST["birth"]);
$gender = cleaner($_POST["gender"]);
$initController = new users();
if ($_POST["gender"] == "man") {
$picture = "assets/images/profile_pics/men-profile.png";
}
else {
$picture = "assets/images/profile_pics/woman-profile.jpg";
}
$callController = $initController->save($name, $fname,$email,$address,$phone,$gender,$birth,$password,$picture);
if($callController){
$_SESSION["email"] = $email;
$_SESSION["password"] = $password;
header('location:/Mysocial/profile');
}
else {
$msg = "We cannot save yet. Please retry after.";
require 'view/signin.php';
echo "<div class ='error'>".$msg."</div>";
}
}
else {
$msg = "Please, fill all input.";
require 'view/signin.php';
echo "<div class ='error'>".$msg."</div>";
}
});
$router->map('GET',"/Mysocial/profile",function()
{
require 'view/profile.php';
});
$router->map('POST',"/Mysocial/profile",function()
{
if (!empty($_POST["userpost"])) {
$postController = new posts();
$save = $postController->save($_POST["userpost"],$_SESSION["email"]);
require 'view/profile.php';
}
else {
header('Location:/Mysocial/profile');
die;
}
});
$router->map('GET',"/Mysocial/profile/deconnect",function()
{
unset($_SESSION["email"],$_SESSION["password"]);
header('Location:/Mysocial');
});
$match = $router->match();
if( is_array($match) && is_callable( $match['target'] ) )
{
call_user_func_array( $match['target'], $match['params'] );
}
else
{
// no route was matched
header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}