-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'enhancement-routes_refactor'
- Loading branch information
Showing
6 changed files
with
78 additions
and
57 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,26 @@ | ||
'use strict'; | ||
|
||
// Articles routes use articles controller | ||
var articles = require('../controllers/articles'); | ||
var authorization = require('./middlewares/authorization'); | ||
|
||
// Article authorization helpers | ||
var hasAuthorization = function(req, res, next) { | ||
if (req.article.user.id != req.user.id) { | ||
return res.send(401, 'User is not authorized'); | ||
} | ||
next(); | ||
} | ||
|
||
module.exports = function(app, passport) { | ||
|
||
app.get('/articles', articles.all); | ||
app.post('/articles', authorization.requiresLogin, articles.create); | ||
app.get('/articles/:articleId', articles.show); | ||
app.put('/articles/:articleId', authorization.requiresLogin, hasAuthorization, articles.update); | ||
app.del('/articles/:articleId', authorization.requiresLogin, hasAuthorization, articles.destroy); | ||
|
||
// Finish with setting up the articleId param | ||
app.param('articleId', articles.article); | ||
|
||
}; |
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,9 @@ | ||
'use strict'; | ||
|
||
module.exports = function(app, passport) { | ||
|
||
// Home route | ||
var index = require('../controllers/index'); | ||
app.get('/', index.render); | ||
|
||
}; |
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,11 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Generic require login routing middleware | ||
*/ | ||
exports.requiresLogin = function(req, res, next) { | ||
if (!req.isAuthenticated()) { | ||
return res.send(401, 'User is not authorized'); | ||
} | ||
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
This file was deleted.
Oops, something went wrong.
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