Advertisement
lowheartrate

register.php

Nov 22nd, 2016
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.56 KB | None | 0 0
  1. <?php
  2. // include common.inc.php
  3. include 'core/common.inc.php';
  4. // show header / add title
  5. showHeader('Registration');
  6. // protect page from users already logged in
  7. protect();
  8. // turn off error_reporting
  9. // error_reporting(0);
  10. ?>
  11.  
  12. <center>
  13.   <form method="POST" class="register_module">
  14.  
  15.     <h2 style="text-align:left;font-family:'Roboto',sans-serif;">Account Credentials<span style="font-size:12px;font-weight:400;"> (required)</span></h2>
  16.  
  17.     <div class="account_credentials">
  18.       <input class="register_module protect_from_spaces" type="text" name="username" placeholder="choose a username*" maxlength="30" required><br />
  19.       <input class="register_module protect_from_spaces" type="email" name="email" placeholder="email address*" required><br />
  20.  
  21.       <div class="row_inline">
  22.         <input class="register_module input protect_from_spaces" type="password" name="password" placeholder="password*" maxlength="18" required>
  23.         <input class="register_module input protect_from_spaces" type="password" name="cpassword" placeholder="confirm password*" maxlength="18" required><br />
  24.       </div>
  25.     </div>
  26.       <br />
  27.  
  28.       <!-- here add user details section (name, avatar, birthday, etc...) -->
  29.       <h2 style="text-align:left;font-family:'Roboto',sans-serif;">Account Details<span style="font-size:12px;font-weight:400;"> (optional)</span></h2>
  30.  
  31.       <br />
  32.       <div class="account_details">
  33.         <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Name:</p>
  34.         <input class="register_module_short protect_from_spaces" style="margin-right:1%;" type="text" name="first_name" placeholder="first name" />
  35.         <input class="register_module_short protect_from_spaces" type="text" name="last_name" placeholder="last name" />
  36.  
  37.         <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Birthday:</p>
  38.         <input style="margin-top:-10px;" class="register_module protect_from_spaces" type="date" name="birthday" />
  39.  
  40.         <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Social Link(s):</p>
  41.         <input class="register_module protect_from_spaces" style="margin-top:-10px;" type="url" name="steam_profile" placeholder="steam profile (http://www.steamcommunity.com/id/lowheartrate/)" />
  42.         <input class="register_module protect_from_spaces" type="url" name="twitter_profile" placeholder="twitter profile (https://twitter.com/lowheartrate)" />
  43.         <input class="register_module protect_from_spaces" type="url" name="facebook_profile" placeholder="facebook profile (https://www.facebook.com/officiallowheartrate)" />
  44.         <input class="register_module protect_from_spaces" type="url" name="instagram_profile" placeholder="instagram profile (https://instagram.com/lowheartrate)" />
  45.  
  46.         <!-- image upload for avatar... -->
  47.         <div class="image_uploader">
  48.           <h2 style="text-align:left;font-family:'Roboto',sans-serif;">✌ Avatar Uploader</h2><br />
  49.  
  50.           <p style="margin-top:-20px;font-size:12px;text-align:left;">Select image to upload:</p>
  51.           <div style="text-align:left;font-size:12px;margin-top:-5px;margin-bottom:25px;">
  52.             <input type="file" name="avatar" />
  53.           </div>
  54.         </div>
  55.       </div>
  56.  
  57.       <!-- check errors in registration -->
  58.       <?php checkRegisterErrors(); ?>
  59.  
  60.       <br />
  61.       <p class="pull-left" style="max-width:50%;">by signing up, you agree to our <a href="#">terms</a> and that you have read our <a href="#">privacy policy</a> and <a href="#">content policy</a>.</p>
  62.       <div class="g-recaptcha pull-right" data-sitekey="6Levrg4TAAAAAN-pL6Xl2tndj3ZDn5nJ3PRUhMV-"></div><br />
  63.  
  64.       <br />
  65.  
  66.       <button type="submit" class="btn-register" style="margin-top:10px;">sign up</button>
  67.   </form>
  68. </center>
  69.  
  70. <?php
  71. // checks registration errors...
  72. function checkRegisterErrors() {
  73.   if(isset($_POST['username'], $_POST['password'])){
  74.       require 'findConflict.php';
  75.       $username = $_POST['username'];
  76.       $password = $_POST['password'];
  77.       $cpassword = $_POST['cpassword'];
  78.       $email = $_POST['email'];
  79.       $avatar = $_POST['avatar'];
  80.       $hash = password_hash($password, PASSWORD_DEFAULT);
  81.       $query = dbConnect()->prepare("SELECT email, username FROM users WHERE username = :username OR email = :email");
  82.       $query->bindParam(':username', $username);
  83.       $query->bindParam(':email', $email);
  84.       $query->execute();
  85.       $conflictingItems = [];
  86.       while ( $result = $query->fetch( PDO::FETCH_ASSOC ) ) {
  87.           $conflictingItems[] = $result;
  88.       }
  89.       // for checking checkGoogleCaptcha() function!!
  90.       require_once 'core/recaptchalib.php';
  91.       if(isset($_POST['g-recaptcha-response']))
  92.       $captcha = $_POST['g-recaptcha-response'];
  93.       $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Levrg4TAAAAAFmjcgKW8kDakmXTiBhmiCnUMchD&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
  94.  
  95.       if ( count ($conflictingItems) == 1 ) {
  96.         switch ( getConflict($conflictingItems, $username, $email) ) {
  97.             case 1:
  98.             // username conflict
  99.             echo "<p class='error'>username taken</p>";
  100.             break;
  101.             case 2:
  102.             // Email conflict
  103.             echo "<p class='error'>email already in use</p>";
  104.             break;
  105.             case 3:
  106.             // email & username conflict
  107.             echo '<p class="error">username & email in use</p>';
  108.             break;
  109.         }
  110.       } elseif ( count($conflictingItems) == 2 ) {
  111.         echo 'username & email already in use';
  112.  
  113.       // check if passwords match!
  114.       } elseif ($password != $cpassword) {
  115.         echo '<p class="error">passwords do not match</p>';
  116.  
  117.       // make sure password is between 8 - 16 characters
  118.       } elseif (strlen($password) < 8 OR strlen($password) > 16) {
  119.         echo '<p class="error">password must be between 8 & 16 characters</p>';
  120.  
  121.       // checks to make sure google recaptcha was posted!
  122.       } elseif (!$captcha) {
  123.         echo '<p class="error">please complete the captcha</p>';
  124.       } elseif($response['success'] == false) {
  125.         echo '<p class="error">you are a robot</p>';
  126.  
  127.  
  128.       } else {
  129.         $activation_id = uniqid(true);
  130.         $query = dbConnect()->prepare("INSERT INTO users (username, password, email, activated, activation_id, avatar) VALUES (:username, :password, :email, :activated, :activation_id, :avatar)");
  131.         $query->bindParam(':username', $username);
  132.         $query->bindParam(':email', $email);
  133.         $query->bindParam(':avatar', $avatar);
  134.         $query->bindParam(':password', $hash);
  135.         $query->bindValue(':activated', "0");
  136.         $query->bindValue(':activation_id', $activation_id);
  137.         $query->execute();
  138.  
  139.         // set variables for optional fields...
  140.         $firstName = $_POST['first_name'];
  141.         $lastName = $_POST['last_name'];
  142.         $birthday = $_POST['birthday'];
  143.         $steam = $_POST['steam_profile'];
  144.         $twitter = $_POST['twitter_profile'];
  145.         $facebook = $_POST['facebook_profile'];
  146.         $instagram = $_POST['instagram_profile'];
  147.  
  148.         // update user_details database
  149.         $query2 = dbConnect()->prepare("INSERT INTO user_details (first_name, last_name, birthday, steam_profile, twitter_profile, facebook_profile, instagram_profile) VALUES (:firstName, :lastName, :birthday, :steam, :twitter, :facebook, :instagram)");
  150.         $query2->bindParam(':firstName', $firstName);
  151.         $query2->bindParam(':lastName', $lastName);
  152.         $query2->bindParam(':birthday', $birthday);
  153.         $query2->bindParam(':steam', $steam_profile);
  154.         $query2->bindParam(':twitter', $twitter_profile);
  155.         $query2->bindParam(':facebook', $facebook_profile);
  156.         $query2->bindParam(':instagram', $instagram_profile);
  157.         $query2->execute();
  158.  
  159.         // send email verification
  160.         require 'core/config.php';
  161.         $subject = $url . 'Registration Confirmation';
  162.         $link = 'http://' . $url. "/activate.php?activation_id=" . $activation_id;
  163.         $message = 'Thanks for registering with us! Please verify your account at' . $link . ' so you can login.';
  164.         $headers = 'From: ' .$contact_email;
  165.         mail($email/* <-- Who its being sent to */, $subject, $message, $headers);
  166.         echo '<p class="info">registration successful, please verify email before logging in.</p>';
  167.  
  168.         header('refresh:5;url=index.php');
  169.  
  170.         echo '<p class="info">if you are not redirected, try to <a href="index.php">refresh</a> your page.</p>';
  171.       }
  172.   }
  173. }
  174. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement