-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.php
204 lines (154 loc) · 6.91 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
<?php
session_start();
include('classes/gallery.php');
//define page title
$title = 'Einstellungen';
include('classes/user.php');
$user = new User($db);
//check if already logged in move to home page
if (!$user->is_logged_in()) {
header('Location: index.php');
}
$images = $user->getAvatar($_SESSION['userId']);
$amountImages = sizeof($images);
if (isset($_POST['update-user'])) {
$email = $_POST['email'];
$password = $_POST['password'];
$password2 = $_POST['passwordConfirm'];
if (!empty($password) && !empty($password2)) {
if (strlen($password) < 3) {
$updateerror[] = 'Das Passwort ist zu kurz. Mindestens 3 Zeichen.';
}
if (strlen($password2) < 3) {
$updateerror[] = 'Das Confirm Passwort ist zu kurz. Mindestens 3 Zeichen.';
}
if ($password != $password2) {
$updateerror[] = 'Die Passwörter stimmen nicht überein..';
}
}
//email validation
if ($email != $user->get_mail($_SESSION['userId'])) {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$updateerror[] = 'Bitte eine valide E-Mail Adresse eingeben.';
} else {
if ($user->mail_exists($email) && $email != $user->get_mail($_SESSION['userId'])) {
$updateerror[] = 'Die E-Mail Adresse ist bereits in Verwendung.';
}
}
}
//if no errors have been created carry on
if (!isset($updateerror)) {
$updateerfolg = false;
//hash the password
if (!empty($password)) {
$hashedpassword = $user->password_save($password);
if ($user->change_password($hashedpassword, $_SESSION['userId'])) {
$updateerfolg = true;
}
}
if ($email != $user->get_mail($_SESSION['userId'])) {
if ($user->update_user($email, $_SESSION['userId'])) {
$updateerfolg = true;
}
}
}
}
//include header template
require('layout/header.php');
?>
<div class="container-fluid">
<div class="content settings-page">
<?php
require('layout/nav.php');
?>
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-12">
<div class="inner">
<h1><?php echo $title ?></h1>
<hr>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-2 col-md-offset-1">
<div class="inner">
<?php
if ($amountImages > 0) {
echo '<div id="uploadavatar"><img src="' . $images . '" class="img-circle avatar" /></div>';
} else {
echo '<div id="uploadavatar"><img src="https://www.gravatar.com/avatar/83e4eb193d866390749a946d35c0503f?s=100&d=mm&r=g" class="img-circle avatar"></div>';
}
?>
</div>
</div>
<div class="col-xs-12 col-sm-4 col-md-3">
<div class="inner">
<h4>Avatar bearbeiten</h4>
<form class="avatarForm" name="avatarForm" enctype="multipart/form-data" action="" method="post">
<input id="avatar" name="avatar" type="file" accept="image/jpg,image/png,image/jpeg,image/gif" />
<div class="upload-msg"> </div>
<div class="form-group pull-left avatarbutton">
<input type="submit" id="avatarbutton" name="send" value="Edit Avatar" class="btn btn-default btn-sm">
</div>
</form>
</div>
</div>
</div>
<div class="row">
<div class="inner">
<div class="col-xs-12 col-sm-4 col-md-5 col-md-offset-1">
<form role="form" class="form-horizontal" method="post" id="editUser" action="<?php echo $_SERVER['PHP_SELF'];
?>" autocomplete="off">
<?php
if ($updateerfolg) {
echo '<p class="bg-success">Daten aktualisiert.</p>';
}
if (isset($updateerror)) {
foreach ($updateerror as $uerror) {
echo '<p class="bg-danger">' . $uerror . '</p>';
}
}
?>
<div class="form-group">
<label class="control-label col-sm-3 settingsform" for="username">Username:</label>
<div class="col-sm-9">
<input type="text" name="username" id="username" readonly="readonly" class="form-control input-lg" placeholder="Username" value="<?php
if (isset($_SESSION['user'])) {
echo $_SESSION['user'];
}
?>" tabindex="1">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Email:</label>
<div class="col-sm-9">
<input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Addresse" value="<?php
echo $user->get_mail($_SESSION['userId']);
?>" tabindex="2">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="password">Passwort:</label>
<div class="col-sm-9">
<input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="3"> <span class="help-inline">Nur wenn Passwort geändert werden soll</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="passwordConfirm">Passwort (x2):</label>
<div class="col-sm-9">
<input type="password" name="passwordConfirm" id="passwordConfirm" class="form-control input-lg" placeholder="Confirm Passwort" tabindex="4">
</div>
</div>
<div class="form-group pull-right col-sm-3">
<input type="submit" id="updateUser" name="update-user" value="Bearbeiten" class="btn btn-success">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
//include footer template
require('layout/footer.php');
?>