1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/lib/routes/admin-api/user.js

41 lines
948 B
JavaScript
Raw Normal View History

'use strict';
2018-12-04 08:16:03 +01:00
const Controller = require('../controller');
2018-12-04 08:16:03 +01:00
class UserController extends Controller {
constructor(config) {
super(config);
2018-12-04 08:16:03 +01:00
this.get('/', this.getUser);
this.get('/logout', this.logout);
}
2018-12-04 08:16:03 +01:00
getUser(req, res) {
if (req.user) {
const user = Object.assign({}, req.user);
if (!this.config.extendedPermissions) {
delete user.permissions;
} else if (!Array.isArray(user.permissions)) {
user.permissions = [];
}
return res
.status(200)
.json(user)
.end();
} else {
return res.status(404).end();
}
2018-12-04 08:16:03 +01:00
}
2018-12-04 08:16:03 +01:00
logout(req, res) {
2018-01-17 09:46:16 +01:00
if (req.session) {
req.session = null;
}
2019-04-03 19:24:57 +02:00
if (req.logout) {
req.logout();
}
2018-01-17 09:46:16 +01:00
res.redirect('/');
2018-12-04 08:16:03 +01:00
}
}
2018-01-17 09:46:16 +01:00
2018-12-04 08:16:03 +01:00
module.exports = UserController;