Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mod] 비밀번호 api 수정 #247

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ module.exports = {
},
updateUserPassword: async function (req, res, next) {
try {
if (!req.body.email || !req.body.password) {
if (!req.body.newPassword) {
throw new BadRequest(ErrorMessage.BadRequestMeg);
}

await User.updatePassword(req).then(() => {
res.status(StatusCode.OK).json({
success: true,
Expand Down
10 changes: 4 additions & 6 deletions src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,11 @@ module.exports = {
},
updatePassword: async function (req) {
const userId = Number(req.decoded);
const email = req.body.email;
const password = req.body.password;
const hashPassword = bcrypt.hashSync(password, 10);
const newPassword = req.body.newPassword;
const hashPassword = bcrypt.hashSync(newPassword, 10);

const sqlUpdate =
'UPDATE users SET password = ? WHERE email = ? AND user_id = ?';
const params = [hashPassword, email, userId];
const sqlUpdate = 'UPDATE users SET password = ? WHERE user_id = ?';
const params = [hashPassword, userId];

const [rows] = await db.queryWithTransaction(sqlUpdate, params);

Expand Down