-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccount.php
More file actions
309 lines (226 loc) · 10.8 KB
/
account.php
File metadata and controls
309 lines (226 loc) · 10.8 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
// Uit deze php bestanden gebruiken wij functies of variabelen:
include_once("app/authentication.php"); // Accounts en login
include_once("app/constants.php"); // wordt gebruikt voor website beschrijving
include_once("app/vendor.php"); // wordt gebruikt voor website beschrijving
include_once("app/database.php"); // wordt gebruikt voor database connectie
include_once("app/model/categorie.php"); // wordt gebruikt voor categorieen ophalen uit DB
include_once("app/model/account.php"); // wordt gebruikt voor database connectie
include_once("app/security/HashResult.php"); // wordt gebruikt voor database connectie
include_once("app/security/IHashMethod.php"); // Voor het hashen van wachtwoorden
include_once("app/security/StandardHashMethod.php"); // Voor het hashen van wachtwoorden
include_once("app/security/FormValidation.php"); // Ter controle van formulieren
include_once("app/field.php"); // voor field in array
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$email = Authentication::getEmail();
if (!Authentication::isLoggedIn() || $email == null) {
header("Location: index.php", true, 303);
die();
}
?>
<!doctype html>
<html class="no-js" lang="">
<head>
<?php
//Hier include je de head-tag-template, alles wat in de header komt pas je aan in "tpl/head-tag-template.php"
include("tpl/head-tag-template.php");
?>
</head>
<body>
<!-- Onze website werkt niet met Internet Explorer 9 en lager-->
<!--[if IE]>
<div id="warning" class="fixed-top"><p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience and security.</p></div>
<![endif]-->
<!-- Hierin -->
<div id="pagina-container">
<div>
<!-- Print de header (logo, navigatiebalken, etc.)-->
<?php
include("tpl/header_template.php");
?>
</div>
</div>
<div class="content-container-narrow">
<!-- Inhoud pagina -->
<h3>Account informatie</h3><br>
<p>Op deze pagina kunt u de gegevens wijzigen en inzien welke gelinkt zijn aan uw persoonlijke account.</p>
<div>
<?php
// Oproepen van de huidige gegevens die dan weer geprint zullen worden
$stmt = Account::get(Database::getConnection(), $email);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// Het account is verwijderd maar de sessie is nog niet geupdatet (dit komt bijna nooit voor)
if (!$row) {
Authentication::logout();
header("Location: index.php");
print('<meta http-equiv="refresh" content="0;index.php">
<script type="text/javascript">
window.location = "index.php";
</script>');
die("Ongecontroleerde fout opgetreden.");
}
extract($row);
if (IS_DEBUGGING_ENABLED) {
print_r($row);
print("<br><br>");
}
/**
* @var array string => Field[]
*/
$secties = array(
"Authenticatie" => [new Field("Huidige_wachtwoord", "password", "", null, true),
new Field("Nieuwe_wachtwoord", "password", "", null, true)],
"Naam" => [new Field("Voornaam", "text", "firstName", $FirstName, true),
new Field("Tussenvoegsel", "text", "middleName", $MiddleName, false),
new Field("Achternaam", "text", "lastName", $LastName, true)],
"Adres" => [new Field("Straatnaam", "text", "addrStreet", $AddressStreet, true),
new Field("Huisnummer", "text", "addrNumber", $AddressNumber, true),
new Field("Toevoeging", "text", "addrToevoeging", $AddressToevoeging, false),
new Field("Postcode", "text", "addrPostal", $AddressPostalCode, true),
new Field("Woonplaats", "text", "addrCity", $AddressCity, true)]
);
$changedValues = array();
// Check en update de values als ze gepost zijn.
foreach ($secties as $naam => $veldenArray) {
foreach ($veldenArray as $veld) {
if (isset($_POST[$veld->getNaam()]) && $_POST[$veld->getNaam()] != null && strlen($veld->getId()) > 0) {
$changedValues[$veld->getId()] = $_POST[$veld->getNaam()];
}
}
}
if (IS_DEBUGGING_ENABLED) {
var_dump($changedValues);
}
$nieuweWachtwoord = null;
if (isset($_POST["Huidige_wachtwoord"]) && isset($_POST["Nieuwe_wachtwoord"])) {
if (Authentication::login(Database::getConnection(), $email, strval($_POST["Huidige_wachtwoord"]))) {
$nieuweWachtwoord = strval($_POST["Nieuwe_wachtwoord"]);
$changedValues["new_pass"] = true;
}
}
if (isset($_POST["csrf_token"]) && hash_equals($csrf_token, $_POST["csrf_token"])) {
if (count($changedValues) > 0) {
Account::update(Database::getConnection(), $email, $nieuweWachtwoord, $changedValues);
header("Location: account.php");
print('<meta http-equiv="refresh" content="0;account.php">
<script type="text/javascript">
window.location = "account.php";
</script>');
die("Refresh de pagina a.u.b.");
}
}
// Genereer de HTML layout
foreach ($secties as $naam => $veldenArray) {
?>
<hr style="margin: 1.5rem 0" />
<div id="account-form-<?php print($naam); ?>">
<h4 class="account-form-title"
style="margin-bottom: 1.0rem">
<?php print($naam); ?>
</h4>
<!-- Form voor de inputs van gegevens om een account te maken -->
<form action="" method="post">
<div class="row">
<?php
foreach ($veldenArray as $veld) {
?>
<div class="account-form-field-container col-4">
<label class="account-form-field-label w-100">
<span class="account-form-field-title"
style="color: <?php print(VENDOR_THEME_COLOR_TEXT_DISABLED); ?>">
<?php print(str_replace("_", " ", $veld->getNaam())); ?>
</span>
<input name="<?php print($veld->getNaam()); ?>"
type="<?php print($veld->getType()); ?>"
class="account-form-field-input form-control w-100"
<?php
if ($veld->getVar() != null) {
printf('value="%s"', $veld->getVar());
}
if ($veld->isRequired()) {
print("required");
}
?>
/>
</label>
</div>
<?php
}
?>
</div>
<div class="row">
<!-- Opvuller -->
<div class="col-9">
</div>
<div class="col-3">
<input type="submit"
value="Update informatie"
class="btn btn-secondary w-100"
style="margin-top: 1.2rem">
</div>
</div>
<input type="hidden"
name="csrf_token"
value="<?php print($csrf_token);?>"
/>
</form>
</div>
<?php
}
?>
<div id="account-actions">
<div id="account-actions-delete" style="margin: 1.4rem 0">
<form action="" method="post">
<input type="hidden"
name="action"
value="delete"
/>
<input type="hidden"
name="csrf_token"
value="<?php print($csrf_token);?>"
/>
<div class="row">
<!-- Opvuller -->
<div class="col-9">
</div>
<div class="col-3">
<input type="submit"
value="Verwijder account"
class="btn btn-danger w-100"
/>
</div>
</div>
</form>
</div>
</div>
<?php
// Als de gebruiker op een actieknop heeft gedrukt
if (isset($_POST["action"]) && strlen(strval($_POST["action"])) > 0) {
// Als de CSRF token goed is
if (isset($_POST["csrf_token"]) && hash_equals($csrf_token, $_POST["csrf_token"])) {
switch (strval($_POST["action"])) {
// Verwijder account
case "delete":
Account::delete(Database::getConnection(), $email);
Authentication::logout();
header("Location: account.php");
print('<meta http-equiv="refresh" content="0;account.php">
<script type="text/javascript">
window.location = "account.php";
</script>');
break;
}
}
}
?>
</div>
</div>
<div class="footer-container">
<?php
include("tpl/footer_template.php");
?>
</div>
</body>
</html>