1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/routes/admin-api/user.js
Ivar Conradi Østhus d01c9d2dac
fix: use airbnb lint rules directly (#583)
This drops usage of finn-eslint rules as they are no
longer maintained.
2020-04-14 22:29:11 +02:00

41 lines
1018 B
JavaScript

'use strict';
const Controller = require('../controller');
class UserController extends Controller {
constructor(config) {
super(config);
this.get('/', this.getUser);
this.get('/logout', this.logout);
}
getUser(req, res) {
if (req.user) {
const user = { ...req.user };
if (!this.config.extendedPermissions) {
delete user.permissions;
} else if (!Array.isArray(user.permissions)) {
user.permissions = [];
}
return res
.status(200)
.json(user)
.end();
}
return res.status(404).end();
}
// Depcreated, use "/logout" instead. Will be removed in later release.
logout(req, res) {
if (req.session) {
req.session = null;
}
if (req.logout) {
req.logout();
}
res.redirect(`${this.config.baseUriPath}/`);
}
}
module.exports = UserController;