This repository has been archived by the owner on Jun 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.php
116 lines (73 loc) · 2.72 KB
/
controller.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
<?php
if (!isset($_POST['page'])) {
include('view_startpage.php');
exit();
}
session_start();
require('model.php');
if ($_POST['page'] == 'StartPage') {
if($_POST['command'] == 'Login') {
if (verify_user($_POST['login_username'], $_POST['login_password'])) {
$_SESSION['username'] = $_POST['login_username'];
include('view_mainpage.php');
} else {
$errorCode = 'wrong_credentials';
include('view_startpage.php');
}
exit();
} else if($_POST['command'] == 'Signup') {
if (verify_user_exists($_POST['signup_username'])) {
echo 'signup_exists';
} else {
if (signup_user($_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'])) {
echo 'signup_success';
}
else {
echo 'signup_error';
}
}
exit();
}
}
if ($_POST['page'] == 'MainPage') {
if($_POST['command'] == 'ReadPosts') {
echo json_encode(fetch_posts());
exit();
} else if($_POST['command'] == 'CreatePost') {
create_post($_SESSION['username'], $_POST['post-title'], $_POST['post-description']);
exit();
} else if($_POST['command'] == 'Logout') {
session_unset();
session_destroy();
include('view_startpage.php');
exit();
} else if($_POST['command'] == 'FetchEmailStatus') {
echo json_encode(fetch_email_status($_SESSION['username']));
exit();
} else if ($_POST['command'] == 'UpdateProfile') {
update_profile($_SESSION['username'], $_POST['profile-email'], $_POST['profile-status']);
exit();
} else if($_POST['command'] == 'CreateComment') {
create_comment($_SESSION['username'], $_POST['post-comment'], $_POST['post-id']);
exit();
} else if($_POST['command'] == 'ReadComments') {
echo json_encode(fetch_comments($_POST['post-id']));
exit();
} else if($_POST['command'] == 'LikePost') {
echo like_post($_SESSION['username'], $_POST['post-id']);
exit();
} else if($_POST['command'] == 'FetchLikeStatus') {
echo verify_post_liked($_SESSION['username'], $_POST['post-id']);
exit();
} else if($_POST['command'] == 'UnsubscribeUser') {
echo unsubscribe_user($_SESSION['username'], $_POST['post-user']);
exit();
} else if($_POST['command'] == 'DeletePost') {
delete_post($_POST['post-id']);
exit();
} else if($_POST['command'] == 'ReadUnsubscribedUsers') {
echo json_encode(fetch_unsubscribed_users($_SESSION['username']));
exit();
}
}
?>