Skip to content

Commit

Permalink
simplify method
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed Jun 21, 2024
1 parent 6760633 commit 291b3ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 1 addition & 3 deletions caracal.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ var HANDLERS = {
"requestResetPassword": customHandlers.requestResetPassword,
"getOwnUser": customHandlers.getOwnUser,
"editOwnUser": customHandlers.editOwnUser,
"impersonate": function() {
return customHandlers.impersonate(userFunction);
},
"impersonate": customHandlers.impersonate,
"dataEnforce": auth.dataEnforce,
"monitorCheck": monitor.check,
"mongoFind": dataHandlers.General.find,
Expand Down
20 changes: 14 additions & 6 deletions handlers/customHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const auth = require('./authHandlers.js');
const sgMail = require('@sendgrid/mail');
const mongoDB = require("../service/database");

var dataHandlers = require('./dataHandlers.js');

sgMail.setApiKey(process.env.SENDGRID_API_KEY);
let defaultAddresses = '["[email protected]", "[email protected]", "[email protected]"]';
let adminAddressRaw = process.env.ADMIN_EMAILS || defaultAddresses;
Expand Down Expand Up @@ -139,13 +141,19 @@ function editOwnUser(db, collection) {
};
}

function impersonate(userFunction) {
function impersonate() {
return function(req, res, next) {
let fakeToken = {'email': req.body.email};
let user = userFunction(fakeToken);
let token = auth.makeJwt(user, auth.PRIKEY, auth.EXPIRY);
req.data = token;
next();
dataHandlers.User.forLogin(req.body.email).then((x)=>{
const newToken = {};

Check failure on line 147 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
newToken.userType = x[0].userType || 'Null';

Check failure on line 148 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
newToken.userFilter = x[0].userFilter || ['Public'];

Check failure on line 149 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
newToken.sub = req.body.email;

Check failure on line 150 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
newToken.email = req.body.email;

Check failure on line 151 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
newToken.name = req.body.email;

Check failure on line 152 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
newToken.data = x[0];

Check failure on line 153 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
req.data = newToken;

Check failure on line 154 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8
next()

Check failure on line 155 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Expected indentation of 6 spaces but found 8

Check failure on line 155 in handlers/customHandlers.js

View workflow job for this annotation

GitHub Actions / build (10.x)

Missing semicolon
});
};
}

Expand Down

0 comments on commit 291b3ae

Please sign in to comment.