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
1
Issues
1
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
Quentin Vrel
projet-cdaw
Commits
c02760a5
Commit
c02760a5
authored
Nov 14, 2020
by
Quentin Vrel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tp3 : douleur sur la mise à jour du user
parent
81917c8e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
4 deletions
+92
-4
Request.class.php
BackEnd/tp3/classes/Request.class.php
+27
-2
UserController.class.php
BackEnd/tp3/controller/UserController.class.php
+41
-0
User.class.php
BackEnd/tp3/model/User.class.php
+16
-0
User.sql.php
BackEnd/tp3/sql/User.sql.php
+8
-2
No files found.
BackEnd/tp3/classes/Request.class.php
View file @
c02760a5
...
@@ -3,6 +3,7 @@ class Request {
...
@@ -3,6 +3,7 @@ class Request {
protected
$controllerName
;
protected
$controllerName
;
protected
$uriParameters
;
protected
$uriParameters
;
protected
$data
;
protected
static
$_instance
;
protected
static
$_instance
;
public
static
function
getCurrentRequest
(){
public
static
function
getCurrentRequest
(){
...
@@ -16,6 +17,7 @@ class Request {
...
@@ -16,6 +17,7 @@ class Request {
public
function
__construct
()
{
public
function
__construct
()
{
$this
->
initBaseURI
();
$this
->
initBaseURI
();
$this
->
initControllerAndParametersFromURI
();
$this
->
initControllerAndParametersFromURI
();
$this
->
initData
();
}
}
// intialise baseURI
// intialise baseURI
...
@@ -62,9 +64,32 @@ class Request {
...
@@ -62,9 +64,32 @@ class Request {
return
$this
->
controllerName
;
return
$this
->
controllerName
;
}
}
public
function
getUriParams
()
{
return
$this
->
uriParameters
;
}
public
function
initData
()
{
if
(
$this
->
getHttpMethod
()
===
'PUT'
){
$this
->
data
=
""
;
$stream
=
fopen
(
"php://input"
,
"r"
);
$next_byte
=
fread
(
$stream
,
'1024'
);
$this
->
data
.=
$next_byte
;
fclose
(
$stream
);
$this
->
data
=
json_decode
(
$this
->
data
,
TRUE
);
}
}
// retourne la méthode HTTP utilisée dans la requête courante
// retourne la méthode HTTP utilisée dans la requête courante
public
function
getHttpMethod
()
{
public
function
getHttpMethod
()
{
return
$_SERVER
[
"REQUEST_METHOD"
];
return
$_SERVER
[
"REQUEST_METHOD"
];
}
}
public
function
getData
()
{
return
$this
->
data
;
}
}
}
\ No newline at end of file
BackEnd/tp3/controller/UserController.class.php
View file @
c02760a5
...
@@ -14,8 +14,15 @@ class UserController extends Controller {
...
@@ -14,8 +14,15 @@ class UserController extends Controller {
{
{
switch
(
$this
->
request
->
getHttpMethod
())
{
switch
(
$this
->
request
->
getHttpMethod
())
{
case
'GET'
:
case
'GET'
:
if
(
$this
->
request
->
getUriParams
())
return
$this
->
getUser
(
$this
->
request
->
getUriParams
()[
0
]);
return
$this
->
getAllUsers
();
return
$this
->
getAllUsers
();
break
;
break
;
case
'PUT'
:
if
(
$this
->
request
->
getUriParams
())
return
$this
->
updateUser
(
$this
->
request
->
getUriParams
()[
0
],
$this
->
request
->
getData
());
break
;
}
}
return
Response
::
errorResponse
(
"unsupported parameters or method in users"
);
return
Response
::
errorResponse
(
"unsupported parameters or method in users"
);
}
}
...
@@ -28,4 +35,38 @@ class UserController extends Controller {
...
@@ -28,4 +35,38 @@ class UserController extends Controller {
// TODO
// TODO
return
$response
;
return
$response
;
}
}
protected
function
getUser
(
$id
){
$user
=
User
::
getRow
(
$id
);
$response
=
Response
::
okResponse
(
json_encode
(
$user
));
return
$response
;
}
protected
function
updateUser
(
$id
,
$data
){
$sets
=
[];
if
(
isset
(
$data
[
'login'
])){
$sets
[]
=
[
'USER_LOGIN'
,
$data
[
'login'
]];
}
if
(
isset
(
$data
[
'email'
])){
$sets
[]
=
[
'USER_EMAIL'
,
$data
[
'email'
]];
}
if
(
isset
(
$data
[
'role'
])){
$sets
[]
=
[
'USER_ROLE'
,
$data
[
'role'
]];
}
if
(
isset
(
$data
[
'pwd'
])){
$sets
[]
=
[
'USER_PWD'
,
$data
[
'pwd'
]];
}
if
(
isset
(
$data
[
'name'
])){
$sets
[]
=
[
'USER_NAME'
,
$data
[
'name'
]];
}
if
(
isset
(
$data
[
'surname'
])){
$sets
[]
=
[
'USER_SURNAME'
,
$data
[
'surname'
]];
}
//$sets = implode(', ', $sets);
$success
=
true
;
foreach
(
$sets
as
$set
)
{
$success
&=
User
::
update
(
$id
,
$set
);
}
$response
=
$success
?
Response
::
okResponse
(
"Updated"
)
:
Response
::
errorResponse
(
"failed"
);
return
$response
;
}
}
}
\ No newline at end of file
BackEnd/tp3/model/User.class.php
View file @
c02760a5
...
@@ -12,4 +12,20 @@ class User extends Model {
...
@@ -12,4 +12,20 @@ class User extends Model {
$stm
=
parent
::
exec
(
'USER_LIST'
);
$stm
=
parent
::
exec
(
'USER_LIST'
);
return
$stm
->
fetchAll
();
return
$stm
->
fetchAll
();
}
}
public
static
function
getRow
(
$id
)
{
$stm
=
parent
::
exec
(
'USER_GET_WITH_ID'
,
[
'id'
=>
$id
]);
return
$stm
->
fetchAll
();
}
public
static
function
update
(
$id
,
$set
)
{
$stm
=
parent
::
exec
(
'USER_UPDATE'
,
[
'id'
=>
$id
,
'set_field'
=>
$set
[
0
],
'set_value'
=>
$set
[
1
]]);
try
{
return
true
;
}
catch
(
\Throwable
$th
)
{
die
(
"dommage, fromage"
);
}
}
}
}
\ No newline at end of file
BackEnd/tp3/sql/User.sql.php
View file @
c02760a5
...
@@ -4,10 +4,16 @@ User::addSqlQuery('USER_LIST',
...
@@ -4,10 +4,16 @@ User::addSqlQuery('USER_LIST',
'SELECT * FROM USER ORDER BY USER_LOGIN'
);
'SELECT * FROM USER ORDER BY USER_LOGIN'
);
User
::
addSqlQuery
(
'USER_GET_WITH_LOGIN'
,
User
::
addSqlQuery
(
'USER_GET_WITH_LOGIN'
,
'SELECT * FROM USER WHERE USER_LOGIN=:login'
);
'SELECT * FROM USER WHERE USER_LOGIN=:login'
);
User
::
addSqlQuery
(
'USER_GET_WITH_ID'
,
'SELECT * FROM USER WHERE USER_ID=:id'
);
User
::
addSqlQuery
(
'USER_CREATE'
,
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 (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'
,
User
::
addSqlQuery
(
'USER_CONNECT'
,
'SELECT * FROM USER WHERE USER_LOGIN=:login and USER_PWD=:password'
);
'SELECT * FROM USER WHERE USER_LOGIN=:login and USER_PWD=:password'
);
User
::
addSqlQuery
(
'USER_UPDATE'
,
'UPDATE `USER` SET :set_field = :set_value WHERE `USER_ID` = :id'
);
\ 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