Ruby on rails 使用designe“mapping”成员实现自定义身份验证
我正在尝试为Desive编写自定义远程身份验证。 我找到的所有API文档都是,所以我正在进行尝试和错误处理 我对理解“mapping.to.new”行的作用特别感兴趣 这似乎很关键,因为如果它返回nil,身份验证过程将失败 但是这些映射是什么,它们在哪里定义 此外,电话 有点奇怪,好像是一个对象实例化。。。不是吗 我还发现了一个不同的实现,它看起来像:Ruby on rails 使用designe“mapping”成员实现自定义身份验证,ruby-on-rails,authentication,devise,Ruby On Rails,Authentication,Devise,我正在尝试为Desive编写自定义远程身份验证。 我找到的所有API文档都是,所以我正在进行尝试和错误处理 我对理解“mapping.to.new”行的作用特别感兴趣 这似乎很关键,因为如果它返回nil,身份验证过程将失败 但是这些映射是什么,它们在哪里定义 此外,电话 有点奇怪,好像是一个对象实例化。。。不是吗 我还发现了一个不同的实现,它看起来像: resource = mapping.to.where(["username = ?", auth_params[:username]]).fi
resource = mapping.to.where(["username = ?", auth_params[:username]]).first
似乎mapping.to会返回一个关系对象,但是,我应该在哪里定义我的映射呢
class RemoteAuthenticatable < Authenticatable
def authenticate!
auth_params = authentication_hash
auth_params[:password] = password
resource = mapping.to.new
return fail! unless resource
if validate(resource){ resource.remote_authentication(auth_params) }
success!(resource)
end
end
end
mapping.to是映射身份验证的模型类的实例,通常是用户或管理员。
因此,如果调用mapping.to.new,则与调用User.new相同。
如果你调用mapping.to.where。。。它返回与用户相同的结果。其中
你可以在网上找到更多信息
class RemoteAuthenticatable < Authenticatable
def authenticate!
auth_params = authentication_hash
auth_params[:password] = password
resource = mapping.to.new
return fail! unless resource
if validate(resource){ resource.remote_authentication(auth_params) }
success!(resource)
end
end
end