Introduces POST /login and PATCH /password routes for admin authentication and password management. Adds corresponding schema validation for login and password change, enforces stricter password requirements, and updates adminService with JWT-based profile retrieval and improved token handling.
21 lines
702 B
JavaScript
21 lines
702 B
JavaScript
const express = require("express")
|
|
const router = express.Router()
|
|
const adminService = require("../../services/adminService")
|
|
|
|
router.post("/login", async (req, res) => {
|
|
const { username, password } = req.body
|
|
const result = await adminService.loginAdmin(username, password)
|
|
return res.status(200).json(result)
|
|
})
|
|
|
|
router.patch("/password", async (req, res) => {
|
|
const token = req.headers.authorization.replace("Bearer ", "")
|
|
const profile = await adminService.getAdminProfileByToken(token)
|
|
|
|
const { newPassword } = req.body
|
|
|
|
const result = await adminService.changeAdminPassword(profile.id, newPassword)
|
|
return res.status(200).json(result)
|
|
})
|
|
|
|
module.exports = router |