1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

chore(modernize): UserController

This commit is contained in:
ivaosthu 2018-12-04 08:16:03 +01:00 committed by Ivar Conradi Østhus
parent 2ce0f074bb
commit c9cda79727
2 changed files with 15 additions and 11 deletions

View File

@ -6,7 +6,7 @@ const ArchiveController = require('./archive.js');
const EventController = require('./event.js'); const EventController = require('./event.js');
const strategies = require('./strategy'); const strategies = require('./strategy');
const metrics = require('./metrics'); const metrics = require('./metrics');
const user = require('./user'); const UserController = require('./user');
const apiDef = require('./api-def.json'); const apiDef = require('./api-def.json');
class AdminApi extends Controller { class AdminApi extends Controller {
@ -21,7 +21,7 @@ class AdminApi extends Controller {
this.app.use('/strategies', strategies.router(config)); this.app.use('/strategies', strategies.router(config));
this.app.use('/events', new EventController(stores).router); this.app.use('/events', new EventController(stores).router);
this.app.use('/metrics', metrics.router(config)); this.app.use('/metrics', metrics.router(config));
this.app.use('/user', user.router(config)); this.app.use('/user', new UserController().router);
} }
index(req, res) { index(req, res) {

View File

@ -1,11 +1,15 @@
'use strict'; 'use strict';
const { Router } = require('express'); const Controller = require('../controller');
exports.router = function() { class UserController extends Controller {
const router = Router(); constructor() {
super();
this.get('/', this.getUser);
this.get('/logout', this.logout);
}
router.get('/', (req, res) => { getUser(req, res) {
if (req.user) { if (req.user) {
return res return res
.status(200) .status(200)
@ -14,14 +18,14 @@ exports.router = function() {
} else { } else {
return res.status(404).end(); return res.status(404).end();
} }
}); }
router.get('/logout', (req, res) => { logout(req, res) {
if (req.session) { if (req.session) {
req.session = null; req.session = null;
} }
res.redirect('/'); res.redirect('/');
}); }
}
return router; module.exports = UserController;
};