Commit c2f31add authored by thibaut-felten's avatar thibaut-felten

Endpoint users

parent b8edf1f7
......@@ -3,12 +3,12 @@
// of the directory that contains this file (index.php)
// e.g. http://eden.imt-lille-douai.fr/~luc.fabresse/index.php => __ROOT_DIR = /home/luc.fabresse/public_html
$rootDirectoryPath = realpath(dirname(__FILE__));
define ('__ROOT_DIR', $rootDirectoryPath );
define ('ROOT_DIR', $rootDirectoryPath );
// Load all application config
require_once(__ROOT_DIR . "/config/config.php");
require_once(ROOT_DIR . "/config/config.php");
// Load the Loader class to automatically load classes when needed
require_once(__ROOT_DIR . '/classes/AutoLoader.class.php');
require_once(ROOT_DIR . '/classes/AutoLoader.class.php');
// Reify the current request
$request = Request::getCurrentRequest();
......
......@@ -9,37 +9,29 @@ public function __construct() {
// This method will be automatically executed by PHP whenever it encounters an unknown class name in the source code
private function load($className) {
$classFile = "";
// TODO : compute path of the file to load (cf. PHP function is_readable)
// it is in one of these subdirectory '/classes/', '/model/', '/controller/'
// if it is a model, load its sql queries file too in sql/ directory
if(strpos($className, "Controller") !==FALSE){
$classFile .= __ROOT_DIR . "/controller/";
}else if(strpos($className, "Model") !==FALSE){
$classFile .= __ROOT_DIR . "/model/";
}else if(strpos($className, "Role") !==FALSE){
$classFile .= __ROOT_DIR . "../model/";
}else if(strpos($className, "User") !==FALSE){
$classFile .= __ROOT_DIR . "/model/";
}else if(strpos($className, "Response") !==FALSE){
$classFile .= __ROOT_DIR . "/classes/";
}else if(strpos($className, "Request") !==FALSE){
$classFile .= __ROOT_DIR . "/classes/";
}else if(strpos($className, "Dispatcher") !==FALSE){
$classFile .= __ROOT_DIR . "/classes/";
}else if(strpos($className, "DatabasePDO") !==FALSE){
$classFile .= __ROOT_DIR . "/classes/";
$paths = array('/classes/','/model/','/controller/');
$fileToLoad = null;
$i = 0;
do{
$fileToLoad = ROOT_DIR . $paths[$i] . ucfirst($className
) . '.class.php';
$i++;
} while(!is_readable($fileToLoad) && $i<count($paths));
if(! is_readable($fileToLoad)){
throw new Exception('Unknown class '.$className);
}
require_once($fileToLoad);
if(strlen(strstr($fileToLoad,'/model/'))>0){
$sqlFileToLoad = ROOT_DIR . '/sql/' . ucfirst($className) . '.sql.php';
if(is_readable($sqlFileToLoad)){
require_once($sqlFileToLoad);
}
}
$classFile.=$className.".class.php";
include $classFile;
}
}
$__LOADER = new AutoLoader();
\ No newline at end of file
......@@ -19,10 +19,10 @@ class DatabasePDO extends PDO {
if(defined('DB_PORT'))
$connectionString .= ";port=". DB_PORT;
$connectionString .= ";dbname=" . DB_DATABASE;
$connectionString .= ";dbname=" . DB_DBNAME;
$connectionString .= ";charset=utf8";
parent::__construct($connectionString,DB_USERNAME,DB_PASSWORD);
parent::__construct($connectionString,DB_USER,DB_PASSWORD);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
}
\ No newline at end of file
......@@ -11,6 +11,8 @@ class Dispatcher {
}
public static function dispatchToController($controllerName, $request) {
// TODO
$controllerClass = ucfirst($controllerName)."Controller";
$controller = new $controllerClass($controllerName,$request);
return $controller;
}
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ class UsersController extends Controller {
protected function getAllUsers()
{
$users = User::getList();
// TODO
$response = new Response(200,json_encode($users));
return $response;
}
}
\ No newline at end of file
<?php
User::addSqlQuery('USER_LIST',
'SELECT * FROM USER ORDER BY USER_LOGIN');
'SELECT * FROM USERS ORDER BY ID');
User::addSqlQuery('USER_GET_WITH_LOGIN',
'SELECT * FROM USER WHERE USER_LOGIN=:login');
'SELECT * FROM USERS WHERE USER_LOGIN=:login');
User::addSqlQuery('USER_CREATE',
'INSERT INTO USER (USER_ID, USER_LOGIN, USER_EMAIL, USER_ROLE, USER_PWD, USER_NAME, USER_SURNAME) VALUES (NULL, :login, :email, :role, :pwd, :name, :surname)');
'INSERT INTO USERS (USER_ID, USER_LOGIN, USER_EMAIL, USER_ROLE, USER_PWD, USER_NAME, USER_SURNAME) VALUES (NULL, :login, :email, :role, :pwd, :name, :surname)');
User::addSqlQuery('USER_CONNECT',
'SELECT * FROM USER WHERE USER_LOGIN=:login and USER_PWD=:password');
\ No newline at end of file
'SELECT * FROM USERS WHERE USER_LOGIN=:login and USER_PWD=:password');
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment