-
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.
Merge pull request #13 from webcast-io/feature/basic-auth
Basic Authentication
- Loading branch information
Showing
9 changed files
with
245 additions
and
123 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
var auth = require('basic-auth'); | ||
|
||
|
||
// Loads the controller | ||
// | ||
// @app {Object} The config | ||
// | ||
function main (config) { | ||
|
||
return { | ||
|
||
isAuth: function(req, res, next) { | ||
|
||
if(!config.auth) { | ||
return next(); | ||
} | ||
|
||
var user = auth(req); | ||
|
||
if( | ||
config.auth && | ||
user && | ||
config.auth.username === user.name && | ||
config.auth.password === user.pass | ||
) { | ||
return next(); | ||
} | ||
|
||
res.json(403, { message: 'Permission Denied' }); | ||
} | ||
|
||
}; | ||
|
||
} | ||
|
||
module.exports = main; |
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,24 @@ | ||
'use strict'; | ||
|
||
// Defines support for res.json in controller | ||
// actions | ||
// | ||
// @req {Object} The http request object | ||
// @res {Object} The http response object | ||
// @next {Functioroutern} The function to execute once finished | ||
// | ||
module.exports = function (req,res, next) { | ||
|
||
res.json = function (statusCodeOrBody, body) { | ||
var status = 200; | ||
if (typeof statusCodeOrBody === 'number') { | ||
status = statusCodeOrBody; | ||
} else { | ||
body = statusCodeOrBody; | ||
} | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.statusCode = status; | ||
res.end(JSON.stringify(body)); | ||
}; | ||
next(); | ||
}; |
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,33 @@ | ||
|
||
'use strict'; | ||
|
||
var connectRoute = require('connect-route'); | ||
|
||
module.exports = function(app) { | ||
|
||
//////////////// | ||
/* API routes */ | ||
//////////////// | ||
|
||
return connectRoute(function (router) { | ||
|
||
router.get('/', app.controllers.site.index); | ||
router.get('/jobs', app.controllers.jobs.index); | ||
router.post('/jobs', app.controllers.jobs.create); | ||
router.get('/jobs/search', app.controllers.jobs.search); | ||
router.get('/jobs/new', app.controllers.jobs.new); | ||
router.get('/jobs/processing', app.controllers.jobs.processing); | ||
router.get('/jobs/completed', app.controllers.jobs.completed); | ||
router.get('/jobs/failed', app.controllers.jobs.failed); | ||
router.get('/jobs/:id', app.controllers.jobs.show); | ||
router.put('/jobs/:id', app.controllers.jobs.update); | ||
router.put('/jobs/:id/take', app.controllers.jobs.take); | ||
router.put('/jobs/:id/release', app.controllers.jobs.release); | ||
router.put('/jobs/:id/complete', app.controllers.jobs.complete); | ||
router.put('/jobs/:id/fail', app.controllers.jobs.fail); | ||
router.put('/jobs/:id/retry', app.controllers.jobs.retry); | ||
router.delete('/jobs/:id', app.controllers.jobs.delete); | ||
|
||
}); | ||
|
||
}; |
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
Oops, something went wrong.