views:

42

answers:

1

i'm trying to verify in my controller whether user has sufficient rights to upload files or not. swfupload does a POST request with (according to documentation) cookie values passed directly in POST request. this makes before_filter :authenticate_user! unusable, user is not authorized correctly.

as far as I know from devise docs, there is a possibility of creating custom session controllers. is it a good starting point to solve this problem? any idea how to extract session id from POST and proceed with authorization?

A: 

I had a similiar issue with swfupload. I used midleware and some custom helper links to make it work. More info here: http://thewebfellas.com/blog/2008/12/22/flash-uploaders-rails-cookie-based-sessions-and-csrf-rack-middleware-to-the-rescue

ebuychance
yup, thanks. this is exactly what I needed. just one more tip for other people. be aware of the position of your middleware in stack. middleware presented in link above should be called as early as possible (before Warden). so instead of `config.middleware.use` use better `config.middleware.insert_before`
Michal
one more comment. it's even simpler to use POST params instead of custom links. if you use swfupload, pass your session id in `post_params` parameter (see swfupload docs) and extract it in your middleware using `params = ::Rack::Request.new(env).params`
Michal