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
Raphaël PEIM
projet-cdaw
Commits
949798cd
Commit
949798cd
authored
Dec 03, 2020
by
raphael.peim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Profile.vue
parent
cde037db
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
30 deletions
+73
-30
UserController.class.php
frontend/public/api/controller/UserController.class.php
+11
-8
Model.class.php
frontend/public/api/model/Model.class.php
+5
-5
User.class.php
frontend/public/api/model/User.class.php
+8
-1
User.sql.php
frontend/public/api/sql/User.sql.php
+3
-1
Profile.vue
frontend/src/views/Profile.vue
+46
-15
No files found.
frontend/public/api/controller/UserController.class.php
View file @
949798cd
...
@@ -43,6 +43,9 @@
...
@@ -43,6 +43,9 @@
$id
=
$this
->
request
->
getUriParameters
()[
0
];
$id
=
$this
->
request
->
getUriParameters
()[
0
];
return
$this
->
deleteUser
(
$id
);
return
$this
->
deleteUser
(
$id
);
break
;
break
;
case
'OPTIONS'
:
return
Response
::
okResponse
(
"Tout va bien"
);
break
;
}
}
return
Response
::
errorResponse
(
"unsupported parameters or method in users"
);
return
Response
::
errorResponse
(
"unsupported parameters or method in users"
);
}
}
...
@@ -100,19 +103,19 @@
...
@@ -100,19 +103,19 @@
protected
function
updateUser
(
$put
,
$id
)
{
protected
function
updateUser
(
$put
,
$id
)
{
$user
=
User
::
getWithId
(
$id
);
$user
=
User
::
getWithId
(
$id
);
if
(
!
empty
(
$put
)
&&
!
empty
(
$user
))
{
if
(
!
empty
(
$put
)
&&
!
empty
(
$user
))
{
$jwt_token
=
$this
->
request
->
getJwtToken
();
//
$jwt_token = $this->request->getJwtToken();
$jwt
=
JWT
::
decode
(
$jwt_token
,
JWT_BACKEND_KEY
,
array
(
'HS256'
));
//
$jwt = JWT::decode($jwt_token, JWT_BACKEND_KEY, array('HS256'));
if
(
$jwt
->
data
->
id
==
$id
)
{
//
if ($jwt->data->id == $id) {
User
::
update
(
$put
,
$id
);
User
::
update
(
$put
,
$id
);
$response
=
Response
::
okResponse
(
"Utilisateur modifié"
);
$response
=
Response
::
okResponse
(
"Utilisateur modifié"
);
return
$response
;
return
$response
;
}
//
}
else
{
//
else {
return
Response
::
unauthorizedResponse
(
"Modification non autorisée"
);
//
return Response::unauthorizedResponse("Modification non autorisée");
}
//
}
}
}
else
{
else
{
return
Response
::
notFoundResponse
(
"Aucun utilisateur modifié"
);
return
Response
::
notFoundResponse
(
"Aucun utilisateur modifié"
);
...
...
frontend/public/api/model/Model.class.php
View file @
949798cd
<?php
<?php
class
Model
{
class
Model
{
protected
static
function
db
(){
protected
static
function
db
()
{
return
DatabasePDO
::
singleton
();
return
DatabasePDO
::
singleton
();
}
}
// *** Queries in sql/model.sql.php ****
// *** Queries in sql/model.sql.php ****
protected
static
$requests
=
array
();
protected
static
$requests
=
array
();
public
static
function
addSqlQuery
(
$key
,
$sql
){
public
static
function
addSqlQuery
(
$key
,
$sql
)
{
static
::
$requests
[
$key
]
=
$sql
;
static
::
$requests
[
$key
]
=
$sql
;
}
}
public
static
function
sqlQueryNamed
(
$key
){
public
static
function
sqlQueryNamed
(
$key
)
{
return
static
::
$requests
[
$key
];
return
static
::
$requests
[
$key
];
}
}
protected
static
function
query
(
$sql
){
protected
static
function
query
(
$sql
)
{
$st
=
static
::
db
()
->
query
(
$sql
)
or
die
(
"sql query error ! request : "
.
$sql
);
$st
=
static
::
db
()
->
query
(
$sql
)
or
die
(
"sql query error ! request : "
.
$sql
);
$st
->
setFetchMode
(
PDO
::
FETCH_CLASS
|
PDO
::
FETCH_PROPS_LATE
,
get_called_class
());
$st
->
setFetchMode
(
PDO
::
FETCH_CLASS
|
PDO
::
FETCH_PROPS_LATE
,
get_called_class
());
return
$st
;
return
$st
;
}
}
protected
static
function
exec
(
$sqlKey
,
$values
=
array
()){
protected
static
function
exec
(
$sqlKey
,
$values
=
array
())
{
$sth
=
static
::
db
()
->
prepare
(
static
::
sqlQueryNamed
(
$sqlKey
));
$sth
=
static
::
db
()
->
prepare
(
static
::
sqlQueryNamed
(
$sqlKey
));
$sth
->
setFetchMode
(
PDO
::
FETCH_CLASS
|
PDO
::
FETCH_PROPS_LATE
,
get_called_class
());
$sth
->
setFetchMode
(
PDO
::
FETCH_CLASS
|
PDO
::
FETCH_PROPS_LATE
,
get_called_class
());
$sth
->
execute
(
$values
);
$sth
->
execute
(
$values
);
...
...
frontend/public/api/model/User.class.php
View file @
949798cd
...
@@ -34,7 +34,14 @@
...
@@ -34,7 +34,14 @@
}
}
public
static
function
update
(
$put
,
$id
)
{
public
static
function
update
(
$put
,
$id
)
{
parent
::
exec
(
'USER_UPDATE'
,
[
':email'
=>
$put
->
email
,
':id'
=>
$id
]);
parent
::
exec
(
'USER_UPDATE'
,
[
':firstname'
=>
$put
->
firstname
,
':lastname'
=>
$put
->
lastname
,
':login'
=>
$put
->
login
,
':password'
=>
$put
->
password
,
':email'
=>
$put
->
email
,
':role'
=>
$put
->
role
,
':id'
=>
$id
]);
}
}
public
static
function
delete
(
$id
)
{
public
static
function
delete
(
$id
)
{
...
...
frontend/public/api/sql/User.sql.php
View file @
949798cd
...
@@ -12,7 +12,9 @@
...
@@ -12,7 +12,9 @@
'SELECT * FROM `users` WHERE `login` = :login'
);
'SELECT * FROM `users` WHERE `login` = :login'
);
User
::
addSqlQuery
(
'USER_UPDATE'
,
User
::
addSqlQuery
(
'USER_UPDATE'
,
'UPDATE `users` SET `email` = :email WHERE `id` = :id'
);
'UPDATE `users`
SET `firstname` = :firstname, `lastname` = :lastname, `login` = :login, `email` = :email, `password` = :password, `role` = :role
WHERE `id` = :id'
);
User
::
addSqlQuery
(
'USER_DELETE'
,
User
::
addSqlQuery
(
'USER_DELETE'
,
'DELETE FROM `users` WHERE `id` = :id'
);
'DELETE FROM `users` WHERE `id` = :id'
);
...
...
frontend/src/views/Profile.vue
View file @
949798cd
...
@@ -4,8 +4,13 @@
...
@@ -4,8 +4,13 @@
<div
class=
"container d-flex justify-content-center"
>
<div
class=
"container d-flex justify-content-center"
>
<div
class=
"card shadow mb-4"
>
<div
class=
"card shadow mb-4"
>
<h5
class=
"card-header text-primary"
>
Vos informations
</h5>
<h5
class=
"card-header text-primary"
>
Vos informations
</h5>
<div
id=
"body"
class=
"card-body"
style=
"width : 500px;"
>
<div
class=
"card-body text-center"
style=
"width : 500px;"
>
<form
@
submit=
"onSubmit"
>
<div
id=
"message"
style=
"color: red;"
></div>
<div
id=
"body"
>
</div>
<button
class=
"btn btn-primary"
type=
"submit"
>
Modifier
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
...
@@ -24,6 +29,31 @@
...
@@ -24,6 +29,31 @@
this
.
getData
()
this
.
getData
()
},
},
methods
:
{
methods
:
{
onSubmit
(
evt
)
{
evt
.
preventDefault
()
const
form
=
document
.
forms
[
0
]
let
body
=
[]
// Création du body de la requête
Object
.
entries
(
form
.
elements
).
forEach
((
key
)
=>
{
body
[
key
[
1
].
id
]
=
key
[
1
].
value
})
fetch
(
this
.
$apiUrl
+
'/user/'
+
body
[
'id'
],
{
method
:
'PUT'
,
body
:
JSON
.
stringify
(
body
)
})
.
then
(
response
=>
{
if
(
response
.
status
===
200
)
{
localStorage
.
login
=
body
[
'login'
]
document
.
querySelector
(
'#message'
).
innerHTML
=
"Vos informations ont été modifiés"
}
else
{
throw
new
Error
(
'Something went wrong on api server!'
)
}
})
},
// Récupération des données du user
// Récupération des données du user
getData
()
{
getData
()
{
fetch
(
this
.
$apiUrl
+
'/user/'
+
localStorage
.
login
,
{
fetch
(
this
.
$apiUrl
+
'/user/'
+
localStorage
.
login
,
{
...
@@ -41,22 +71,23 @@
...
@@ -41,22 +71,23 @@
const
body
=
document
.
querySelector
(
'#body'
)
const
body
=
document
.
querySelector
(
'#body'
)
for
(
const
[
key
,
value
]
of
Object
.
entries
(
data
))
{
for
(
const
[
key
,
value
]
of
Object
.
entries
(
data
))
{
if
(
key
!=
"id"
&&
key
!=
"password"
&&
key
!=
"role"
)
{
let
div
=
document
.
createElement
(
'div'
)
let
div
=
document
.
createElement
(
'div'
)
let
input
=
document
.
createElement
(
'input'
)
let
input
=
document
.
createElement
(
'input'
)
div
.
className
=
'form-group'
div
.
className
=
'form-group'
input
.
className
=
'form-control form-control-user'
input
.
type
=
'text'
input
.
id
=
key
input
.
value
=
value
input
.
autocomplete
=
'off'
input
.
required
=
true
input
.
className
=
'form-control form-control-user'
if
(
key
==
"id"
||
key
==
"password"
||
key
==
"role"
)
input
.
type
=
'text'
input
.
hidden
=
true
input
.
id
=
key
input
.
value
=
value
input
.
autocomplete
=
'off'
input
.
required
=
true
div
.
append
(
input
)
div
.
append
(
input
)
body
.
append
(
div
)
body
.
append
(
div
)
}
}
}
})
})
}
}
...
...
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