Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement login_required decorator #3

Open
thomasyip opened this issue Feb 11, 2014 · 2 comments
Open

Implement login_required decorator #3

thomasyip opened this issue Feb 11, 2014 · 2 comments

Comments

@thomasyip
Copy link
Member

There is no concept of decorator in nodejs. We might need to invent it, which might be complicated.

On the other hand, login_required function can be used without decorator. It can be defined in urls.py wrapping the view.

@ulion
Copy link

ulion commented Feb 11, 2014

this is what I did for the view.js:

function authRequired(f) {
return function (req, res) {
if (!req.owner || !req.user) {
res.writeHead(401, {
'Cache-Control': 'no-cache',
'Content-Type': 'application/json'
});
res.write(JSON.stringify({error: 'Auth required.'}));
res.end();
return;
}
return f.apply(null, arguments);
}
}

module.exports = {
http307: {post: post, get: get, put: post},
servemedia: {get: authRequired(serveMedia)},
signrequest: {get: authRequired(signrequest), post:
authRequired(signrequest)},
postcompleted: {post: redirectedPost, get: authRequired(redirectedGet)}
};

@thomasyip
Copy link
Member Author

Cool, I like it. Easy enough to port it into dingo. @ulion, thanks for the head up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants