具有集成 webdav 和身份验证的 Rails 3.1 应用程序? [英] Rails 3.1 app with integrated webdav and authentication?
问题描述
我想为 Rails 3.1 应用程序启用 WebDav,我使用 Devise 进行身份验证,使用 CanCan 进行授权.
I would like to enable WebDav for Rails 3.1 application, where I use Devise for authentication and CanCan for authorization.
到目前为止,我打开了 WebDav 并且工作正常.是否可以使用带有 dav4rack 的设计登录/用户来启用/限制对 WebDav 上某些文件/目录的访问?也许已经有一个关于这个的 howto 或 wiki 页面?任何帮助将不胜感激.
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.
附注.这是解决此类问题的正确方法吗?也许我应该切换回 apache mod_dav 并将 apache 的 dav 用户/组与我的 Rails 应用程序中定义的用户/组同步?
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?
推荐答案
我在这里找到了一个带有 Dav4Rack 资源的 Devise 示例https://github.com/bryanrite/dav4rack-example-devise-subdirectories/blob/master/app/models/my_resource.rb
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.
这篇关于具有集成 webdav 和身份验证的 Rails 3.1 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!