-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var constants = require('../../constants'); | ||
|
||
module.exports = function(req, res, next) { | ||
|
||
const root_api_key = constants.ROOT_USER_API_KEY; | ||
|
||
console.log('checking if is resource owner'); | ||
Account.findOne({ token: req.query.access_token || req.get('Authorization').replace('Bearer ', '') }) | ||
.then((account) => { | ||
if (!account) { return res.serverError('Auth error: No account found with this token.') } | ||
if (account.token == root_api_key) return next(); | ||
return Job.findOne({ ownerId: account.id, id: req.param('id') }); | ||
}) | ||
.then((job) => { | ||
if (job) return next(); | ||
}) | ||
.catch((err) => { | ||
return res.forbidden('You are not permitted to perform this action. Only localhost account can do this.'); | ||
}) | ||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var constants = require('../../constants'); | ||
|
||
module.exports = function(req, res, next) { | ||
|
||
const root_api_key = constants.ROOT_USER_API_KEY; | ||
|
||
console.log('checking if is localhost account'); | ||
if (req.query.access_token == root_api_key || req.get('Authorization') == `Bearer ${root_api_key}`) { | ||
return next(); | ||
} | ||
|
||
return res.forbidden('You are not permitted to perform this action. Only localhost account can do this.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var constants = require('./constants'); | ||
|
||
function createLocalHostAccount(callback) { | ||
const defaultLocalHostAcc = { | ||
hostname: constants.ROOT_USER_HOSTNAME, | ||
api_key: constants.ROOT_USER_API_KEY | ||
} | ||
Account.findOrCreate({ hostname: defaultLocalHostAcc.hostname }, defaultLocalHostAcc) | ||
.exec((err, recordFound, newRecord) => { | ||
if (err) console.error(err); | ||
if (recordFound) console.log('default localhost account already exist.'); | ||
if (newRecord) console.log('created a default localhost account.'); | ||
if (callback) callback(); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
createLocalHostAccount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
var sails = require('sails'); | ||
var constants = require('../constants'); | ||
|
||
before(function(done) { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters