Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['submit'])){
- if (!isset($_POST['username'])) $error[] = "Please fill out all fields";
- if (!isset($_POST['email'])) $error[] = "Please fill out all fields";
- if (!isset($_POST['password'])) $error[] = "Please fill out all fields";
- $username = $_POST['username'];
- if(!$user->isValidUsername($username)){
- $error[] = 'Usernames must be at least 3 Alphanumeric characters';
- } else {
- $stmt = $db->prepare('SELECT username FROM users WHERE username = :username');
- $stmt->execute(array(':username' => $username));
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- if(!empty($row['username'])){
- $error[] = 'Username provided is already in use.';
- }
- }
- if(strlen($_POST['password']) < 3){
- $error[] = 'Password is too short.';
- }
- if(strlen($_POST['passwordConfirm']) < 3){
- $error[] = 'Confirm password is too short.';
- }
- if($_POST['password'] != $_POST['passwordConfirm']){
- $error[] = 'Passwords do not match.';
- }
- $email = htmlspecialchars_decode($_POST['email'], ENT_QUOTES);
- if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
- $error[] = 'Please enter a valid email address';
- } else {
- $stmt = $db->prepare('SELECT email FROM users WHERE email = :email');
- $stmt->execute(array(':email' => $email));
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- if(!empty($row['email'])){
- $error[] = 'Email provided is already in use.';
- }
- }
- if(!isset($error)){
- $hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);
- $activation = md5(uniqid(rand(),true));
- try {
- $stmt = $db->prepare('INSERT INTO users (username,password,email,active) VALUES (:username, :password, :email, :active)');
- $stmt->execute(array(
- ':username' => $username,
- ':password' => $hashedpassword,
- ':email' => $email,
- ':active' => $activation
- ));
- $id = $db->lastInsertId('userID');
- $to = $_POST['email'];
- $subject = "Account Confirmation";
- $body = "<p>Thank you for signing up\</p>
- <p>To activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activation'>".DIR."activate.php?x=$id&y=$activation</a></p>
- <p>Regards Site Admin</p>";
- $mail = new Mail();
- $mail->setFrom(SITEEMAIL);
- $mail->addAddress($to);
- $mail->subject($subject);
- $mail->body($body);
- $mail->send();
- //redirect to index page
- header('Location: index.php?action=joined');
- exit;
- //else catch the exception and show the error.
- } catch(PDOException $e) {
- $error[] = $e->getMessage();
- }
- if(!isset($error)){ $error = array(); }
- }
- }
- ?>
- <div class="tab-pane" id="registerTab">
- <div class="modal-body">
- <form role="form" method="post" action="" autocomplete="off">
- <?php
- if(isset($error)){
- foreach($error as $error){
- echo '<p class="bg-danger">'.$error.'</p>';
- }
- }
- //if action is joined show sucess
- if(isset($_GET['action']) && $_GET['action'] == 'joined'){
- echo "<h2 class='bg-success'>Registration successful, please check your email to activate your account.</h2>";
- }
- ?>
- <div class="form-group">
- <input type="email" name="email" id="email" class="form-control" placeholder="Email" required="required" value="<?php if(isset($error)){ echo htmlspecialchars($_POST['email'], ENT_QUOTES); } ?>" tabindex="1">
- </div>
- <div class="form-group">
- <input type="text" name="username" id="username" class="form-control"placeholder="User Name" required="required" value="<?php if(isset($error)){ echo htmlspecialchars($_POST['username'], ENT_QUOTES); } ?>" tabindex="2">
- </div>
- <div class="form-group">
- <input type="password" name="password" id="password"class="form-control" placeholder="Password" required="required" tabindex="3">
- </div>
- <div class="form-group">
- <input type="password" name="passwordConfirm" id="passwordConfirm" class="form-control" placeholder="Confirm Password" required="required" tabindex="4">
- </div>
- <div class="form-group">
- <button type="submit" name="submit" class="btn btn-primary btn-lg btn-block login-btn" tabindex="5">Register</button>
- </div>
- </form>
- </div>
- <div class="modal-footer">
- <div class="login-footer">
- <span class="login-footer-item">
- Have an Account? <a href="#registerTab" data-target="#registerTab">Sign in</a>
- </span>
- </div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement