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
0aaf1c25
Commit
0aaf1c25
authored
Nov 25, 2020
by
Zohten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added code getter for responses
parent
92de9aa7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
Response.class.php
BackEnd/src/classes/Response.class.php
+4
-0
UserController.class.php
BackEnd/src/controller/UserController.class.php
+18
-6
No files found.
BackEnd/src/classes/Response.class.php
View file @
0aaf1c25
...
...
@@ -69,4 +69,8 @@ class Response
echo
$this
->
body
;
exit
;
// do we keep that?
}
public
function
getCode
(){
return
$this
->
code
;
}
}
BackEnd/src/controller/UserController.class.php
View file @
0aaf1c25
...
...
@@ -38,11 +38,18 @@ class UserController extends Controller
return
Response
::
errorResponse
(
$message
);
}
public
function
authUser
(
$id
,
$allowAdmin
=
True
){
/**
* Authentificate a user if he has the same id as the one in token, bypassed by admin
*
* @param int $id id of the User
* @return Response
*/
public
function
authUser
(
$id
){
// Token phase
$verifyArray
=
$this
->
request
->
verifyJwtToken
();
if
(
$verifyArray
[
'message'
]
!==
"Valid token."
)
{
return
Response
::
unauthorizedResponse
(
$jsonResult
);
$message
=
json_encode
(
$verifyArray
[
'error'
]);
return
Response
::
unauthorizedResponse
(
$message
);
}
// Auth phase
$data
=
$verifyArray
[
'decodedJWT'
]
->
data
;
...
...
@@ -50,10 +57,13 @@ class UserController extends Controller
$message
=
json_encode
([
"message"
=>
"You don't have access to this account."
]);
return
Response
::
unauthorizedResponse
(
$message
);
}
$message
=
json_encode
([
"message"
=>
"Authentified."
]);
return
Response
::
okResponse
(
$message
);
}
/**
* G
et
all users in USER table
* G
ET
all users in USER table
*
* @return Response
*/
...
...
@@ -65,8 +75,9 @@ class UserController extends Controller
}
/**
* G
et
a specific user in USER table based on id
* G
ET
a specific user in USER table based on id
*
* @param int $id id of the User
* @return Response
*/
protected
function
getUser
(
$id
)
...
...
@@ -79,15 +90,16 @@ class UserController extends Controller
/**
* Update a specific user in USER table based on id
*
* @param array $array array containing id + fields to modify
* @return Response
*/
protected
function
updateUser
(
$array
)
{
// Auth with token phase
$authError
=
$this
->
authUser
(
$array
[
'id'
]);
if
(
$authError
){
if
(
$this
->
authUser
(
$array
[
'id'
])
->
getCode
()
!=
200
){
return
authError
;
}
// Update phase
User
::
updateUser
(
$array
);
...
...
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