adminmate-express-mongoose
Advanced tools
Comparing version 1.0.4 to 1.0.5
12
index.js
@@ -10,8 +10,8 @@ const router = require('express').Router(); | ||
constructor({ projectId, secretKey, authKey, masterPassword, models }) { | ||
global._config = {}; | ||
global._config.projectId = projectId; | ||
global._config.secretKey = secretKey; | ||
global._config.authKey = authKey; | ||
global._config.masterPassword = masterPassword; | ||
global._config.models = models; | ||
global._amConfig = {}; | ||
global._amConfig.projectId = projectId; | ||
global._amConfig.secretKey = secretKey; | ||
global._amConfig.authKey = authKey; | ||
global._amConfig.masterPassword = masterPassword; | ||
global._amConfig.models = models; | ||
} | ||
@@ -18,0 +18,0 @@ |
{ | ||
"name": "adminmate-express-mongoose", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Adminmate Express/Mongoose connector", | ||
@@ -5,0 +5,0 @@ "author": "Marc Delalonde", |
@@ -9,3 +9,3 @@ const jwt = require('jwt-simple'); | ||
setTimeout(() => { | ||
if (password !== global._config.masterPassword) { | ||
if (password !== global._amConfig.masterPassword) { | ||
return res.status(403).json({ message: 'Invalid master password' }); | ||
@@ -17,5 +17,5 @@ } | ||
exp_date: Date.now() + (24 * expireDays * 1000) | ||
}, global._config.authKey); | ||
}, global._amConfig.authKey); | ||
res.json({ admin_token: adminToken }); | ||
}, 2000); | ||
}; |
@@ -6,3 +6,3 @@ const axios = require('axios'); | ||
// Create request signature | ||
const hmac = crypto.createHmac('sha256', global._config.secretKey); | ||
const hmac = crypto.createHmac('sha256', global._amConfig.secretKey); | ||
hmac.update(JSON.stringify(data)); | ||
@@ -18,3 +18,3 @@ const signatureToCompareWith = hmac.digest('hex'); | ||
'Content-Type': 'application/json', | ||
'X-Project-Id': global._config.projectId, | ||
'X-Project-Id': global._amConfig.projectId, | ||
'Signature': signatureToCompareWith | ||
@@ -51,3 +51,3 @@ // 'Authorization': `bearer ${token}` | ||
module.exports.checkModels = async (req, res) => { | ||
if (global._config.models && global._config.models.length > 0) { | ||
if (global._amConfig.models && global._amConfig.models.length > 0) { | ||
const request = await requestLauncher('POST', '/api/check_models', {}, { action: 'check_models' }).catch(err => { | ||
@@ -54,0 +54,0 @@ console.log('===', err.response.status, err.response.data); |
@@ -6,3 +6,3 @@ const mongoose = require('mongoose'); | ||
let models = []; | ||
global._config.models.forEach(model => { | ||
global._amConfig.models.forEach(model => { | ||
models.push({ | ||
@@ -17,3 +17,3 @@ name: model.collection.name, | ||
module.exports.getModelConfig = (req, res) => { | ||
const currentModel = global._config.models.find(m => m.collection.name === req.params.model); | ||
const currentModel = global._amConfig.models.find(m => m.collection.name === req.params.model); | ||
if (!currentModel) { | ||
@@ -40,3 +40,3 @@ return res.status(403).json({ message: 'Invalid request' }); | ||
const currentModel = global._config.models.find(m => m.collection.name === modelName); | ||
const currentModel = global._amConfig.models.find(m => m.collection.name === modelName); | ||
if (!currentModel) { | ||
@@ -189,3 +189,3 @@ return res.status(403).json({ message: 'Invalid request' }); | ||
const currentModel = global._config.models.find(m => m.collection.name === modelName); | ||
const currentModel = global._amConfig.models.find(m => m.collection.name === modelName); | ||
if (!currentModel) { | ||
@@ -218,3 +218,3 @@ return res.status(403).json({ message: 'Invalid request' }); | ||
const currentModel = global._config.models.find(m => m.collection.name === modelName); | ||
const currentModel = global._amConfig.models.find(m => m.collection.name === modelName); | ||
if (!currentModel) { | ||
@@ -253,3 +253,3 @@ return res.status(403).json({ message: 'Invalid request' }); | ||
const currentModel = global._config.models.find(m => m.collection.name === modelName); | ||
const currentModel = global._amConfig.models.find(m => m.collection.name === modelName); | ||
if (!currentModel) { | ||
@@ -256,0 +256,0 @@ return res.status(403).json({ message: 'Invalid request' }); |
@@ -8,3 +8,3 @@ const jwt = require('jwt-simple'); | ||
try { | ||
decoded = jwt.decode(token, global._config.authKey); | ||
decoded = jwt.decode(token, global._amConfig.authKey); | ||
} catch(e) { | ||
@@ -11,0 +11,0 @@ return res.status(403).json({ code: 'not_authorized' }); |
15440