2017-11-16 16:45:01 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-04 08:16:03 +01:00
|
|
|
const Controller = require('../controller');
|
2017-11-16 16:45:01 +01:00
|
|
|
|
2018-12-04 08:16:03 +01:00
|
|
|
class UserController extends Controller {
|
2018-12-19 14:50:01 +01:00
|
|
|
constructor(config) {
|
|
|
|
super(config);
|
2018-12-04 08:16:03 +01:00
|
|
|
this.get('/', this.getUser);
|
|
|
|
this.get('/logout', this.logout);
|
|
|
|
}
|
2017-11-16 16:45:01 +01:00
|
|
|
|
2018-12-04 08:16:03 +01:00
|
|
|
getUser(req, res) {
|
2017-11-16 16:45:01 +01:00
|
|
|
if (req.user) {
|
2018-12-19 13:35:54 +01:00
|
|
|
const user = Object.assign({}, req.user);
|
2018-12-19 14:50:01 +01:00
|
|
|
if (!this.config.extendedPermissions) {
|
2018-12-19 13:35:54 +01:00
|
|
|
delete user.permissions;
|
2018-12-19 14:50:01 +01:00
|
|
|
} else if (!Array.isArray(user.permissions)) {
|
|
|
|
user.permissions = [];
|
2018-12-19 13:35:54 +01:00
|
|
|
}
|
2017-11-16 16:45:01 +01:00
|
|
|
return res
|
|
|
|
.status(200)
|
2018-12-19 13:35:54 +01:00
|
|
|
.json(user)
|
2017-11-16 16:45:01 +01:00
|
|
|
.end();
|
|
|
|
} else {
|
|
|
|
return res.status(404).end();
|
|
|
|
}
|
2018-12-04 08:16:03 +01:00
|
|
|
}
|
2017-11-16 16:45:01 +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;
|