/
user_registration.php
44 lines (42 loc) · 1.48 KB
/
user_registration.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
<?php
define ( "NO_SESSION_REGENERATION", true );
require_once (__DIR__ . "/config.php");
require_once (TEMPLATES_PATH . "/utils.php");
require_once (INCLUDES_PATH . "/authentication.php");
require_once (INCLUDES_PATH . "/events.php");
require_once (DATABASE_PATH . "/events.php");
try {
if (!isset ($_GET ["idEvent"])) {
http_response_code(400);
echo 'Missing event ID.';
} else if (!isset ($_GET ["action"])) {
http_response_code(400);
echo 'Missing action value.';
} else if (!isUserLoggedIn()) {
http_response_code(403);
echo 'You need to login to edit this event.';
} else if (! validateCSRFToken ( rawurldecode($_GET ["csrf_token"]) )) {
http_response_code ( 403 );
echo 'Invalid CSRF token.';
}else {
$event_id = $_GET ["idEvent"];
$user_id = getUserID();
$register = $_GET ["action"];
if (!canSeeEvent($user_id, $event_id)) {
http_response_code(403);
echo 'You do not have access to this event.';
} else {
if($register) {
registerInEvent($user_id, $event_id);
} else {
unregisterFromEvent($user_id, $event_id);
}
header("Location: view_event.php?id=" . $event_id);
}
}
} catch ( InvalidArgumentException $e ) {
http_response_code ( 400 );
echo $e->getMessage ();
} catch ( Exception $e ) {
http_response_code ( 500 );
}