This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
executable file
·86 lines (79 loc) · 2.11 KB
/
login.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
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST') die();
header('Content-Type: application/json');
require_once 'autoload.php';
set_exception_handler('sendExeptionJson');
session_start();
if (empty($_POST['method'])) {
throw new Exception('Geen methode meegegeven', 400);
}
// Controleer of velden zijn meegegeven behorende bij de methode, en roep juiste handler op
switch ($_POST['method']) {
case 'invitecode':
helpers\validator::validatePOST(['invitecode']);
handleInvitecode();
break;
case 'login':
helpers\validator::validatePOST(['username', 'password']);
handleLogin();
break;
case 'register':
helpers\validator::validatePOST(['username', 'password', 'password2', 'email']);
handleRegister();
break;
case 'logout':
handleLogout();
break;
default:
throw new Exception('Onbekende methode', 400);
}
/**
* handleLogin
* Haal opgegeven gebruiker op en zet, indien gevonden, username in sessie
*
* @return void
*/
function handleLogin()
{
$user = objects\User::login($_POST['username'], $_POST['password']);
$_SESSION['weddingID'] = null;
$_SESSION['username'] = $user->username;
helpers\successHandler::sendJSON();
}
/**
* handleRegister
* Registreer opgegeven gebruiker, en zet indien aangemaakt, username in sessie
*
* @return void
*/
function handleRegister()
{
$user = objects\User::createUser($_POST['username'], $_POST['password'], $_POST['password2'], $_POST['email']);
$_SESSION['weddingID'] = null;
$_SESSION['username'] = $user->username;
helpers\successHandler::sendJSON();
}
/**
* handleInvitecode
* Controleer wedding code en zet indien gevonden, weddingID in sessie
*
* @return void
*/
function handleInvitecode()
{
$wedding = objects\Wedding::validateWeddingCode($_POST['invitecode']);
$_SESSION['username'] = null;
$_SESSION['weddingID'] = $wedding->id;
helpers\successHandler::sendJSON();
}
/**
* handleLogout
*
* @return void
*/
function handleLogout()
{
$_SESSION = array();
session_destroy();
helpers\successHandler::sendJSON();
}