60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
const router = require('express-promise-router')()
|
|
const user = require('../../../controllers/users')
|
|
const users = require('../../../controllers/api/v1/users')
|
|
const userAuth = require('../../../middleware/user')
|
|
const oidc = require('../../../controllers/oidc')
|
|
|
|
// Validate and create a new user.
|
|
router.post('/register', user.register)
|
|
|
|
// Validate and log the user in.
|
|
router.post('/login', user.login)
|
|
|
|
// Supply user with the token to set a new password.
|
|
router.post('/reset-password-init', user.generateResetPasswordToken)
|
|
|
|
// Validate new passwords, change if successful and sign the user in.
|
|
router.post('/reset-password-submit', user.changePassword)
|
|
|
|
// Create a brand-new SSO account from the session-stored IdP claims, and sign the user in.
|
|
router.post('/create-profile', oidc.createProfileSubmit)
|
|
|
|
// Confirm the matched local account's password, then permanently convert it into an SSO-only
|
|
// account (IdP-derived name/username, local password removed).
|
|
router.post('/convert-account', oidc.convertAccountSubmit)
|
|
|
|
// Find user by username or email in dictionary or admin console.
|
|
router.get(
|
|
'/addUser',
|
|
userAuth.isAuthenticated,
|
|
userAuth.canAdministrateDictionary,
|
|
user.findByUsernameOrEmail
|
|
)
|
|
|
|
// List all users in the admin console.
|
|
router.get(
|
|
'/listAllUsers',
|
|
userAuth.isAuthenticated,
|
|
userAuth.isPortalAdmin,
|
|
users.listUsers
|
|
)
|
|
|
|
// Update hits per page setting of the requesting user.
|
|
router.post('/hitsPerPage', users.updateHitsPerPage)
|
|
|
|
// Update first name, last name and email of the requesting user.
|
|
router.post('/basic-data', users.updateBasicData)
|
|
|
|
// Update password of the requesting user.
|
|
router.post('/password', users.updatePassword)
|
|
|
|
// Delete user profile of the requesting user.
|
|
// TODO This route has no explicit isAuthenticated middleware, unlike the admin-only routes above
|
|
// - it relies entirely on req.user.id throwing inside the controller when req.user is undefined,
|
|
// which surfaces as an unhandled 500 rather than a clean 401/403 (see the general API-auth TODO
|
|
// in routes/api/index.js). Since this endpoint permanently destroys account data, it deserves an
|
|
// explicit auth check of its own rather than an implicit crash-as-guard.
|
|
router.delete('/current', users.deleteCurrent)
|
|
|
|
module.exports = router
|