PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/banned/profile.php

http://esglobalban.googlecode.com/
PHP | 245 lines | 175 code | 18 blank | 52 comment | 56 complexity | 1ce232813cbc565af65b289a1584f178 MD5 | raw file
  1. <?php
  2. /*
  3. This file is part of GlobalBan.
  4. Written by Stefan Jonasson <soynuts@unbuinc.net>
  5. Copyright 2008 Stefan Jonasson
  6. GlobalBan is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. GlobalBan is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GlobalBan. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. require_once(ROOTDIR."/include/database/class.UserQueries.php");
  18. require_once(ROOTDIR."/include/objects/class.User.php");
  19. $userQueries = new UserQueries();
  20. $user = $userQueries->getUserInfo($_SESSION['name']); // Get current logged in user's info
  21. // Boolean values of whether post values are valid
  22. $valid = array("username"=>true,
  23. "steamId"=>true,
  24. "email"=>true,
  25. "curPassword"=>true,
  26. "cpassword"=>true,
  27. "npassword"=>true,
  28. "vpassword"=>true);
  29. // *********************************************
  30. // If the user is updating their general profile
  31. // *********************************************
  32. if(isset($_POST['generalProfile'])) {
  33. $generalChangesMade = false;
  34. $generalErrors = false;
  35. $username = $_POST['username'];
  36. // Check if user name was changed
  37. if($user->getName() != addslashes($username)) {
  38. // Determine if NEW username already exists
  39. if(!$userQueries->usernameExist($username) && !empty($username)) {
  40. $valid['username'] = true;
  41. $generalChangesMade = true; // A change has been made
  42. // Update username
  43. $user->setName($username);
  44. } else {
  45. $valid['username'] = false;
  46. $generalErrors = true;
  47. }
  48. }
  49. // Steam ID
  50. $steamId = $_POST['steamId'];
  51. if($user->getSteamId() != $steamId) {
  52. if(preg_match("/^STEAM_[01]:[01]:\d{0,10}$/", $steamId)) {
  53. $valid['steamId'] = true;
  54. $generalChangesMade = true; // A change has been made
  55. // Update Steam ID
  56. $user->setSteamId($steamId);
  57. } else {
  58. $valid['steamId'] = false;
  59. $generalErrors = true;
  60. }
  61. }
  62. // Email
  63. $email = $_POST['email'];
  64. // Email changed and password correct
  65. if($user->getEmail() != $email && $user->getPassword() == md5($_POST['curPassword'])) {
  66. // Simplified version that does not do dns validation
  67. if(preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $email)) {
  68. $valid['email'] = true;
  69. $valid['curPassword'] = true;
  70. $generalChangesMade = true;
  71. // Everything is valid for an email change, set the changes
  72. $user->setEmail($email);
  73. } else {
  74. $valid['email'] = false;
  75. $generalErrors = true;
  76. }
  77. } else if($user->getEmail() == $email) {
  78. // If email isn't being changed then this can be valid
  79. $valid['curPassword'] = true;
  80. } else if($user->getEmail() != $email && $user->getPassword() != md5($_POST['curPassword'])) {
  81. // Email changed but password incorrect
  82. $valid['curPassword'] = false;
  83. $generalErrors = true;
  84. // Email was correct but password still wrong
  85. if(preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $email)) {
  86. $valid['email'] = true;
  87. } else {
  88. $valid['email'] = false;
  89. }
  90. }
  91. // Save changes to the database as long as everything is valid
  92. if($generalChangesMade && $valid['username'] && $valid['steamId'] && $valid['email'] && $valid['curPassword']) {
  93. // DB save
  94. $userQueries->updateUser($user);
  95. // Need to update cookie and session values if username is updated
  96. $_SESSION['name'] = $user->getName();
  97. setcookie("gbu", $user->getName(), time()+60*60*24*100, "/"); // 100 days
  98. }
  99. }
  100. // *********************************************
  101. // If the user is updating their password
  102. // *********************************************
  103. if(isset($_POST['updatePassword'])) {
  104. // Current password check
  105. if($user->getPassword() == md5($_POST['cpassword'])) {
  106. $valid['cpassword'] = true;
  107. } else {
  108. $valid['cpassword'] = false;
  109. }
  110. // New Password check
  111. $newpassword = $_POST['npassword'];
  112. // Must have atleast 1 alphanumeric and at least 1 number and be a length of at least 6
  113. $regex = "/^\w*(?=\w*\d)(?=\w*[a-zA-Z])\w*$/";
  114. if(strlen($newpassword) > 5 && preg_match($regex,$newpassword)) {
  115. $valid['npassword'] = true;
  116. } else {
  117. $valid['npassword'] = false;
  118. }
  119. // New Password verification check
  120. $vpassword = $_POST['vpassword'];
  121. // Check if it matches the first password
  122. if($vpassword == $newpassword) {
  123. $valid['vpassword'] = true;
  124. } else {
  125. $valid['vpassword'] = false;
  126. }
  127. // Save changes to the database as long as everything is valid
  128. if($valid['cpassword'] && $valid['npassword'] && $valid['vpassword']) {
  129. // DB save
  130. $passwordChangesMade = true;
  131. $user->setPassword(md5($newpassword)); // Need to md5 the new password
  132. $userQueries->updateUser($user);
  133. // Need to update cookie and session values if username is updated
  134. $_SESSION['password'] = $user->getPassword(); // password should already be md5 encrypted
  135. setcookie("gbp", $user->getPassword(), time()+60*60*24*100, "/"); // 100 days
  136. }
  137. }
  138. ?>
  139. <div class="tborder">
  140. <div id="tableHead">
  141. <div><b>User Profile - General Information</b></div>
  142. </div>
  143. <form action="index.php?page=profile" method="post" id="form">
  144. <table class="bordercolor" width="100%" cellspacing="1" cellpadding="5" border="0" style="margin-top: 1px;">
  145. <tr>
  146. <td class="rowColor1" width="1%" nowrap>Username:</td>
  147. <td class="rowColor1"><input type="text" name="username" value="<?=$user->getName()?>" size="40" maxlength="40" />
  148. <?php if(!$valid['username']) { ?><span class="error">Enter a valid username</span><?php } ?></td>
  149. </tr>
  150. <tr>
  151. <td class="rowColor2" width="1%" nowrap>Steam ID:</td>
  152. <td class="rowColor2"><input name="steamId" id="steamdId" type="text" value="<?=$user->getSteamId()?>" size="25" maxlength="25"/> (must be in <b>STEAM_X:X:XXXXXX</b> format)
  153. <?php if(!$valid['steamId']) { ?><span class="error">Steam ID not in vaild format</span><?php } ?></td>
  154. <tr>
  155. <td class="rowColor1" width="1%" nowrap>Email:</td>
  156. <td class="rowColor1"><input type="text" name="email" size="60" maxlength="80" value="<?=$user->getEmail()?>" />
  157. <?php if(!$valid['email']) { ?><span class="error">Enter a valid email</span><?php } ?></td>
  158. </tr>
  159. </tr>
  160. <td class="rowColor2" width="1%" nowrap><img src="images/bullet_star.png"/> Current Password:</td>
  161. <td class="rowColor2"><input type="password" name="curPassword" value="" size="25" maxlength="25"/>
  162. <?php if(!$valid['curPassword']) { ?><span class="error">Enter a valid password</span><?php } ?></td>
  163. </tr>
  164. <tr>
  165. <td align="left" colspan="3" class="rowColor1">
  166. <input type="submit" value="Update" name="generalProfile" class="button" /></td>
  167. </tr>
  168. </table>
  169. </form>
  170. </div>
  171. <?php
  172. // Display that the changes were successful
  173. if($generalChangesMade) {
  174. ?><h5 class="error">General Information Updated</h5><?php
  175. }
  176. ?>
  177. <?php
  178. // Display an error message if there was any bad input
  179. if($generalErrors) {
  180. ?><h5 class="error">All changes made have been reset due to bad input</h5><?php
  181. }
  182. ?>
  183. <h5><img src="images/bullet_star.png"/> Only required if changing email</h5>
  184. <br/>
  185. <div class="tborder">
  186. <div id="tableHead">
  187. <div><b>User Profile - Change Password</b></div>
  188. </div>
  189. <form action="index.php?page=profile" method="post" id="form">
  190. <table class="bordercolor" width="100%" cellspacing="1" cellpadding="5" border="0" style="margin-top: 1px;">
  191. </tr>
  192. <td class="rowColor1" width="1%" nowrap>Current Password:</td>
  193. <td class="rowColor1"><input type="password" name="cpassword" value="" size="25" maxlength="25"/>
  194. <?php if(!$valid['cpassword']) { ?><span class="error">Enter a valid password</span><?php } ?></td>
  195. </tr>
  196. </tr>
  197. <td class="rowColor2" width="1%" nowrap>New Password:</td>
  198. <td class="rowColor2"><input type="password" name="npassword" value="" size="25" maxlength="25"/>
  199. <?php if(!$valid['npassword']) { ?><span class="error">Enter a valid password</span><?php } ?></td>
  200. </tr>
  201. <tr>
  202. <td class="rowColor1" width="1%" nowrap>Verify New Password:</td>
  203. <td class="rowColor1"><input type="password" name="vpassword" value="" size="25" maxlength="25"/>
  204. <?php if(!$valid['vpassword']) { ?><span class="error">Password mis-match</span><?php } ?></td>
  205. </tr>
  206. <tr>
  207. <td align="left" colspan="3" class="rowColor2">
  208. <input type="hidden" name="nopostpass" value="0" />
  209. <input type="submit" value="Change Password" name="updatePassword" class="button" /></td>
  210. </tr>
  211. </table>
  212. </form>
  213. </div>
  214. <h5>
  215. All password fields in the above section are required for changing a password.<br/>
  216. Passwords must contain at least 1 digit and be at least 6 characters in length.
  217. </h5>
  218. <?php
  219. // Display that the changes were successful
  220. if($passwordChangesMade) {
  221. ?><h5 class="error">Password Updated</h5><?php
  222. }
  223. ?>