“authenticate_user!"的设计实现在哪里?方法? [英] where is devise implementation of "authenticate_user!" method?

查看:25
本文介绍了“authenticate_user!"的设计实现在哪里?方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

authenticate_user! 方法的设计实现在哪里?

Where is devise implementation of authenticate_user! method?

我一直在寻找它,到目前为止还没有找到.

I have been looking for it and have not found it so far.

推荐答案

lib/devise/controllers/helpers.rb1 并且是动态生成的(user 只是可能的后缀之一):

It's in lib/devise/controllers/helpers.rb1 and is generated dynamically (user being only one of the possible suffixes):

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

这篇关于“authenticate_user!"的设计实现在哪里?方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆