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:
parent
2ce0f074bb
commit
c9cda79727
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user