Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projet-cdaw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thibaut Felten
projet-cdaw
Commits
c2f31add
Commit
c2f31add
authored
Nov 18, 2020
by
thibaut-felten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Endpoint users
parent
b8edf1f7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
42 deletions
+36
-42
api.php
backend/MVC/api.php
+4
-4
AutoLoader.class.php
backend/MVC/classes/AutoLoader.class.php
+22
-30
DatabasePDO.class.php
backend/MVC/classes/DatabasePDO.class.php
+2
-2
Dispatcher.class.php
backend/MVC/classes/Dispatcher.class.php
+3
-1
UsersController.class.php
backend/MVC/controller/UsersController.class.php
+1
-1
User.sql.php
backend/MVC/sql/User.sql.php
+4
-4
No files found.
backend/MVC/api.php
View file @
c2f31add
...
...
@@ -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
();
...
...
backend/MVC/classes/AutoLoader.class.php
View file @
c2f31add
...
...
@@ -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
backend/MVC/classes/DatabasePDO.class.php
View file @
c2f31add
...
...
@@ -19,10 +19,10 @@ class DatabasePDO extends PDO {
if
(
defined
(
'DB_PORT'
))
$connectionString
.=
";port="
.
DB_PORT
;
$connectionString
.=
";dbname="
.
DB_D
ATABAS
E
;
$connectionString
.=
";dbname="
.
DB_D
BNAM
E
;
$connectionString
.=
";charset=utf8"
;
parent
::
__construct
(
$connectionString
,
DB_USER
NAME
,
DB_PASSWORD
);
parent
::
__construct
(
$connectionString
,
DB_USER
,
DB_PASSWORD
);
$this
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
}
}
\ No newline at end of file
backend/MVC/classes/Dispatcher.class.php
View file @
c2f31add
...
...
@@ -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
backend/MVC/controller/UsersController.class.php
View file @
c2f31add
...
...
@@ -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
backend/MVC/sql/User.sql.php
View file @
c2f31add
<?php
User
::
addSqlQuery
(
'USER_LIST'
,
'SELECT * FROM USER
ORDER BY USER_LOGIN
'
);
'SELECT * FROM USER
S ORDER BY ID
'
);
User
::
addSqlQuery
(
'USER_GET_WITH_LOGIN'
,
'SELECT * FROM USER WHERE USER_LOGIN=:login'
);
'SELECT * FROM USER
S
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 USER
S
(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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment