File Routing authorize

37 views
Skip to first unread message

munteanu.ale...@gmail.com

unread,
Mar 27, 2014, 11:02:40 AM3/27/14
to tot...@googlegroups.com
Hi,
i have this code:
exports.install = function(framework)
{
//framework.route('/download/{name}.exe', download, ['authorize']);
framework.file('All *.exe', download);
};
function download()
{
var self=this;
console.log(self.user); //undefined
}

How to get User object? And how to make it available only for logged in users, like authorize flag in regular route.
I know, i cat get req.header.cookies and to manipulate this data, but is there another solutions?

Peter Širka

unread,
Mar 27, 2014, 1:30:57 PM3/27/14
to tot...@googlegroups.com, munteanu.ale...@gmail.com
Hi,
file routing is performed without onAuthorization delegate, but you can implement it:

function download(req, res, isValid) {

   
if (isValid)
       
return req.url.indexOf('.exe') !== -1;

    framework
.onAuthorization(req, res, req.flags, function(isLogged, user) {

         
if (!isLogged) {
            framework
.response401(req, res);
           
return;
         
}

         req
.user = user;

         
// HERE HERE - your code here
   
});
};

Thanks :-)

munteanu.ale...@gmail.com

unread,
Mar 29, 2014, 11:31:42 AM3/29/14
to tot...@googlegroups.com, munteanu.ale...@gmail.com
Thanks :-)
Reply all
Reply to author
Forward
0 new messages