Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // include common.inc.php
- include 'core/common.inc.php';
- // show header / add title
- showHeader('Registration');
- // protect page from users already logged in
- protect();
- // turn off error_reporting
- error_reporting(0);
- ?>
- <center>
- <form enctype="multipart/form-data" action="" method="post" class="register_module">
- <h2 style="text-align:left;font-family:'Roboto',sans-serif;">Account Credentials<span style="font-size:12px;font-weight:400;"> (required)</span></h2>
- <div class="account_credentials">
- <input class="register_module protect_from_spaces" type="text" name="username" placeholder="choose a username*" maxlength="30" required><br />
- <input class="register_module protect_from_spaces" type="email" name="email" placeholder="email address*" required><br />
- <div class="row_inline">
- <input class="register_module input protect_from_spaces" type="password" name="password" placeholder="password*" maxlength="18" required>
- <input class="register_module input protect_from_spaces" type="password" name="cpassword" placeholder="confirm password*" maxlength="18" required><br />
- </div>
- </div>
- <br />
- <!-- here add user details section (name, avatar, birthday, etc...) -->
- <h2 style="text-align:left;font-family:'Roboto',sans-serif;">Account Details<span style="font-size:12px;font-weight:400;"> (optional)</span></h2>
- <br />
- <div class="account_details">
- <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Name:<span style="font-size:12px;font-weight:400;"> (required)</span></p>
- <input class="register_module_short protect_from_spaces" style="margin-right:1%;" type="text" name="first_name" placeholder="first name*" required />
- <input class="register_module_short protect_from_spaces" type="text" name="last_name" placeholder="last name" />
- <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Birthday:</p>
- <input style="margin-top:-10px;" class="register_module protect_from_spaces" type="date" name="birthday" />
- <p style="text-align:left;font-family:'Roboto',sans-serif;font-weight:400;">Social Link(s):</p>
- <input class="register_module protect_from_spaces" type="text" style="margin-top:-10px;" type="url" name="steam_profile" placeholder="steam profile (http://www.steamcommunity.com/id/lowheartrate/)" />
- <input class="register_module protect_from_spaces" type="text" name="twitter_profile" placeholder="twitter profile (https://twitter.com/lowheartrate)" />
- <input class="register_module protect_from_spaces" type="text" name="facebook_profile" placeholder="facebook profile (https://www.facebook.com/officiallowheartrate)" />
- <input class="register_module protect_from_spaces" type="text" name="instagram_profile" placeholder="instagram profile (https://instagram.com/lowheartrate)" />
- <!-- image upload for avatar... -->
- <div class="image_uploader">
- <h2 style="text-align:left;font-family:'Roboto',sans-serif;">✌ Avatar Uploader</h2><br />
- <p style="margin-top:-20px;font-size:12px;text-align:left;">Select image to upload:</p>
- <div style="text-align:left;font-size:12px;margin-top:-5px;margin-bottom:25px;">
- <input type="file" name="avatar" class="" />
- </div>
- </div>
- </div>
- <!-- check errors in registration -->
- <?php checkRegisterErrors(); ?>
- <br />
- <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>
- <div class="g-recaptcha pull-right" data-sitekey="6Levrg4TAAAAAN-pL6Xl2tndj3ZDn5nJ3PRUhMV-"></div><br />
- <br />
- <button type="submit" name="submit_registration" class="btn-register" style="margin-top:10px;">sign up</button>
- </form>
- </center>
- <?php
- // checks registration errors...
- function checkRegisterErrors() {
- if(isset($_POST['submit_registration'])){
- require 'findConflict.php';
- $username = $_POST['username'];
- $password = $_POST['password'];
- $cpassword = $_POST['cpassword'];
- $email = $_POST['email'];
- $hash = password_hash($password, PASSWORD_DEFAULT);
- $query = dbConnect()->prepare("SELECT email, username FROM users WHERE username = :username OR email = :email");
- $query->bindParam(':username', $username);
- $query->bindParam(':email', $email);
- $query->execute();
- $conflictingItems = [];
- while ( $result = $query->fetch( PDO::FETCH_ASSOC ) ) {
- $conflictingItems[] = $result;
- }
- // for checking checkGoogleCaptcha() function!!
- require_once 'core/recaptchalib.php';
- if(isset($_POST['g-recaptcha-response']))
- $captcha = $_POST['g-recaptcha-response'];
- $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Levrg4TAAAAAFmjcgKW8kDakmXTiBhmiCnUMchD&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
- if ( count ($conflictingItems) == 1 ) {
- switch ( getConflict($conflictingItems, $username, $email) ) {
- case 1:
- // username conflict
- echo "<p class='error'>username taken</p>";
- break;
- case 2:
- // Email conflict
- echo "<p class='error'>email already in use</p>";
- break;
- case 3:
- // email & username conflict
- echo '<p class="error">username & email in use</p>';
- break;
- }
- } elseif ( count($conflictingItems) == 2 ) {
- echo 'username & email already in use';
- // check if passwords match!
- } elseif ($password != $cpassword) {
- echo '<p class="error">passwords do not match</p>';
- // make sure password is between 8 - 16 characters
- } elseif (strlen($password) < 8 OR strlen($password) > 16) {
- echo '<p class="error">password must be between 8 & 16 characters</p>';
- // checks to make sure google recaptcha was posted!
- } elseif (!$captcha) {
- echo '<p class="error">please complete the captcha</p>';
- } elseif($response['success'] == false) {
- echo '<p class="error">you are a robot</p>';
- } else {
- // require config.php to get maximum file size --> $maximum_avatar_file_size = '125000';
- // to get avatars directory --> $avatars_directory = 'includes/uploads/avatars';
- require 'core/config.php';
- // need for file upload query & query to insert fields into database..
- $activation_id = uniqid(true);
- // file upload stuff... ONLY NEEDED FOR TESTING PURPOSES!
- // var_dump($_FILES);
- // move uploaded file to directory (includes/uploads/avatar)
- $upload_directory = $avatars_directory;
- // sets $image & gets image type, name, tmp_name
- $image = $_FILES['avatar'];
- $image_name = $_FILES['avatar']['name'];
- $image_tmp_name = $_FILES['avatar']['tmp_name'];
- $image_size = $_FILES['avatar']['size'];
- $image_type = $_FILES['avatar']['type'];
- // set file name (make it unique)
- $file_name = $activation_id . $image_name;
- // finds extension of file uploaded...
- $image_extension = strtolower(pathinfo($_FILES['avatar']['name'],PATHINFO_EXTENSION));
- // allowed extensions of file uploaded...
- $valid_image_extensions = array('jpeg', 'jpg', 'png', 'gif');
- // if image extension is a valid image extension...
- if (in_array($image_extension, $valid_image_extensions)) {
- if ($image_size > $maximum_avatar_file_size) {
- echo '<p class="error">error; file size is too large! Maximum file size is ' .$maximum_avatar_file_size. ' bytes. <a href="register.php">Retry Registration</a></p>';
- exit();
- } else {
- // move the file to desired directory ($upload_directory)
- move_uploaded_file($image_tmp_name, "$upload_directory/$file_name");
- }
- }
- // query to insert fields into database...
- //$activation_id = uniqid(true);
- $query = dbConnect()->prepare("INSERT INTO users (username, password, email, activated, activation_id, avatar) VALUES (:username, :password, :email, :activated, :activation_id, :avatar)");
- $query->bindParam(':username', $username);
- $query->bindParam(':email', $email);
- $query->bindParam(':password', $hash);
- $query->bindValue(':activated', "0");
- $query->bindValue(':activation_id', $activation_id);
- $query->bindValue(':avatar', $file_name);
- $query->execute();
- // set variables for optional fields...
- $firstName = $_POST['first_name'];
- $lastName = $_POST['last_name'];
- $birthday = $_POST['birthday'];
- $steam_profile = $_POST['steam_profile'];
- $twitter_profile = $_POST['twitter_profile'];
- $facebook_profile = $_POST['facebook_profile'];
- $instagram_profile = $_POST['instagram_profile'];
- // update user_details database
- $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)");
- $query2->bindParam(':firstName', $firstName);
- $query2->bindParam(':lastName', $lastName);
- $query2->bindParam(':birthday', $birthday);
- $query2->bindParam(':steam', $steam_profile);
- $query2->bindParam(':twitter', $twitter_profile);
- $query2->bindParam(':facebook', $facebook_profile);
- $query2->bindParam(':instagram', $instagram_profile);
- $query2->execute();
- // query to add image name to database to echo later on...
- /*
- $add_image_to_database = dbConnect()->prepare("INSERT INTO users (avatar) VALUES (:avatar)");
- $add_image_to_database->bindParam(':avatar', $file_name);
- $add_image_to_database->execute();
- */
- // send email verification
- require 'core/config.php';
- $subject = $url . 'Registration Confirmation';
- $link = 'http://' . $url. "/activate.php?activation_id=" . $activation_id;
- $message = 'Thanks for registering with us! Please verify your account at' . $link . ' so you can login.';
- $headers = 'From: ' .$contact_email;
- mail($email/* <-- Who its being sent to */, $subject, $message, $headers);
- echo '<p class="info">registration successful, please verify email before logging in.</p>';
- header('refresh:5;url=index.php');
- echo '<p class="info">if you are not redirected, try to <a href="index.php">refresh</a> your page.</p>';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement