Gdzie jest implementacja metody authenticate_user!
?gdzie znajduje się implementacja "authenticate_user!" metoda?
Szukałem go i nie znalazłem go do tej pory.
Gdzie jest implementacja metody authenticate_user!
?gdzie znajduje się implementacja "authenticate_user!" metoda?
Szukałem go i nie znalazłem go do tej pory.
Jest w lib/devise/controllers/helpers.rb
1 i jest generowana dynamicznie (użytkownik jest tylko jednym z możliwych przyrostków):
def self.define_helpers(mapping) #:nodoc:
mapping = mapping.name
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(opts={})
opts[:scope] = :#{mapping}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
def #{mapping}_signed_in?
!!current_#{mapping}
end
def current_#{mapping}
@current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
end
def #{mapping}_session
current_#{mapping} && warden.session(:#{mapping})
end
METHODS
ActiveSupport.on_load(:action_controller) do
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
end
end
To uznany za pomocą niektórych metaprogramowanie tutaj - https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb#L46-49
class_eval <<-METHODS, __FILE__, __LINE__ + 1
def authenticate_#{mapping}!(opts={})
opts[:scope] = :#{mapping}
warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
...
end
Po dodaniu opracować do tory, zazwyczaj dodaje się config/routes.rb
:
devise_for :user
Jest to zdefiniowane w Devise Mapper class.
który nazywa Devise.add_mapping
dla każdego zasobu przechodzi do devise_for
metoda add_mapping modułu opracowują jest zdefiniowana here, które następnie wywołuje define_helpers
, który definiuje authenticate
jak omówiono w innych odpowiedzi.
Proszę zobaczyć http://stackoverflow.com/questions/32237346/what-is-code-for-devise-authenticate-user-after-generated-for-user – Abram
, więc jak mam do niego dostęp explicity. to połączenie nie działa >> 'Devise :: Controllers :: Helpers.authenticate_user!' – vipin8169