~lss-team/lilsoftstats/trunk

« back to all changes in this revision

Viewing changes to inc/myaccount.php

  • Committer: Nick
  • Date: 2011-11-14 04:10:28 UTC
  • Revision ID: nick@little-apps.org-20111114041028-cvmpwq6z6hx3pkya
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Little Software Stats
 
4
 *
 
5
 * An open source program that allows developers to keep track of how their software is being used
 
6
 *
 
7
 * @package             Little Software Stats
 
8
 * @author              Little Apps
 
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
 
12
 * @since               Version 0.1
 
13
 * @filesource
 
14
 */
 
15
 
 
16
require_once('main.php');
 
17
 
 
18
if (!$sLogin->CheckUser())
 
19
        header(sprintf("Location: %s/login.php", SITE_URL));
 
20
 
 
21
$sCurrentUsername = $_SESSION['UserName'];
 
22
 
 
23
if (!$sMySQL->Select("Users", array("UserName" => $sCurrentUsername), "", "0,1"))
 
24
        die("Unable to query database, error:" . $sMySQL->sLastError);
 
25
 
 
26
 
 
27
$sCurrentId = $sMySQL->aArrayedResult['UserId'];
 
28
$sCurrentEmail = $sMySQL->aArrayedResult['UserEmail'];
 
29
$sCurrentPass = $sMySQL->aArrayedResult['UserPass'];
 
30
 
 
31
$sVerifyPass = trim($_REQUEST['password']);
 
32
 
 
33
$sNewUsername = trim($_REQUEST['username']);
 
34
$sNewEmail = trim($_REQUEST['email']);
 
35
$sNewPass = trim($_REQUEST['newpassword']);
 
36
$sNewPass2 = trim($_REQUEST['newpassword2']);
 
37
 
 
38
$aNewConfig = array();
 
39
 
 
40
$bChangeUser = false;
 
41
$bChangePass = false;
 
42
$bChangeEmail = false;
 
43
 
 
44
if ($sNewUsername == '') {
 
45
        echo RedMsgBox("The username cannot be empty");
 
46
        return;
 
47
}
 
48
 
 
49
if ($sNewEmail == '') {
 
50
        echo RedMsgBox("The e-mail address cannot be empty");
 
51
        return;
 
52
}
 
53
 
 
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; }
 
60
        } else {
 
61
                $aNewConfig['UserName'] = $sNewUsername;
 
62
                
 
63
                $bChangeUser = true;
 
64
        }
 
65
}
 
66
 
 
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");
 
71
                return;
 
72
        } else {
 
73
                $aNewConfig['UserEmail'] = $sNewEmail;
 
74
                
 
75
                $bChangeEmail = true;
 
76
        }
 
77
}
 
78
 
 
79
// Check valid new password
 
80
if ($sNewPass != '' && $sNewPass2 != '') {
 
81
        if ($sNewPass != $sNewPass2) {
 
82
                echo RedMsgBox("The passwords do not match");
 
83
                return;
 
84
        } else if (strlen($sNewPass) < 6) {
 
85
                echo RedMsgBox("Password must be more than 6 characters");
 
86
                return;
 
87
        } else {
 
88
                $aNewConfig['UserPass'] = md5($sNewPass);
 
89
                
 
90
                $bChangePass = true;
 
91
        }
 
92
}
 
93
 
 
94
if (empty($aNewConfig)) {
 
95
        echo yellowMsgBox("Nothing needs to be updated");
 
96
        return;
 
97
}
 
98
 
 
99
if (md5($sVerifyPass) != $sCurrentPass) {
 
100
        echo RedMsgBox("The password does not match your current password");
 
101
        return;
 
102
}
 
103
 
 
104
if (!$sMySQL->Update("Users", $aNewConfig, array("UserId" => $sCurrentId))) {
 
105
    echo RedMsgBox("Unable to query database, error:" . $sMySQL->sLastError);
 
106
    return;
 
107
}
 
108
 
 
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!";
 
115
 
 
116
if (!SendMail($sCurrentEmail, $sSubject, $sMessage)) {
 
117
        echo RedMsgBox ("Unable to send account update notification");
 
118
        return;
 
119
}
 
120
 
 
121
if ($bChangeUser)
 
122
    $_SESSION['UserName'] = $sNewUsername;
 
123
 
 
124
echo GreenMsgBox("Your account information was successfully updated");
 
125
?>
 
 
b'\\ No newline at end of file'