-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.php
218 lines (187 loc) · 5.13 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
212
213
214
215
216
217
218
<?php
define('INCLUDE_CHECK',true);
// Those two files can be included only if INCLUDE_CHECK is defined
require "includes/connect.php";
require 'includes/functions.php';
include 'includes/membersOnly.php';
function adderror($error){
global $errorarray;
$errorarray[] = $error;
}
function addsuccess($success){
global $successarray;
$successarray[] = $success;
}
$userInfo = mysql_query("SELECT username,email FROM users WHERE
userid=".$_SESSION['id']."
");
$userRow = mysql_fetch_assoc($userInfo);
if (!$userRow)
die('Error getting user information.');
if ($_POST['save'])
{
$cansave = true;
//Check old hash
$userSalt = getUserSalt($_SESSION['id']);
$oldHash = getPassword($_SESSION['usr'], $_POST['oldpass'], $userSalt);
//Check oldHash against the stored hash
$passOut = mysql_query("SELECT password FROM users WHERE
userid=".mysql_real_escape_string($_SESSION['id'])."
");
$passrow = mysql_fetch_assoc($passOut);
if ($passrow['password'])
{
if ($oldHash != $passrow['password'])
{
adderror("Incorrect password. Cannot save.");
$cansave = false;
}
}
else
{
adderror("Incorrect password. Cannot save.");
$cansave = false;
}
mysql_free_result($passOut);
//==== Password ===================================================
if ($_POST['newpass'])
{
if ($_POST['oldpass'] == $_POST['newpass'])
{
adderror("Old and new password cannot be the same.");
$cansave = false;
}
$_POST['newpass'] = mysql_real_escape_string($_POST['newpass']);
if ($_POST['newpass'] != $_POST['newpass2'])
{
adderror("Passwords do not match.");
$cansave = false;
}
if(strlen($_POST['newpass']) < 8)
{
adderror("Your new password needs to be 8 characters or more!");
$cansave = false;
}
}
//==== Email ===================================================
if ($userRow['email'] != $_POST['cemail'])
{
if (!checkEmail($_POST['cemail']))
{
adderror("Not a valid email.");
$cansave = false;
}
}
//==== Saving ===================================================
//Everything checks out
//Change the password
if ($cansave)
{
//Save password, if new pass
if ($_POST['newpass'])
{
$newHash = getPassword($_SESSION['usr'], $_POST['newpass'], $userSalt);
$passIn = mysql_query("UPDATE users SET
password='".$newHash."' WHERE
userid=".mysql_real_escape_string($_SESSION['id'])."
");
if ($passIn)
{
addsuccess("Password changed!");
}
else
{
adderror("Error changing your password!");
}
}
//Save email, if new email
if ($userRow['email'] != $_POST['cemail'])
{
$emailIn = mysql_query("UPDATE users SET
email='".mysql_real_escape_string($_POST['cemail'])."' WHERE
userid=".mysql_real_escape_string($_SESSION['id'])."
");
if ($emailIn)
{
addsuccess("Email changed!");
$userRow['email'] = mysql_real_escape_string($_POST['cemail']);
}
else
{
adderror("Error changing your email!");
}
}
}
}
else if ($_POST['clearnotes'])
{
adderror("Nope. Chuck Testa.");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Pencl - Coming Soon</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/styles.css" media="screen">
<link rel="stylesheet" type="text/css" href="css/book.css" media="screen">
<?php
//Put this at the end of the <head> tag to track
include 'includes/topbar_header.php';
include 'includes/tracker.php';
?>
</head>
<body>
<?php
//Must be first thing in the <body> tag to function correctly
include 'includes/topbar.php';
?>
<div class="bookcontainer">
<div class="book">
<div class="page">
<?php
echo "<h1>User settings for ".$userRow['username']."</h1>";
echo "<br />";
if ($errorarray)
{
foreach($errorarray as $value)
echo "<p class='error'>$value</p>";
}
if ($successarray)
{
foreach($successarray as $svalue)
echo "<p class='success'>$svalue</p>";
}
unset($errorarray);
unset($successarray);
?>
<form class="clearfix" action="" method="post">
<h3>Change password</h3>
<div>
<label class="grey" for="oldpass">Current:</label>
<input class="field" type="password" name="oldpass" id="password" size="23" />
</div>
<div>
<label class="grey" for="newpass">New:</label>
<input class="field" type="password" name="newpass" id="password" size="23" />
</div>
<div>
<label class="grey" for="newpass">Retype new:</label>
<input class="field" type="password" name="newpass2" id="password" size="23" />
</div>
<h3>Change Email</h3>
<div>
<label class="grey" for="email">Email:</label>
<input class="field" type="text" name="cemail" id="cemail" value="<?php echo $userRow['email'] ?>" size="23" />
</div>
<br />
<input type="submit" name="save" value="Save" />
<input type="submit" name="clearnotes" value="Delete Notebooks" />
<input type="button" name="cancel" value="Cancel" onClick="window.history.back()" />
</form>
</div>
</div>
</div>
</body>
</html>