PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/register/index.php

https://github.com/beakid/md
PHP | 154 lines | 149 code | 5 blank | 0 comment | 15 complexity | 394969971a9fdddcc7a2c6086b988ff4 MD5 | raw file
  1. <?
  2. include("../session_mysql.php");
  3. include("../functions.php");
  4. $registered = false;
  5. $activated = false;
  6. if($_POST["action"] == "register_user")
  7. {
  8. if(!$_POST["user_name"])
  9. {
  10. $error["user_name"] = errormess("Choose a username");
  11. }
  12. else
  13. {
  14. if(mysql_num_rows(mysql_query("SELECT user_name FROM md_user WHERE user_name = '$_POST[user_name]'")))
  15. {
  16. $error["user_name"] = errormess("Username already exists");
  17. }
  18. }
  19. if(!$_POST["user_city"])
  20. {
  21. $error["user_city"] = errormess("Enter your city");
  22. }
  23. if(!$_POST["user_email"])
  24. {
  25. $error["user_email"] = errormess("Enter your email");
  26. }
  27. elseif(!preg_match('/^[_a-z0-9-]+(?:\.[_a-z0-9-]+)*@(?:[-a-z0-9-]+\.)+(?:[a-z]{2,7})$/i', $_POST["user_email"]))
  28. {
  29. $error["user_email"] = errormess("Wrong email format");
  30. }
  31. if(!$_POST["user_password"])
  32. {
  33. $error["user_password"] = errormess("Choose a password");
  34. }
  35. elseif(!$_POST["user_password2"])
  36. {
  37. $error["user_password"] = errormess("Confirm your password");
  38. }
  39. elseif($_POST["user_password2"] != $_POST["user_password"])
  40. {
  41. $error["user_password"] = errormess("Passwords does not match");
  42. }
  43. if($_POST["user_dci"] && !preg_match ("/^[0-9]+$/", $_POST["user_dci"]))
  44. {
  45. $error["user_dci"] = errormess("Only numbers");
  46. }
  47. if(!count($error))
  48. {
  49. $code = "asdfijv".rand(1,100);
  50. mysql_query("INSERT INTO md_user (user_name, user_password, user_email, user_dci, user_country, user_city, user_code)
  51. VALUES ('".addslashes($_POST[user_name])."','$_POST[user_password]','$_POST[user_email]','$_POST[user_dci]','".strtolower($_POST[user_country])."','".addslashes($_POST[user_city])."','$code')");
  52. $id = mysql_insert_id();
  53. $message = "Welcome to MagicDraft!
  54. Your account has been created. To be able to login and start drafting you first need to activate the account by clicking on this link:
  55. $path/register/?activate=".$id."&code=".$code."
  56. Welcome!";
  57. mail($_POST["user_email"], "MagicDraft - Your account has been created", $message, "From: MagicDraft <mail@magicdraft.net>\n"."Reply-To: mail@magicdraft.net\n"."X-Sender: mail@magicdraft.net\n"."Return-Path: mail@magicdraft.net");
  58. $registered = true;
  59. }
  60. }
  61. elseif($_GET["activate"] && $_GET["code"])
  62. {
  63. mysql_query("UPDATE md_user SET user_active = 1 WHERE pk_user_id = '$_GET[username]' AND code = '$_GET[code]'");
  64. $activated = true;
  65. }
  66. ?>
  67. <?=printHeader("MagicDraft - Register","register")?>
  68. <div id="content">
  69. <div id="left">
  70. <div class="box olive welcome_box">
  71. <img src="<?=$path;?>/images/header_welcome.png" class="headerpic" alt="Welcome!" />
  72. <p class="text">Can you make the right picks? Improve your skills in drafting Magic the Gathering here with us!
  73. Start ripping those packs right now.
  74. </p>
  75. </div>
  76. </div>
  77. <div id="middle">
  78. <?
  79. if($activated)
  80. {
  81. ?>
  82. <h1><span class="orange">Account activated!</span></h1>
  83. <p class="text"><br />Your account is now active. Login with your username and password in the right top corner.</p>
  84. <?
  85. }
  86. elseif($registered)
  87. {
  88. ?>
  89. <h1><span class="orange">Congratulations!</span> Your account has been created</h1>
  90. <p class="text"><br />An email with an activation link has been sent to <?=$_POST["user_email"];?>.
  91. Click the link to start using MagicDraft.net. Welcome!</p>
  92. <?
  93. }
  94. else
  95. {
  96. if(!$_POST["user_country"]) $user_country = "BE"; else $user_country = $_POST["user_country"];
  97. ?>
  98. <h1><span class="orange">Registration</span> Create your account</h1>
  99. <div id="registerform">
  100. <form action="index.php" method="post">
  101. <input type="hidden" name="action" value="register_user">
  102. <table>
  103. <tr>
  104. <td>Username</td>
  105. <td><input type="text" class="textfield" name="user_name" value="<?=$user_name;?>" /><?=$error["user_name"];?></td>
  106. </tr>
  107. <tr>
  108. <td>Email</td>
  109. <td><input type="text" class="textfield" name="user_email" value="<?=$user_email;?>" /><?=$error["user_email"];?></td>
  110. </tr>
  111. <tr>
  112. <td>Password</td>
  113. <td><input type="password" class="textfield" name="user_password" value="<?=$user_password;?>" /><?=$error["user_password"];?></td>
  114. </tr>
  115. <tr>
  116. <td>Confirm</td>
  117. <td><input type="password" class="textfield" name="user_password2" value="<?=$user_password2;?>" /></td>
  118. </tr>
  119. <tr>
  120. <td>DCI#</td>
  121. <td><input type="text" class="textfield" name="user_dci" value="<?=$user_dci;?>" /><?=$error["user_dci"];?></td>
  122. </tr>
  123. <tr>
  124. <td>Country</td>
  125. <td><img id="user_country_image" style="vertical-align: middle; margin-left: 12px;" src="../images/flags/<?=strtolower($user_country);?>.png" alt="" />
  126. <select name="user_country" onchange="$('user_country_image').src = '../images/flags/' + this.value + '.png';">
  127. <?=countrylist($user_country);?>
  128. </select>
  129. <tr>
  130. <td>City</td>
  131. <td><input type="text" class="textfield" name="user_city" value="<?=$user_city;?>" /><?=$error["user_city"];?></td>
  132. </tr>
  133. <tr>
  134. <td></td>
  135. <td><br /><input type="image" src="<?=$path;?>/images/button_register.png" value="submit" /></td>
  136. </tr>
  137. </table>
  138. </form>
  139. </div>
  140. <?
  141. }
  142. ?>
  143. </div>
  144. <div id="right">
  145. </div>
  146. <div class="breaker"></div>
  147. </div>
  148. </body>
  149. </html>