-
Notifications
You must be signed in to change notification settings - Fork 1
/
middleware-account-settings.php
63 lines (55 loc) · 2.01 KB
/
middleware-account-settings.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
<?php
require_once "./app/core/Handle.php";
require_once "./app/models/Accounts.php";
session_start();
header('Content-type: application/json');
$response_array = [];
Handle::authentication("account", Popups::mustBeAuthenticated(), "login.php");
Handle::requiredParameters([$_POST['id'], $_POST['value']], Popups::requiredField(), "settings.php");
if(empty($_POST['id']) || empty($_POST['value']) || empty($_SESSION['account'])) {
if(empty($_POST['value']) && isset($_POST['id'])) {
switch($_POST['id']) {
case 'firstName':
$response_array['oldValue'] = $_SESSION['account']->first_name;
break;
case 'lastName':
$response_array['oldValue'] = $_SESSION['account']->last_name;
break;
case 'city':
$response_array['oldValue'] = $_SESSION['account']->city;
break;
case 'dob':
$response_array['oldValue'] = $_SESSION['account']->birth_date;
break;
case 'phone':
$response_array['oldValue'] = $_SESSION['account']->phone;
break;
}
$response_array['status'] = 'empty';
} else{
$response_array['status'] = 'error';
}
} else {
$accountID = $_SESSION['account']->account_id;
switch($_POST['id']) {
case 'firstName':
Accounts::updateFirstName($accountID, $_POST['value']);
break;
case 'lastName':
Accounts::updateLastName($accountID, $_POST['value']);
break;
case 'city':
Accounts::updateCity($accountID, $_POST['value']);
break;
case 'dob':
Accounts::updateBirthday($accountID, $_POST['value']);
break;
case 'phone':
Accounts::updatePhone($accountID, $_POST['value']);
break;
}
$response_array['status'] = 'success';
$_SESSION['account'] = Accounts::getAccountViaID($accountID);
}
echo json_encode($response_array);
?>