Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. <?php
  2. // core configuration
  3. include_once "config/core.php";
  4.  
  5. // set page title
  6. $page_title = "Sign Up";
  7.  
  8. // include login checker
  9. $require_login=false;
  10. include_once "login_checker.php";
  11.  
  12. // include classes
  13. include_once 'config/database.php';
  14. include_once 'objects/user.php';
  15. include_once "libs/php/utils.php";
  16. include_once "libs/php/pw-hashing/passwordLib.php";
  17.  
  18. // get database connection
  19. $database = new Database();
  20. $db = $database->getConnection();
  21.  
  22. // initialize objects
  23. $user = new User($db);
  24. $utils = new Utils();
  25.  
  26. // include page header HTML
  27. include_once "layout_head.php";
  28.  
  29. // if form was posted
  30. if($_POST){
  31.  
  32. // set user email to detect if it already exists
  33. $user->email=$_POST['email'];
  34.  
  35. // check if email already exists
  36. if($user->emailExists()){
  37. echo "<div class="alert alert-danger">";
  38. echo "The email you specified is already registered. Please try to <a href='{$home_url}login'>login.</a>";
  39. echo "</div>";
  40. }
  41.  
  42. else{
  43.  
  44. // set values to object properties
  45. $user->parent_id=0;
  46. $user->firstname=$_POST['firstname'];
  47. $user->lastname=$_POST['lastname'];
  48. $user->contact_number=$_POST['contact_number'];
  49. $user->address=$_POST['address'];
  50. $user->username=$_POST['username'];
  51. $user->password=$_POST['password'];
  52. $user->access_level='Customer';
  53. $user->status=0;
  54.  
  55. // access code for email verification
  56. $access_code=$utils->getToken();
  57. $user->access_code=$access_code;
  58.  
  59. // create the user
  60. if($user->create()){
  61.  
  62. // send confimation email
  63. $send_to_email=$_POST['email'];
  64. $body="Hi {$send_to_email}.<br /><br />";
  65. $body.="Please click the following link to verify your email and login: {$home_url}verify/?access_code={$access_code}";
  66. $subject="Verification Email";
  67.  
  68. // if($utils->sendEmailViaPhpMailerLibrary($send_to_email, $subject, $body)){
  69. if($utils->sendEmailViaPhpMail($send_to_email, $subject, $body)){
  70. echo "<div class="alert alert-info">";
  71. echo "Verification link was sent to your email. Click that link to login.";
  72. echo "</div>";
  73. }
  74.  
  75. else{
  76. echo "<div class="alert alert-danger">";
  77. echo "User was created but unable to send verification email. Please contact admin.";
  78. echo "</div>";
  79. }
  80.  
  81. }else{
  82. echo "<div class="alert alert-danger" role="alert">Unable to register. Please try again.</div>";
  83. }
  84. }
  85. }
  86.  
  87. // if the form wasn't submitted yet, show register form
  88. else{
  89. ?>
  90.  
  91. <form action='register.php' method='post' id='register'>
  92.  
  93. <table class='table table-hover table-responsive table-bordered'>
  94.  
  95. <tr>
  96. <td class='width-30-percent'>Firstname</td>
  97. <td><input type='text' name='firstname' class='form-control' required value="<?php echo isset($_POST['firstname']) ? htmlspecialchars($_POST['firstname'], ENT_QUOTES) : ""; ?>" /></td>
  98. </tr>
  99.  
  100. <tr>
  101. <td>Lastname</td>
  102. <td><input type='text' name='lastname' class='form-control' required value="<?php echo isset($_POST['lastname']) ? htmlspecialchars($_POST['lastname'], ENT_QUOTES) : ""; ?>" /></td>
  103. </tr>
  104.  
  105. <tr>
  106. <td>Email</td>
  107. <td><input type='email' name='email' class='form-control' required value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email'], ENT_QUOTES) : ""; ?>" /></td>
  108. </tr>
  109.  
  110. <tr>
  111. <td>Contact Number</td>
  112. <td><input type='text' name='contact_number' class='form-control' required value="<?php echo isset($_POST['contact_number']) ? htmlspecialchars($_POST['contact_number'], ENT_QUOTES) : ""; ?>" /></td>
  113. </tr>
  114.  
  115. <tr>
  116. <td>Address</td>
  117. <td><textarea name='address' class='form-control' required><?php echo isset($_POST['address']) ? htmlspecialchars($_POST['address'], ENT_QUOTES) : ""; ?></textarea></td>
  118. </tr>
  119.  
  120. <tr>
  121. <td>Username</td>
  122. <td><input type='text' name='username' class='form-control' required value="<?php echo isset($_POST['username']) ? htmlspecialchars($_POST['username'], ENT_QUOTES) : ""; ?>" /></td>
  123. </tr>
  124.  
  125. <tr>
  126. <td>Password</td>
  127. <td><input type='password' name='password' class='form-control' required id='passwordInput'></td>
  128. </tr>
  129.  
  130. <tr>
  131. <td>Confirm Password</td>
  132. <td>
  133. <input type='password' name='confirm_password' class='form-control' required id='confirmPasswordInput'>
  134. <p>
  135. <div class="" id="passwordStrength"></div>
  136. </p>
  137. </td>
  138. </tr>
  139.  
  140. <tr>
  141. <td></td>
  142. <td>
  143. <button type="submit" class="btn btn-primary">
  144. <span class="glyphicon glyphicon-plus"></span> Sign Up
  145. </button>
  146. </td>
  147. </tr>
  148.  
  149. </table>
  150. </form>
  151.  
  152. <?php
  153. }
  154.  
  155. // include page footer HTML
  156. include_once "layout_foot.php";
  157. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement