File: class/user.php

Recommend this page to a friend!
  Classes of Andoitz Jordan Marmolejo   JavaScript Query Terminal   class/user.php   Download  
File: class/user.php
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: JavaScript Query Terminal
Online console to run server commands using AJAX
Author: By
Last change: Update of class/user.php
Date: 2 years ago
Size: 2,144 bytes
 

Contents

Class file image Download
<?php Class User{ public $logged = false; public function __construct(){ $this->testLogin(); } private function testLogin(){ if(isset($_POST["command"])){ $part = explode(" ",$_POST["command"]); if($part[0] == 'login'){ if(count($part)==3){ $this->login($part[1],$part[2],$_POST["token"],true); } else{ $this->abort('Error de sintaxis: Para inciar sesión utilice "login <username> <password>"'); } } else{ if(isset($_SESSION["user"]["username"]) && isset($_SESSION["user"]["password"])){ $this->login($_SESSION["user"]["username"],$_SESSION["user"]["password"],$_POST["token"]); } else{ $this->abort('Debe estar logueado para utilizar el terminal. Para inciar sesión utilice "login <username> <password>"'); } } } } public function login($username,$password,$token,$post=false){ //TEMPORAL USER AND PASSWORD $user["username"] = "test"; $user["password"] = "test"; $user["token"] = "zxcasd2"; if($username == $user["username"] && $password == $user["password"]){ if($token == $user["token"]){ $this->logged = true; if($post){ $_SESSION["user"]["username"] = $username; $_SESSION["user"]["password"] = $password; $_SESSION["user"]["token"] = $user["token"]; $this->abort('Hola '.$username.'! Bienvenido al terminal'); } } else{ if($post){ $this->logged = true; $_SESSION["user"]["username"] = $username; $_SESSION["user"]["password"] = $password; $_SESSION["user"]["token"] = $user["token"]; $this->abort('Hola '.$username.'! Bienvenido al terminal',array("token"=>$user["token"])); } else{ $this->abort('Su sesión ha caducado. Vuelva a iniciar sesión "login <username> <password>"'); } } } else{ $this->abort('Usuario o contraseña incorrectos. Para inciar sesión utilice "login <username> <password>"'); } } public function logout(){ } private function abort($message,$header=array()){ $result = array("data" => "\n [[ib;#FFF;<BACKGROUND>]".$message."]\n", "header" => $header); echo json_encode($result); die(); } } ?>