ruby on rails - implmenting custom authentication with devise, 'mapping' member -
i'm trying write custom (remote) authentication devise. api doc i've found this example, i'm proceding trials , errors.
i'm particulary interested in understanding 'mapping.to.new' line do.
it seems crucial since if returns nil, authentication process fail.
but "mappings", defined?
furthermore, call
mapping.to.new
has strange, seems object instantiation... isn't it?
i've found different implementation, looks like:
resource = mapping.to.where(["username = ?", auth_params[:username]]).first
where seems mapping.to returns relation object, again, expected define mappings are?
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
instance class of model on map authentification ( user
or admin
). if call mapping.to.new
same call user.new
. , if call mapping.to.where(...)
return same result user.where(...)
.
more can find on mapping.rb
Comments
Post a Comment