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 {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
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) {
|
|
|
|
return res
|
|
|
|
.status(200)
|
|
|
|
.json(req.user)
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
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;
|