Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 KB | None | 0 0
  1. <?php
  2.  
  3. class userLogin{
  4.  
  5.     protected $userDetails;
  6.  
  7.     public static function staticUserLogin(array $userDetails = NULL){
  8.         if($userDetails === NULL){
  9.         $session = new userSession();
  10.         return $session->output;
  11.         }
  12.         elseif(isset($userDetails['userName']) && isset($userDetails['userPassword'])){
  13.         $logMeIn = new userLogin();
  14.         return $logMeIn->setUserDetails($userDetails);
  15.         }
  16.     }
  17.    
  18.     protected function setUserDetails($userDetails){
  19.         $this->userDetails = $userDetails;
  20.         return $this->checkLogin();
  21.     }  
  22.        
  23.     public function checkLogin(){
  24.         $user="cwells";
  25.         $pass="test";
  26.         //check user login using userSession class if true
  27.         //show page. If false return false
  28.         $session = new userSession();
  29.         if($this->userDetails['userName'] == $user && $this->userDetails['userPassword'] == $pass){
  30.             return $session->setUserSession($this->userDetails['userName']);
  31.         }
  32.         else{
  33.         return CREDENTIALS_INCORRECT;  
  34.         }
  35.     }
  36.    
  37.     private function registerUser(){
  38.    
  39.         //echo the form
  40.    
  41.     }
  42.    
  43. }
  44.  
  45. class userUpdates extends userLogin{
  46.  
  47.     protected function __construct(){
  48.    
  49.     }
  50.    
  51.     protected function userChangePassword(){
  52.    
  53.     }
  54.    
  55.     protected function userChangeEmail(){
  56.    
  57.     }  
  58.    
  59. }  
  60.  
  61. class userSession{
  62.    
  63.     public $output;
  64.    
  65.     public function __construct(){
  66.         if(!isset($_SESSION['userLogin']) && !isset($_SESSION['userName'])){
  67.             $this->showLoginForm();
  68.         }
  69.         else{
  70.             $this->checkLogin();           
  71.         }
  72.         return $this->output;
  73.     }
  74.    
  75.     private function checkLogin(){
  76.     if($_SESSION['userLogin'] == true && mktime() - $_SESSION['userToken'] < 60){
  77.         $this->output = LOGGED_IN;
  78.     }
  79.     }
  80.    
  81.     public function setUserSession($userName){
  82.         $_SESSION['userToken'] = mktime();
  83.         $_SESSION['userName'] = $userName;
  84.         $_SESSION['userLogin'] = true;
  85.         $this->checkLogin();
  86.         return $this->output;
  87.     }
  88.    
  89.     public function destroySession(){
  90.    
  91.     }
  92.    
  93.     public function showLoginForm(){
  94.         $form  = '<h2 class="login">Login</h2>';
  95.         $form .= '<form method="GET" action="login.php" name="login">';
  96.         $form .= '<input type="text" name="userName" value="Username" class="login">';
  97.         $form .= '<span class="spacer"></span>';
  98.         $form .= '<input type="password" name="userPassword" value="Password" class="login">';
  99.         $form .= '<span class="spacer"></span>';
  100.         $form .= '<div id="lowerLogin">';
  101.         $form .= '<a class="topNavMenu" href="register.php">Register</a></div>';
  102.         $form .= '<input type="submit" name="loginSubmit" value="Login" class="button">';
  103.         $form .= '</form>';
  104.         $this->output = $form;
  105.    
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement