3
* Little Software Stats
5
* An open source program that allows developers to keep track of how their software is being used
7
* @package Little Software Stats
9
* @copyright Copyright (c) 2011, Little Apps
10
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License v3
11
* @link http://little-apps.org
16
require_once('main.php');
18
if (!$sLogin->CheckUser())
19
header(sprintf("Location: %s/login.php", SITE_URL));
21
$sCurrentUsername = $_SESSION['UserName'];
23
if (!$sMySQL->Select("Users", array("UserName" => $sCurrentUsername), "", "0,1"))
24
die("Unable to query database, error:" . $sMySQL->sLastError);
27
$sCurrentId = $sMySQL->aArrayedResult['UserId'];
28
$sCurrentEmail = $sMySQL->aArrayedResult['UserEmail'];
29
$sCurrentPass = $sMySQL->aArrayedResult['UserPass'];
31
$sVerifyPass = trim($_REQUEST['password']);
33
$sNewUsername = trim($_REQUEST['username']);
34
$sNewEmail = trim($_REQUEST['email']);
35
$sNewPass = trim($_REQUEST['newpassword']);
36
$sNewPass2 = trim($_REQUEST['newpassword2']);
38
$aNewConfig = array();
42
$bChangeEmail = false;
44
if ($sNewUsername == '') {
45
echo RedMsgBox("The username cannot be empty");
49
if ($sNewEmail == '') {
50
echo RedMsgBox("The e-mail address cannot be empty");
54
// Check valid username
55
if ($sNewUsername != $sCurrentUsername) {
56
if (!preg_match("/^[a-z\d_]{5,20}$/i", $sNewUsername)) {
57
if (strlen($sNewUsername) < 5) { echo RedMsgBox("Username must be at least 5 characters"); return; }
58
else if (strlen($sNewUsername) > 20) { echo RedMsgBox("Username cannot be more then 20 characters"); return; }
59
else { echo RedMsgBox("Username can only contain alpha-numeric characters (a-z, A-Z, 0-9) and underscores"); return; }
61
$aNewConfig['UserName'] = $sNewUsername;
67
// Check valid email address
68
if ($sNewEmail != $sCurrentEmail) {
69
if (!filter_var($sNewEmail, FILTER_VALIDATE_EMAIL)) {
70
echo RedMsgBox("The e-mail address is invalid");
73
$aNewConfig['UserEmail'] = $sNewEmail;
79
// Check valid new password
80
if ($sNewPass != '' && $sNewPass2 != '') {
81
if ($sNewPass != $sNewPass2) {
82
echo RedMsgBox("The passwords do not match");
84
} else if (strlen($sNewPass) < 6) {
85
echo RedMsgBox("Password must be more than 6 characters");
88
$aNewConfig['UserPass'] = md5($sNewPass);
94
if (empty($aNewConfig)) {
95
echo yellowMsgBox("Nothing needs to be updated");
99
if (md5($sVerifyPass) != $sCurrentPass) {
100
echo RedMsgBox("The password does not match your current password");
104
if (!$sMySQL->Update("Users", $aNewConfig, array("UserId" => $sCurrentId))) {
105
echo RedMsgBox("Unable to query database, error:" . $sMySQL->sLastError);
109
$sSubject = "Your account at $sSiteName";
110
$sMessage = "Below is your updated account information:\n\n";
111
$sMessage .= "Username: " . (($bChangeUser) ? ($sNewUsername) : ($sCurrentUsername)) . "\n";
112
$sMessage .= "E-mail address: ". (($bChangeEmail) ? ($sNewEmail) : ($sCurrentEmail)). "\n";
113
$sMessage .= "Password: ". (($bChangePass) ? ($sNewPass) : ("(Password has not been changed)")) . "\n\n";
114
$sMessage .= "This is an automated response, please do not reply!";
116
if (!SendMail($sCurrentEmail, $sSubject, $sMessage)) {
117
echo RedMsgBox ("Unable to send account update notification");
122
$_SESSION['UserName'] = $sNewUsername;
124
echo GreenMsgBox("Your account information was successfully updated");
b'\\ No newline at end of file'