Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Andrew Murdoch
- * @date 2012-09-13
- * @description This file handles the managment of the sign up form. This file is
- * in charge of sending out the verification email and registering the user in
- * the database
- */
- //Include File
- include ('../Classes/user.php');
- include ('../function.php');
- //Retrieve form data.
- //GET - user submitted data using AJAX
- //POST - in case user does not support javascript, we'll use POST instead
- $fName = ($_GET['fName']) ? $_GET['fName'] : $_POST['fName'];
- $lName = ($_GET['lName']) ? $_GET['lName'] : $_POST['lName'];
- $email = ($_GET['userEmail']) ? $_GET['userEmail'] : $_POST['userEmail'];
- $password = ($_GET['password']) ? $_GET['password'] : $_POST['password'];
- $address = ($_GET['userAddress']) ? $_GET['userAddress'] : $_POST['userAddress'];
- $city = ($_GET['userCity']) ? $_GET['userCity'] : $_POST['userCity'];
- $country = ($_GET['userCountry']) ? $_GET['userCountry'] : $_POST['userCountry'];
- $state = ($_GET['userState']) ? $_GET['userState'] : $_POST['userState'];
- //flag to indicate which method it uses. If POST set it to 1
- if ($_POST)
- {
- $post=1;
- }
- $name = $fName.' '.$lName;
- $errors = NULL;
- //Simple server side validation for POST data, of course, you should validate the email
- if( !$name )
- {
- $errors[count($errors)] = 'Please enter your first name.';
- }
- if( !$email )
- {
- $errors[count($errors)] = 'Please enter your last name.';
- }
- if( !validateEmail( $email ) )
- {
- $errors[count($errors)] = 'Please enter a valid email';
- }
- if( !$password )
- {
- $errors[count($errors)] = 'Please enter your email.';
- }
- if( !$address )
- {
- $errors[count($errors)] = 'Please enter your passwprd.';
- }
- if( !$city )
- {
- $errors[count($errors)] = 'Please enter your address.';
- }
- if( !$country )
- {
- $errors[count($errors)] = 'Please select a valid country.';
- }
- if( !$state )
- {
- $errors[count($errors)] = 'Please select a valid state.';
- }
- if (!$errors) {
- //recipient
- $to = $email;
- //sender
- $from = $email;
- //subject and the html message
- $hash = gen_activation_key($email);
- $subject = 'Activation Email From ' . $name;
- $message = '
- Thanks for signing up!
- You account has been created, you can login with the following credentials after you activate your account.
- -------------------------
- email: '.$email.';
- password: '.$password.';
- --------------------------
- Please click this link to activate your account:
- localhost/registration/Sign-in/verify.php?email='.$email.'&hash='.$hash.'';
- //For windows
- $message = str_replace("\n.", "\n..", $message);
- //send the mail
- $result = sendmail($to, $subject, $message, $from);
- //Connect to the Database
- if( $newUser = new user($name,$email,$address,$city,$country, $state, $password) )
- {
- //Add the user to the database
- $newUser->registerUser($name,$password,$email,$address,$city,$country,$state);
- $newUser->db=NULL;
- }
- //if POST was used, display the message straight away
- if ($_POST)
- {
- if ($result)
- {
- echo 'Thank you! We have received your message.';
- }
- else
- {
- echo 'Sorry, unexpected error. Please try again later';
- }
- //else if GET was used, return the boolean value so that
- //ajax script can react accordingly
- //1 means success, 0 means failed
- }
- else
- {
- echo $result;
- }
- //if the errors array has values
- }
- else
- {
- //display the errors message
- for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
- echo '<a href="index.php">Back</a>';
- exit;
- }
Add Comment
Please, Sign In to add comment