Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.47 KB | None | 0 0
  1. <?php
  2.  
  3. include_once('class_user.php');
  4.  
  5.     $userObject = new user();
  6.    
  7. if(!$userObject->checkLogin()){
  8.  
  9. include_once('class_inputValidation.php');
  10.  
  11. if(isset($_POST['userName']) && isset($_POST['userPassword'])){
  12.     $validate = new inputValidation();
  13.  
  14.     $rules = array(
  15.             'userName' => array('type' => 'text', 'name' => 'Username', 'required' => true,
  16.                                     'trim' => true, 'min' => '3', 'max' => '30' ),
  17.             'userPassword' => array('type' => 'text', 'name' => 'Password', 'required' => true,
  18.                                     'trim' => true, 'min' => '3', 'max' => '30' )
  19.             );
  20.  
  21.     $validate->addUserInput($_POST);
  22.  
  23.     $validate->addValidationRules($rules);
  24.  
  25.     $validate->startValidation();
  26.    
  27. }
  28.  
  29. if(!isset($_POST['userName']) && !isset($_POST['userPassword']) ||  
  30.     !empty($validate->inputErrors)){
  31. ?>
  32.  
  33. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  34. <p>User Name:
  35. <input type="text" name="userName" size="10"
  36. value="<?php echo $validate->inputValidated['userName']; ?>">
  37. <span class="error">* <?php echo $validate->inputErrors['userName']; ?></span></p>
  38. <p>Password:
  39. <input type="password" name="userPassword" size="10"
  40. value="<?php echo $validate->inputValidated['userPassword']; ?>">
  41. <span class="error">* <?php echo $validate->inputErrors['userPassword']; ?></span></p>
  42. <input type="submit" value="Login">
  43. </form>
  44.  
  45. <?php
  46. }
  47. else{
  48.  
  49. include_once('class_sqlGenerator.php');
  50. include_once('class_PDOConfig.php');
  51.  
  52.     $userObject->userName = $validate->inputValidated['userName'];
  53.     $userObject->userPassword = $validate->inputValidated['userPassword'];
  54.     $userObject->userEmail = $validate->inputValidated['userEmail'];
  55.    
  56.     $db = new PDOV('localhost', 'OOP', 'yoyo', 'OOP');
  57.    
  58.     $dbQuery = new sqlGenerator();
  59.    
  60.     $dbQuery->table = "`usersExample`";
  61.    
  62.     $data = array(
  63.         '`userName`' => array(),
  64.         '`userPassword`' => array(),
  65.         '`userEmail`'   =>  array(),
  66.         '`userID`'  =>  array());
  67.        
  68.     $queryType = array('sqlQuery' => array('type' => 'SELECT',
  69.                                                     'whereCol' => '`userName`',
  70.                                                     'whereVal' => $validate->inputValidated['userName'])); 
  71.  
  72.     $sql = $dbQuery->sqlGeneratorStart($data, $queryType); 
  73.    
  74.     $stmt = $db->preparedQuery($sql);
  75.    
  76.     $dbObject = $stmt->fetchObjs('User');
  77.    
  78.     try{$userObject->verifyCredentials($dbObject);}
  79.     catch(Exception $e){ echo "Error: " .$e->getMessage; }
  80.    
  81.     if($userObject->checkLogin()){
  82.        
  83.         echo "Welcome " .$userObject->userName. ", you are now logged in!";
  84.        
  85.     }
  86. }  
  87. }
  88.  
  89. else{
  90.  
  91. echo "Hello Again!";
  92.  
  93. }  
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement