3 UserCake Version: 2.0.2
\r
7 require_once("models/config.php");
\r
8 if (!securePage($_SERVER['PHP_SELF'])){die();}
\r
10 //Prevent the user visiting the logged in page if he is not logged in
\r
11 if(!isUserLoggedIn()) { header("Location: login.php"); die(); }
\r
16 $successes = array();
\r
17 $password = $_POST["password"];
\r
18 $password_new = $_POST["passwordc"];
\r
19 $password_confirm = $_POST["passwordcheck"];
\r
22 $email = $_POST["email"];
\r
24 //Perform some validation
\r
25 //Feel free to edit / change as required
\r
27 //Confirm the hashes match before updating a users password
\r
28 $entered_pass = generateHash($password,$loggedInUser->hash_pw);
\r
30 if (trim($password) == ""){
\r
31 $errors[] = lang("ACCOUNT_SPECIFY_PASSWORD");
\r
33 else if($entered_pass != $loggedInUser->hash_pw)
\r
36 $errors[] = lang("ACCOUNT_PASSWORD_INVALID");
\r
38 if($email != $loggedInUser->email)
\r
40 if(trim($email) == "")
\r
42 $errors[] = lang("ACCOUNT_SPECIFY_EMAIL");
\r
44 else if(!isValidEmail($email))
\r
46 $errors[] = lang("ACCOUNT_INVALID_EMAIL");
\r
48 else if(emailExists($email))
\r
50 $errors[] = lang("ACCOUNT_EMAIL_IN_USE", array($email));
\r
53 //End data validation
\r
54 if(count($errors) == 0)
\r
56 $loggedInUser->updateEmail($email);
\r
57 $successes[] = lang("ACCOUNT_EMAIL_UPDATED");
\r
61 if ($password_new != "" OR $password_confirm != "")
\r
63 if(trim($password_new) == "")
\r
65 $errors[] = lang("ACCOUNT_SPECIFY_NEW_PASSWORD");
\r
67 else if(trim($password_confirm) == "")
\r
69 $errors[] = lang("ACCOUNT_SPECIFY_CONFIRM_PASSWORD");
\r
71 else if(minMaxRange(8,50,$password_new))
\r
73 $errors[] = lang("ACCOUNT_NEW_PASSWORD_LENGTH",array(8,50));
\r
75 else if($password_new != $password_confirm)
\r
77 $errors[] = lang("ACCOUNT_PASS_MISMATCH");
\r
80 //End data validation
\r
81 if(count($errors) == 0)
\r
83 //Also prevent updating if someone attempts to update with the same password
\r
84 $entered_pass_new = generateHash($password_new,$loggedInUser->hash_pw);
\r
86 if($entered_pass_new == $loggedInUser->hash_pw)
\r
88 //Don't update, this fool is trying to update with the same password ¬¬
\r
89 $errors[] = lang("ACCOUNT_PASSWORD_NOTHING_TO_UPDATE");
\r
93 //This function will create the new hash and update the hash_pw property.
\r
94 $loggedInUser->updatePassword($password_new);
\r
95 $successes[] = lang("ACCOUNT_PASSWORD_UPDATED");
\r
99 if(count($errors) == 0 AND count($successes) == 0){
\r
100 $errors[] = lang("NOTHING_TO_UPDATE");
\r
104 require_once("models/header.php");
\r
108 <div id='top'><div id='logo'></div></div>
\r
111 <h2>User Settings</h2>
\r
112 <div id='left-nav'>";
\r
113 include("left-nav.php");
\r
119 echo resultBlock($errors,$successes);
\r
123 <form name='updateAccount' action='".$_SERVER['PHP_SELF']."' method='post'>
\r
125 <label>Password:</label>
\r
126 <input type='password' name='password' />
\r
129 <label>Email:</label>
\r
130 <input type='text' name='email' value='".$loggedInUser->email."' />
\r
133 <label>New Pass:</label>
\r
134 <input type='password' name='passwordc' />
\r
137 <label>Confirm Pass:</label>
\r
138 <input type='password' name='passwordcheck' />
\r
141 <label> </label>
\r
142 <input type='submit' value='Update' class='submit' />
\r
147 <div id='bottom'></div>
\r