-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlibrary.js
More file actions
74 lines (57 loc) · 2.03 KB
/
library.js
File metadata and controls
74 lines (57 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(function (module) {
"use strict";
var meta = module.parent.require('./meta'),
user = module.parent.require('./user'),
controllers = require('./lib/controllers'),
nconf = require("nconf");
var constants = Object.freeze({
'name': "JWT",
'admin': {
'route': '/plugins/jwt',
'icon': 'fa-file-archive-o'
}
});
var JWT = {};
JWT.init = function (params, callback) {
var jwt = require('jsonwebtoken'),
_ = require('lodash'),
router = params.router,
hostMiddleware = params.middleware,
hostControllers = params.controllers,
url=nconf.get("url");
router.get('/admin/plugins/jwt', hostMiddleware.admin.buildHeader, controllers.renderAdminPage);
router.get('/api/admin/plugins/jwt', controllers.renderAdminPage);
function getToken(req, res, next) {
if (req.user && req.user.uid) {
meta.settings.get('jwt', function (err, settings) {
user.getUserData(req.user.uid, function (err, user) {
user._uid=user.uid;
var token = jwt.sign(_.omit(user, 'password'), settings.secret, {
expiresIn: 60 * 5
});
res.send(token);
});
});
} else {
res.redirect('/login');
}
}
router.get('/api/jwt', getToken);
JWT.reloadSettings();
callback();
};
JWT.addAdminNavigation = function (header, callback) {
header.plugins.push({
"route": constants.admin.route,
"icon": constants.admin.icon,
"name": constants.name
});
callback(null, header);
};
JWT.reloadSettings=function(){
meta.settings.get('jwt', function(err, settings) {
JWT.settings = settings;
});
};
module.exports = JWT;
}(module));