Rails 3.1 app with integrated webdav and authentication?

廉价感情. 提交于 2019-12-10 19:36:29

问题


I would like to enable WebDav for Rails 3.1 application, where I use Devise for authentication and CanCan for authorization.

So far I turned on WebDav and works fine. Is it possible to use Devise logins/users with dav4rack to enable/restrict access to certain files/directories on WebDav? Maybe there is already a howto or wiki page about that? Any help will be appreciated.

PS. is this the right way of solving this kind of problem? maybe i should switch back to apache mod_dav and synchronise apache's dav users/groups with users/groups defined in my Rails application?


回答1:


I found an example of Devise w/ a Dav4Rack resource here https://github.com/bryanrite/dav4rack-example-devise-subdirectories/blob/master/app/models/my_resource.rb

class MyResource < DAV4Rack::FileResource

  def root
    File.join(options[:root].to_s, user.id.to_s)
  end

  private

  def authenticate(username, password)
    self.user = User.find_by_username(username)
    user.try(:valid_password?, password)
  end  

end

In my case, I used email instead of username.



来源:https://stackoverflow.com/questions/8034384/rails-3-1-app-with-integrated-webdav-and-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!