-
Notifications
You must be signed in to change notification settings - Fork 34
/
settings.php
211 lines (174 loc) · 7.12 KB
/
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
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
<?php
session_start();
require_once("inc/config.inc.php");
require_once("inc/functions.inc.php");
//Überprüfe, dass der User eingeloggt ist
//Der Aufruf von check_user() muss in alle internen Seiten eingebaut sein
$user = check_user();
include("templates/header.inc.php");
if(isset($_GET['save'])) {
$save = $_GET['save'];
if($save == 'personal_data') {
$vorname = trim($_POST['vorname']);
$nachname = trim($_POST['nachname']);
if($vorname == "" || $nachname == "") {
$error_msg = "Bitte Vor- und Nachname ausfüllen.";
} else {
$statement = $pdo->prepare("UPDATE users SET vorname = :vorname, nachname = :nachname, updated_at=NOW() WHERE id = :userid");
$result = $statement->execute(array('vorname' => $vorname, 'nachname'=> $nachname, 'userid' => $user['id'] ));
$success_msg = "Daten erfolgreich gespeichert.";
}
} else if($save == 'email') {
$passwort = $_POST['passwort'];
$email = trim($_POST['email']);
$email2 = trim($_POST['email2']);
if($email != $email2) {
$error_msg = "Die eingegebenen E-Mail-Adressen stimmten nicht überein.";
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_msg = "Bitte eine gültige E-Mail-Adresse eingeben.";
} else if(!password_verify($passwort, $user['passwort'])) {
$error_msg = "Bitte korrektes Passwort eingeben.";
} else {
$statement = $pdo->prepare("UPDATE users SET email = :email WHERE id = :userid");
$result = $statement->execute(array('email' => $email, 'userid' => $user['id'] ));
$success_msg = "E-Mail-Adresse erfolgreich gespeichert.";
}
} else if($save == 'passwort') {
$passwortAlt = $_POST['passwortAlt'];
$passwortNeu = trim($_POST['passwortNeu']);
$passwortNeu2 = trim($_POST['passwortNeu2']);
if($passwortNeu != $passwortNeu2) {
$error_msg = "Die eingegebenen Passwörter stimmten nicht überein.";
} else if($passwortNeu == "") {
$error_msg = "Das Passwort darf nicht leer sein.";
} else if(!password_verify($passwortAlt, $user['passwort'])) {
$error_msg = "Bitte korrektes Passwort eingeben.";
} else {
$passwort_hash = password_hash($passwortNeu, PASSWORD_DEFAULT);
$statement = $pdo->prepare("UPDATE users SET passwort = :passwort WHERE id = :userid");
$result = $statement->execute(array('passwort' => $passwort_hash, 'userid' => $user['id'] ));
$success_msg = "Passwort erfolgreich gespeichert.";
}
}
}
$user = check_user();
?>
<div class="container main-container">
<h1>Einstellungen</h1>
<?php
if(isset($success_msg) && !empty($success_msg)):
?>
<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<?php echo $success_msg; ?>
</div>
<?php
endif;
?>
<?php
if(isset($error_msg) && !empty($error_msg)):
?>
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<?php echo $error_msg; ?>
</div>
<?php
endif;
?>
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#data" aria-controls="home" role="tab" data-toggle="tab">Persönliche Daten</a></li>
<li role="presentation"><a href="#email" aria-controls="profile" role="tab" data-toggle="tab">E-Mail</a></li>
<li role="presentation"><a href="#passwort" aria-controls="messages" role="tab" data-toggle="tab">Passwort</a></li>
</ul>
<!-- Persönliche Daten-->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="data">
<br>
<form action="?save=personal_data" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputVorname" class="col-sm-2 control-label">Vorname</label>
<div class="col-sm-10">
<input class="form-control" id="inputVorname" name="vorname" type="text" value="<?php echo htmlentities($user['vorname']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputNachname" class="col-sm-2 control-label">Nachname</label>
<div class="col-sm-10">
<input class="form-control" id="inputNachname" name="nachname" type="text" value="<?php echo htmlentities($user['nachname']); ?>" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
</div>
</div>
</form>
</div>
<!-- Änderung der E-Mail-Adresse -->
<div role="tabpanel" class="tab-pane" id="email">
<br>
<p>Zum Änderen deiner E-Mail-Adresse gib bitte dein aktuelles Passwort sowie die neue E-Mail-Adresse ein.</p>
<form action="?save=email" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputPasswort" class="col-sm-2 control-label">Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswort" name="passwort" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label">E-Mail</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail" name="email" type="email" value="<?php echo htmlentities($user['email']); ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail2" class="col-sm-2 control-label">E-Mail (wiederholen)</label>
<div class="col-sm-10">
<input class="form-control" id="inputEmail2" name="email2" type="email" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
</div>
</div>
</form>
</div>
<!-- Änderung des Passworts -->
<div role="tabpanel" class="tab-pane" id="passwort">
<br>
<p>Zum Änderen deines Passworts gib bitte dein aktuelles Passwort sowie das neue Passwort ein.</p>
<form action="?save=passwort" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputPasswort" class="col-sm-2 control-label">Altes Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswort" name="passwortAlt" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu" class="col-sm-2 control-label">Neues Passwort</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu" name="passwortNeu" type="password" required>
</div>
</div>
<div class="form-group">
<label for="inputPasswortNeu2" class="col-sm-2 control-label">Neues Passwort (wiederholen)</label>
<div class="col-sm-10">
<input class="form-control" id="inputPasswortNeu2" name="passwortNeu2" type="password" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Speichern</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include("templates/footer.inc.php")
?>