Guest User

Untitled

a guest
Nov 24th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @author Andrew Murdoch
  5.  * @date 2012-09-13
  6.  * @description This file handles the managment of the sign up form. This file is
  7.  * in charge of sending out the verification email and registering the user in
  8.  * the database
  9.  */
  10.  
  11.     //Include File
  12.     include ('../Classes/user.php');
  13.     include ('../function.php');
  14.  
  15.     //Retrieve form data.
  16.     //GET - user submitted data using AJAX
  17.     //POST - in case user does not support javascript, we'll use POST instead
  18.     $fName    = ($_GET['fName'])       ? $_GET['fName']       : $_POST['fName'];
  19.     $lName    = ($_GET['lName'])       ? $_GET['lName']       : $_POST['lName'];
  20.     $email    = ($_GET['userEmail'])   ? $_GET['userEmail']   : $_POST['userEmail'];
  21.     $password = ($_GET['password'])    ? $_GET['password']    : $_POST['password'];
  22.     $address  = ($_GET['userAddress']) ? $_GET['userAddress'] : $_POST['userAddress'];
  23.     $city     = ($_GET['userCity'])    ? $_GET['userCity']    : $_POST['userCity'];
  24.     $country  = ($_GET['userCountry']) ? $_GET['userCountry'] : $_POST['userCountry'];
  25.     $state    = ($_GET['userState'])   ? $_GET['userState']   : $_POST['userState'];
  26.  
  27.     //flag to indicate which method it uses. If POST set it to 1
  28.     if ($_POST)
  29.     {
  30.         $post=1;
  31.     }
  32.  
  33.    $name = $fName.' '.$lName;
  34.    $errors = NULL;
  35.  
  36.     //Simple server side validation for POST data, of course, you should validate the email
  37.     if( !$name )
  38.     {
  39.         $errors[count($errors)] = 'Please enter your first name.';
  40.     }
  41.  
  42.     if( !$email )
  43.     {
  44.         $errors[count($errors)] = 'Please enter your last name.';
  45.     }
  46.  
  47.     if( !validateEmail( $email ) )
  48.     {
  49.         $errors[count($errors)] = 'Please enter a valid email';
  50.     }
  51.  
  52.     if( !$password )
  53.     {
  54.         $errors[count($errors)] = 'Please enter your email.';
  55.     }
  56.  
  57.     if( !$address )
  58.     {
  59.         $errors[count($errors)] = 'Please enter your passwprd.';
  60.     }
  61.  
  62.     if( !$city )
  63.     {
  64.         $errors[count($errors)] = 'Please enter your address.';
  65.     }
  66.  
  67.     if( !$country )
  68.     {
  69.         $errors[count($errors)] = 'Please select a valid country.';
  70.     }
  71.  
  72.     if( !$state )
  73.     {
  74.         $errors[count($errors)] = 'Please select a valid state.';
  75.     }
  76.  
  77.     if (!$errors) {
  78.         //recipient
  79.         $to = $email;
  80.         //sender
  81.         $from = $email;
  82.  
  83.         //subject and the html message
  84.         $hash = gen_activation_key($email);
  85.         $subject = 'Activation Email From ' . $name;
  86.         $message = '
  87.  
  88.         Thanks for signing up!
  89.         You account has been created, you can login with the following credentials after you activate your account.
  90.  
  91.         -------------------------
  92.         email: '.$email.';
  93.         password: '.$password.';
  94.         --------------------------
  95.  
  96.         Please click this link to activate your account:
  97.  
  98.         localhost/registration/Sign-in/verify.php?email='.$email.'&hash='.$hash.'';
  99.  
  100.         //For windows
  101.         $message = str_replace("\n.", "\n..", $message);
  102.  
  103.         //send the mail
  104.         $result = sendmail($to, $subject, $message, $from);
  105.  
  106.         //Connect to the Database
  107.         if( $newUser = new user($name,$email,$address,$city,$country, $state, $password) )
  108.         {
  109.             //Add the user to the database
  110.             $newUser->registerUser($name,$password,$email,$address,$city,$country,$state);
  111.             $newUser->db=NULL;
  112.         }
  113.  
  114.         //if POST was used, display the message straight away
  115.         if ($_POST)
  116.         {
  117.             if ($result)
  118.             {
  119.                 echo 'Thank you! We have received your message.';
  120.             }          
  121.             else
  122.             {
  123.                 echo 'Sorry, unexpected error. Please try again later';
  124.             }
  125.             //else if GET was used, return the boolean value so that
  126.             //ajax script can react accordingly
  127.             //1 means success, 0 means failed
  128.         }
  129.         else
  130.         {
  131.             echo $result;  
  132.         }
  133.  
  134.     //if the errors array has values
  135.     }
  136.     else
  137.     {
  138.         //display the errors message
  139.         for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
  140.         echo '<a href="index.php">Back</a>';
  141.         exit;
  142.     }
Add Comment
Please, Sign In to add comment