diff --git a/lib/routes/admin-api/index.js b/lib/routes/admin-api/index.js index 8cac3f2812..f8b9002bbf 100644 --- a/lib/routes/admin-api/index.js +++ b/lib/routes/admin-api/index.js @@ -6,7 +6,7 @@ const ArchiveController = require('./archive.js'); const EventController = require('./event.js'); const strategies = require('./strategy'); const metrics = require('./metrics'); -const user = require('./user'); +const UserController = require('./user'); const apiDef = require('./api-def.json'); class AdminApi extends Controller { @@ -21,7 +21,7 @@ class AdminApi extends Controller { this.app.use('/strategies', strategies.router(config)); this.app.use('/events', new EventController(stores).router); this.app.use('/metrics', metrics.router(config)); - this.app.use('/user', user.router(config)); + this.app.use('/user', new UserController().router); } index(req, res) { diff --git a/lib/routes/admin-api/user.js b/lib/routes/admin-api/user.js index ec32f57e6e..306a8ef4bd 100644 --- a/lib/routes/admin-api/user.js +++ b/lib/routes/admin-api/user.js @@ -1,11 +1,15 @@ 'use strict'; -const { Router } = require('express'); +const Controller = require('../controller'); -exports.router = function() { - const router = Router(); +class UserController extends Controller { + constructor() { + super(); + this.get('/', this.getUser); + this.get('/logout', this.logout); + } - router.get('/', (req, res) => { + getUser(req, res) { if (req.user) { return res .status(200) @@ -14,14 +18,14 @@ exports.router = function() { } else { return res.status(404).end(); } - }); + } - router.get('/logout', (req, res) => { + logout(req, res) { if (req.session) { req.session = null; } res.redirect('/'); - }); + } +} - return router; -}; +module.exports = UserController;