PageRenderTime 674ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/banned/newuser.php

http://globalban-spanish.googlecode.com/
PHP | 227 lines | 156 code | 27 blank | 44 comment | 56 complexity | 8dd96f60c20428da86133c147a5e5aae 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. include_once(ROOTDIR."/include/database/class.UserQueries.php");
  18. // User specific queries
  19. $userQueries = new UserQueries();
  20. // Make variables empty
  21. $username = "";
  22. $email = "";
  23. $vemail = "";
  24. $password = "";
  25. $vpassword = "";
  26. $steamId = "";
  27. $lan_file = ROOTDIR.'/languages/'.$LANGUAGE.'/lan_newuser.php';
  28. include(file_exists($lan_file) ? $lan_file : ROOTDIR."/languages/English/lan_newuser.php");
  29. $nopost = true; // Flag of whether the form was submitted yet
  30. if(isset($_POST['nopost'])) {
  31. $nopost = $_POST['nopost'];
  32. }
  33. // Boolean values of whether post values are valid
  34. $valid = array("username"=>false,
  35. "steamId"=>false,
  36. "email"=>false,
  37. "vemail"=>false,
  38. "password"=>false,
  39. "vpassword"=>false,
  40. "userCode"=>false);
  41. /**
  42. * Post Data from form
  43. */
  44. // User name
  45. if(isset($_POST['username'])) {
  46. $username = $_POST['username'];
  47. if(!$userQueries->usernameExist($username) && !empty($username)) {
  48. $valid['username'] = true;
  49. }
  50. }
  51. // Steam ID
  52. if(isset($_POST['steamId'])) {
  53. $steamId = $_POST['steamId'];
  54. if(!empty($steamId)) {
  55. if(preg_match("/^STEAM_[01]:[01]:\d{0,10}$/", $steamId)) {
  56. $valid['steamId'] = true;
  57. }
  58. }
  59. }
  60. if(isset($_POST['email'])) {
  61. $email = $_POST['email'];
  62. // take a given email address and split it into the username and domain.
  63. //list($userName, $mailDomain) = split("@", $email);
  64. // Check if the dns is valid
  65. //if(checkdnsrr($mailDomain, "MX")) {
  66. // $valid['email'] = true;
  67. //}
  68. // Simplified version that does not do dns validation
  69. if(!$userQueries->emailExist($email) && !empty($email)) {
  70. if(preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i", $email)) {
  71. $valid['email'] = true;
  72. }
  73. }
  74. }
  75. if(isset($_POST['vemail'])) {
  76. $vemail = $_POST['vemail'];
  77. // Check if it matches the email address
  78. if($vemail == $email) {
  79. $valid['vemail'] = true;
  80. }
  81. }
  82. if(isset($_POST['password'])) {
  83. $password = $_POST['password'];
  84. // Must have atleast 1 alphanumeric and at least 1 number and be a length of at least 6
  85. $regex = "/^\w*(?=\w*\d)(?=\w*[a-zA-Z])\w*$/";
  86. if(strlen($password) > 5 && preg_match($regex,$password)) {
  87. $valid['password'] = true;
  88. }
  89. }
  90. if(isset($_POST['vpassword'])) {
  91. $vpassword = $_POST['vpassword'];
  92. // Check if it matches the first password
  93. if($vpassword == $password) {
  94. $valid['vpassword'] = true;
  95. }
  96. }
  97. // User name
  98. if(isset($_POST['userCode'])) {
  99. $code = $_POST['userCode'];
  100. if(!empty($code)) {
  101. if($config->createUserCode == $code || $config->createSuperCode == $code) {
  102. $valid['userCode'] = true;
  103. }
  104. }
  105. }
  106. // Redirect if everything works
  107. if($valid['username'] && $valid['email'] && $valid['vemail'] && $valid['password'] && $valid['steamId'] && $valid['userCode']) {
  108. // Always add the user as a member
  109. if($userQueries->addUser($username, $password, 4, $steamId, $email)) {
  110. // Email the user
  111. $subject = $config->siteName." ".$LAN_NEWUSER_025." ".$LAN_NEWUSER_026;
  112. $body = "<html><body>";
  113. $body .= $LAN_NEWUSER_022.": ".$username;
  114. $body .= "\n\n";
  115. $body .= "\n\n";
  116. $body .= "<p>".$LAN_NEWUSER_023."</p>";
  117. $body .= "</body></html>";
  118. // To send HTML mail, the Content-type header must be set
  119. $headers = "MIME-Version: 1.0" . "\r\n";
  120. $headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
  121. // Additional headers
  122. $headers .= "From: ".$config->siteName." ".$LAN_NEWUSER_025." <".$config->emailFromHeader.">\r\n";
  123. // Send an email message to those that wish to recieve a notice of a newly added ban
  124. mail($email, $subject, $body, $headers);
  125. header("Location: index.php?page=login&created=1"); // Requires ob_start and ob_flush to do header re-direct
  126. } else {
  127. header("Location: index.php?page=newuser&error=1");
  128. }
  129. }
  130. if($_GET['error'] == 1) {
  131. echo "<h5>".$LAN_NEWUSER_002."</h5>";
  132. }
  133. ?>
  134. <div class="tborder">
  135. <div id="tableHead">
  136. <div><b><?php echo $LAN_NEWUSER_001; ?></b></div>
  137. </div>
  138. <form action="index.php?page=newuser" method="post" id="form">
  139. <table class="bordercolor" width="100%" cellspacing="1" cellpadding="5" border="0" style="margin-top: 1px;">
  140. <tr>
  141. <td class="rowColor1">*<?php echo $LAN_NEWUSER_003; ?>:</td>
  142. <td class="rowColor1"><input type="text" name="username" value="<?php echo $username?>" size="40" maxlength="40" />
  143. <?php if(!$valid['username'] && !$nopost) { ?><span class="error"><?php echo $LAN_NEWUSER_004; ?></span><?php } ?></td>
  144. </tr>
  145. <tr>
  146. <td class="rowColor2">*<?php echo $LAN_NEWUSER_005; ?>:</td>
  147. <td class="rowColor2"><input name="steamId" id="steamdId" type="text" value="<?php echo $steamId?>" size="25" maxlength="25"/> (<?php echo $LAN_NEWUSER_006; ?>)
  148. <?php if(!$valid['steamId'] && !$nopost) { ?><span class="error"><?php echo $LAN_NEWUSER_007; ?></span><?php } ?></td>
  149. </tr>
  150. <tr>
  151. <td class="rowColor1">**<?php echo $LAN_NEWUSER_008; ?>:</td>
  152. <td class="rowColor1"><input type="password" name="password" value="" size="25" maxlength="25"/>
  153. <?php if(!$valid['password'] && !$nopost) { ?><span class="error"><?php echo $LAN_NEWUSER_009; ?></span><?php } ?></td>
  154. </tr>
  155. <tr>
  156. <td class="rowColor2">**<?php echo $LAN_NEWUSER_010; ?>:</td>
  157. <td class="rowColor2"><input type="password" name="vpassword" value="" size="25" maxlength="25"/>
  158. <?php if(!$valid['vpassword'] && !empty($password) && !$nopost) { ?><span class="error"><?php echo $LAN_NEWUSER_011; ?></span><?php } ?></td>
  159. </tr>
  160. <tr>
  161. <td class="rowColor1">*<?php echo $LAN_NEWUSER_012; ?>:</td>
  162. <td class="rowColor1"><input type="text" name="email" value="<?php if(!empty($email)) { echo $email; } ?>" size="60" maxlength="80" />
  163. <?php if(!$valid['email'] && !$nopost) { ?><span class="error"><?php echo $LAN_NEWUSER_013; ?></span><?php } ?></td>
  164. </tr>
  165. <tr>
  166. <td class="rowColor2">*<?php echo $LAN_NEWUSER_014; ?>:</td>
  167. <td class="rowColor2"><input type="text" name="vemail" value="" size="60" maxlength="80" />
  168. <?php if(!$valid['vemail'] && !empty($email) && !$nopost) { ?><span class="error"><?php echo $LAN_NEWUSER_015; ?></span><?php } ?></td>
  169. </tr>
  170. <tr>
  171. <td class="rowColor1">*<?php echo $LAN_NEWUSER_016; ?>:</td>
  172. <td class="rowColor1"><input type="password" name="userCode" value="" />
  173. <?php
  174. if(isset($_POST['submit']))
  175. {
  176. if((!$valid['userCode'] && !empty($code) && !$nopost) || empty($code))
  177. {?>
  178. <span class="error"><?php echo $LAN_NEWUSER_017; ?> </span><?php
  179. }?></td>
  180. <?php
  181. }
  182. ?>
  183. </tr>
  184. <tr>
  185. <td align="left" colspan="3" class="rowColor2">
  186. <input type="hidden" name="nopost" value="0" />
  187. <input type="reset" value="<?php echo $LAN_NEWUSER_021; ?>" class="button" />&nbsp;
  188. <input type="submit" value="<?php echo $LAN_NEWUSER_018; ?>" class="button" /></td>
  189. </tr>
  190. </table>
  191. </form>
  192. </div>
  193. <h5>
  194. * <?php echo $LAN_NEWUSER_019; ?><br />
  195. ** <?php echo $LAN_NEWUSER_020; ?>
  196. </h5>