Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet tutoré S5
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DUCRUET THIBAULT p2306959
Projet tutoré S5
Commits
6b20bf66
Commit
6b20bf66
authored
1 year ago
by
Bastien
Browse files
Options
Downloads
Patches
Plain Diff
fonctions modif mdp
parent
57aa8dbd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/src/controllers/userController.js
+11
-0
11 additions, 0 deletions
backend/src/controllers/userController.js
backend/src/models/userDb.js
+23
-0
23 additions, 0 deletions
backend/src/models/userDb.js
backend/src/services/user.js
+18
-0
18 additions, 0 deletions
backend/src/services/user.js
with
52 additions
and
0 deletions
backend/src/controllers/userController.js
+
11
−
0
View file @
6b20bf66
...
@@ -159,3 +159,14 @@ exports.getUserSeenMovies= async (req, res, next) => {
...
@@ -159,3 +159,14 @@ exports.getUserSeenMovies= async (req, res, next) => {
// });
// });
// return updateResult;
// return updateResult;
// }
// }
exports
.
changeUserPassword
=
async
(
req
,
res
,
next
)
=>
{
let
username
=
req
.
session
.
username
;
let
newPassword
=
req
.
body
.
newPassword
;
try
{
await
userServices
.
changeUserPassword
(
username
,
newPassword
)
res
.
status
(
200
).
json
({
message
:
'
Mot de passe modifié
'
});
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
error
:
error
.
toString
()});
}
}
This diff is collapsed.
Click to expand it.
backend/src/models/userDb.js
+
23
−
0
View file @
6b20bf66
...
@@ -90,3 +90,26 @@ exports.getUserSeenMovies = (username) => {
...
@@ -90,3 +90,26 @@ exports.getUserSeenMovies = (username) => {
})
})
};
};
/**
* Met à jour le mot de passe d'un utilisateur dans la base de données.
*
* @param {string} username - Le nom d'utilisateur de l'utilisateur dont le mot de passe doit être modifié.
* @param {string} newPasswordHash - Le nouveau mot de passe hashé de l'utilisateur.
* @returns {Promise<Object>} Une promesse qui se résout avec un objet contenant des informations sur l'opération de modification du mot de passe.
* La promesse se rejette avec une erreur si l'opération échoue.
*/
exports
.
changeUserPassword
=
(
username
,
newPasswordHash
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
db
.
query
(
'
UPDATE Utilisateur set mdp = ? WHERE login=?
'
,
[
newPasswordHash
,
username
],
function
(
error
,
results
,
fields
)
{
if
(
error
)
{
return
reject
(
error
);
}
else
{
return
resolve
(
results
);
}
})
})
}
This diff is collapsed.
Click to expand it.
backend/src/services/user.js
+
18
−
0
View file @
6b20bf66
...
@@ -82,4 +82,22 @@ exports.getUserSeenMovies = async (username) => {
...
@@ -82,4 +82,22 @@ exports.getUserSeenMovies = async (username) => {
catch
(
error
)
{
catch
(
error
)
{
throw
new
Error
(
error
);
throw
new
Error
(
error
);
}
}
}
/**
* Modifie le mot de passe d'un utilisateur dans la base de données.
*
* @param {string} username - Le nom d'utilisateur de l'utilisateur dont le mot de passe doit être modifié.
* @param {string} newPassword - Le nouveau mot de passe de l'utilisateur.
* @returns {Promise<Object>} Une promesse qui se résout avec un objet contenant des informations sur l'opération de modification du mot de passe.
* La promesse se rejette avec une erreur si l'opération échoue.
*/
exports
.
changeUserPassword
=
async
(
username
,
newPassword
)
=>
{
try
{
const
hash
=
await
bcrypt
.
hash
(
newPassword
,
10
);
return
await
userDb
.
changeUserPassword
(
username
,
hash
)
}
catch
(
error
)
{
throw
new
Error
(
error
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment