-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathown_details.php
More file actions
224 lines (167 loc) · 6.61 KB
/
own_details.php
File metadata and controls
224 lines (167 loc) · 6.61 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
<?php
require_once("configuration.php");
if (!isset($_SESSION["LOGIN_USER"]))
{
header('Location: http://' . $_SERVER['SERVER_NAME'] . '/subscription_block');
exit;
}
include("includes/header.php");
$userResult = $dataconnection->query("SELECT * FROM user_accounts WHERE username = '" . $_SESSION["LOGIN_USER"] . "' LIMIT 1");
$userData = $userResult->fetch_assoc();
if (isset($_POST["editor_firstname"]))
{
$firstNameField = $_POST["editor_firstname"];
$secondNameField = $_POST["editor_secondname"];
$emailField = $_POST["editor_email"];
$currentPassField = $_POST["editor_currentpassword"];
$newPassField = $_POST["editor_newpassword"];
$newPass2Field = $_POST["editor_newpassword2"];
if (empty($firstNameField) || empty($secondNameField) || empty($emailField))
{
$errorMessage = "Vaadittuja tietoja puuttuu, tarkista.";
}
if (!filter_var($emailField, FILTER_VALIDATE_EMAIL)) {
$errorMessage = "Virheellinen sähköpostiosoite.";
}
if (empty($errorMessage))
{
$dataChange = $dataconnection->prepare("UPDATE user_accounts SET firstName=?, secondName=?, email=? WHERE username=? LIMIT 1");
@$dataChange->bind_param('ssss', $firstNameField, $secondNameField, $emailField, $_SESSION["LOGIN_USER"]);
$dataChange->execute();
$successMessage = "Tietojen muuttaminen onnistui.";
}
if (!empty($currentPassField))
{
$password = mysqli_real_escape_string($dataconnection, $currentPassField);
$passwordHash = @$dataconnection->query("SELECT password FROM user_accounts WHERE username = '" . $_SESSION["LOGIN_USER"] . "' LIMIT 1")->fetch_object()->password;
if (empty($newPassField) || empty($newPass2Field))
{
$errorMessage = "Vaadittuja tietoja puuttuu, tarkista.";
}
if (!password_verify($password, $passwordHash))
{
$errorMessage = "Nykyinen salasana on virheellinen. Ole hyvä ja tarkista.";
}
if ($newPassField != $newPass2Field)
{
$errorMessage = "Salasanat eivät täsmää. Tarkista oikeinkirjoitus.";
}
if (empty($errorMessage))
{
try
{
$pQuery = "UPDATE user_accounts SET password=? WHERE username=?";
$passwordChange = $dataconnection->prepare("UPDATE user_accounts SET password=? WHERE username=? LIMIT 1");
@$passwordChange->bind_param('ss', password_hash($newPassField, PASSWORD_BCRYPT), $_SESSION["LOGIN_USER"]);
$passwordChange->execute();
$successMessage = "Salasanan vaihtaminen onnistui.";
}
catch(Exception $e)
{
$errorMessage = "Jokin meni pieleen";
}
}
}
}
?>
<div class="container">
<form class="form-horizontal" method="post">
<?php
if (!empty($errorMessage))
{
?>
<div class="alert alert-danger" role="alert">
<?php echo $errorMessage; ?>
</div>
<?php
}
?>
<?php
if (!empty($successMessage))
{
?>
<div class="alert alert-success" role="alert">
<?php echo $successMessage; ?>
</div>
<?php
}
?>
<fieldset>
<!-- Form Name -->
<legend>Muokkaa omia tietoja</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="editor_firstname">Etunimi</label>
<div class="col-md-4">
<input id="editor_email" name="editor_firstname" type="text" value="<?php echo $userData["firstName"]; ?>" placeholder="" class="form-control input-md" required="">
<span class="help-block">Käytetään palvelun kustomoinnissa. Ei näytetä julkisesti.</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="editor_secondname">Sukunimi</label>
<div class="col-md-4">
<input id="editor_email" name="editor_secondname" type="text" value="<?php echo $userData["secondName"]; ?>" placeholder="" class="form-control input-md" required="">
<span class="help-block">Käytetään palvelun kustomoinnissa. Ei näytetä julkisesti.</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="editor_username">Käyttäjänimi</label>
<div class="col-md-4">
<input id="editor_username" name="editor_username" value="<?php echo $userData["username"]; ?>" type="text" placeholder="" class="form-control input-md" disabled="">
<span class="help-block">Tämä on sinun nimimerkkisi, joka näkyy julkisesti muun muassa kommentoidessasi uutisartikkeleita.</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="editor_email">Sähköpostiosoite</label>
<div class="col-md-4">
<input id="editor_email" name="editor_email" type="text" value="<?php echo $userData["email"]; ?>" placeholder="" class="form-control input-md" required="">
<span class="help-block">Voit tilata uuden salasanan tähän sähköpostiosoitteeseen, jos satut unohtamaan sen.</span>
</div>
</div>
<!-- Prepended checkbox -->
<div class="form-group">
<label class="col-md-4 control-label" for="prependedcheckbox">Kirjautumiskerrat</label>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">
<?php echo $userData["accessCount"]; ?>
</span>
</div>
<p class="help-block">tunnuksen luomisen <?php echo date('j.n.Y G:i', $userData["timestamp_registered"]); ?> jälkeen</p>
</div>
</div>
</fieldset>
<fieldset>
<!-- Form Name -->
<legend>Vaihda salasana</legend>
<div class="form-group">
<label class="col-md-4 control-label" for="editor_currentpassword">Nykyinen salasana</label>
<div class="col-md-4">
<input id="editor_currentpassword" name="editor_currentpassword" type="password" value="" placeholder="" class="form-control input-md">
<span class="help-block">Mikäli haluat vaihtaa salasanasi, kirjoita tähän nykyinen salasanasi.</span>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="editor_newpassword">Uusi salasana</label>
<div class="col-md-4">
<input id="editor_newpassword" name="editor_newpassword" type="password" value="" placeholder="" class="form-control input-md">
<span class="help-block">Anna uusi salasana. Muista valita turvallinen sana!</span>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="editor_newpassword2">Uusi salasana uudelleen</label>
<div class="col-md-4">
<input id="editor_newpassword2" name="editor_newpassword2" type="password" value="" placeholder="" class="form-control input-md">
<span class="help-block">Kirjoitusvirheiden välttämiseksi</span>
</div>
</div>
<button type="submit" class="btn btn-default">Tallenna muutokset</button>
</fieldset>
</form>
</div>
<?php
include("includes/footer.php");
?>