This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/lirantal/mean into lirant…
…al-master
- Loading branch information
Showing
7 changed files
with
73 additions
and
60 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) { | ||
|
||
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) { | ||
|
||
// 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 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