mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
implement self/update_password
endpoint
This commit is contained in:
parent
2474fe0a12
commit
80bf198908
@ -1,6 +1,7 @@
|
||||
import { Controller } from "linebridge/dist/server"
|
||||
import passport from "passport"
|
||||
import lodash from "lodash"
|
||||
import bcrypt from "bcrypt"
|
||||
|
||||
import SessionController from "../SessionController"
|
||||
|
||||
@ -434,17 +435,17 @@ export default class UserController extends Controller {
|
||||
return res.status(404).json({ message: "User not found" })
|
||||
}
|
||||
|
||||
const currentPasswordHash = await bcrypt.hash(req.selection.currentPassword, parseInt(process.env.BCRYPT_ROUNDS ?? 3))
|
||||
|
||||
const isPasswordValid = await bcrypt.compareSync(currentPasswordHash, user.password)
|
||||
const isPasswordValid = await bcrypt.compareSync(req.selection.currentPassword, user.password)
|
||||
|
||||
if (!isPasswordValid) {
|
||||
return res.status(401).json({ message: "Invalid password" })
|
||||
return res.status(401).json({
|
||||
message: "Current password dont match"
|
||||
})
|
||||
}
|
||||
|
||||
const result = await updatePassword({
|
||||
user_id: req.user._id,
|
||||
newPassword: req.selection.newPassword,
|
||||
password: req.selection.newPassword,
|
||||
}).catch((error) => {
|
||||
res.status(500).json({ message: error.message })
|
||||
return null
|
||||
|
@ -4,6 +4,14 @@ import { User } from "../../../models"
|
||||
export default async function (payload) {
|
||||
const { user_id, password } = payload
|
||||
|
||||
if (!user_id) {
|
||||
throw new Error("Missing user_id")
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
throw new Error("Missing password")
|
||||
}
|
||||
|
||||
const user = await User.findById(user_id)
|
||||
|
||||
if (!user) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user