This repository was archived by the owner on Dec 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
124 lines (105 loc) · 5.86 KB
/
index.php
File metadata and controls
124 lines (105 loc) · 5.86 KB
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
<?php
/*
* The KANE Project
* A PHP based web application for Rental Listings and Property Management
* T177 - Winter 2024 - Capstone Team 04
* Please email info@kaneproject.ca if you have any questions about this project.
*/
// index.php
// This is the main entry point for the application.
// It is responsible for routing requests to the appropriate page.
// It uses the FastRoute library to define routes and dispatch requests to the appropriate page.
require 'vendor/autoload.php';
use FastRoute\RouteCollector;
use function FastRoute\simpleDispatcher;
$dispatcher = simpleDispatcher(function (RouteCollector $r)
{
// Client (Public) Routes
$r->addRoute('GET', '[/]', '/client/home.php');
$r->addRoute('GET', '/listings[/]', '/client/listings.php');
$r->addRoute('POST', '/listings[/]', '/client/listings.php');
$r->addRoute('GET', '/listing/{slug}[/]', '/client/viewlisting.php');
$r->addRoute('POST', '/listing/{slug}[/]', '/client/viewlisting.php');
$r->addRoute('GET', '/about[/]', '/client/about.php');
$r->addRoute('GET', '/contact[/]', '/client/contact.php');
$r->addRoute('POST', '/contact[/]', '/client/contact.php');
$r->addRoute('GET', '/pricing[/]', '/client/pricing.php');
$r->addRoute('GET', '/account[/]', '/client/account.php');
$r->addRoute('POST', '/account[/]', '/client/account.php');
$r->addRoute('GET', '/account/login[/]', '/client/login.php');
$r->addRoute('POST', '/account/login[/]', '/client/login.php');
$r->addRoute('GET', '/account/register[/]', '/client/register.php');
$r->addRoute('POST', '/account/register[/]', '/client/register.php');
$r->addRoute('GET', '/account/messages[/]', '/client/messages.php');
$r->addRoute('POST', '/account/messages[/]', '/client/messages.php');
$r->addRoute('GET', '/account/logout[/]', '/client/logout.php');
$r->addRoute('POST', '/account/delete[/]', '/client/cleandelete.php');
$r->addRoute('GET', '/account/message/{slug}[/]', '/client/viewchat.php');
$r->addRoute('POST', '/account/message/{slug}[/]', '/client/viewchat.php');
$r->addRoute('GET', '/safety[/]', '/client/safety.php');
$r->addRoute('GET', '/legal/{slug}[/]', '/client/legal.php');
$r->addRoute('GET', '/verify-email/{uid}[/]', '/client/verify.php');
$r->addRoute('GET', '/resend-email/{suid}[/]', '/client/resend.php');
$r->addRoute('GET', '/reset-password[/]', '/client/reset.php');
$r->addRoute('POST', '/reset-password[/]', '/client/reset.php');
$r->addRoute('GET', '/reset/{resetid}[/]', '/client/processReset.php');
$r->addRoute('POST', '/reset/{resetid}[/]', '/client/processReset.php');
// Landlord Portal Routes
$r->addRoute('GET', '/portal[/]', '/portal/dashboard.php');
$r->addRoute('GET', '/portal/login[/]', '/portal/login.php');
$r->addRoute('POST', '/portal/login[/]', '/portal/login.php');
$r->addRoute('GET', '/portal/register[/]', '/portal/register.php');
$r->addRoute('POST', '/portal/register[/]', '/portal/register.php');
$r->addRoute('GET', '/portal/logout[/]', '/portal/logout.php');
$r->addRoute('GET', '/portal/new[/]', '/portal/addlisting.php');
$r->addRoute('POST', '/portal/new[/]', '/portal/addlisting.php');
$r->addRoute('GET', '/portal/listings[/]', '/portal/mylistings.php');
$r->addRoute('GET', '/portal/listing/{id}[/]', '/portal/listingview.php');
$r->addRoute('POST', '/portal/listing/{id}[/]', '/portal/listingview.php');
$r->addRoute('GET', '/portal/delete-listing/{id}[/]', '/portal/deletelisting.php');
$r->addRoute('POST', '/portal/delete-account[/]', '/portal/cleandelete.php');
$r->addRoute('GET', '/portal/messages[/]', '/portal/messages.php');
$r->addRoute('GET', '/portal/message/{slug}[/]', '/portal/messageview.php');
$r->addRoute('POST', '/portal/message/{slug}[/]', '/portal/messageview.php');
$r->addRoute('GET', '/portal/settings[/]', '/portal/settings.php');
$r->addRoute('POST', '/portal/settings[/]', '/portal/settings.php');
$r->addRoute('GET', '/portal/view-stats/{listingid}[/]', '/portal/viewstats.php');
$r->addRoute('GET', '/portal/verify-email/{uid}[/]', '/portal/verify.php');
$r->addRoute('GET', '/portal/resend-email/{suid}[/]', '/portal/resend.php');
$r->addRoute('GET', '/portal/reset-password[/]', '/portal/reset.php');
$r->addRoute('POST', '/portal/reset-password[/]', '/portal/reset.php');
$r->addRoute('GET', '/portal/reset/{resetid}[/]', '/portal/processReset.php');
$r->addRoute('POST', '/portal/reset/{resetid}[/]', '/portal/processReset.php');
// Site Admin Routes
$r->addRoute('GET', '/admin[/]', '/admin/dashboard.php');
$r->addRoute('GET', '/admin/login[/]', '/admin/login.php');
$r->addRoute('GET', '/admin/users[/]', '/admin/users.php');
$r->addRoute('GET', '/admin/user/{id}[/]', '/admin/viewuser.php');
$r->addRoute('GET', '/admin/listings[/]', '/admin/listings.php');
$r->addRoute('GET', '/admin/viewlisting/{id}[/]', '/admin/viewlisting.php');
$r->addRoute('GET', '/admin/reports[/]', '/admin/reports.php');
$r->addRoute('GET', '/admin/report/{id}[/]', '/admin/viewreport.php');
$r->addRoute('GET', '/admin/logout[/]', '/admin/logout.php');
});
$httpMethod = $_SERVER['REQUEST_METHOD'];
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$routeInfo = $dispatcher->dispatch($httpMethod, $uri);
switch ($routeInfo[0])
{
case \FastRoute\Dispatcher::FOUND:
$page = $routeInfo[1];
$vars = $routeInfo[2];
foreach ($vars as $varName => $varValue) {
${$varName} = $varValue;
}
include(__DIR__ . '/public' . $page);
break;
case \FastRoute\Dispatcher::NOT_FOUND:
http_response_code(404);
include(__DIR__ . '/public' . '/404.php');
break;
case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
http_response_code(405);
echo '<pre>405 Method Not Allowed</pre>';
break;
}