代码之家  ›  专栏  ›  技术社区  ›  opsb

用于设计的自定义身份验证策略

  •  25
  • opsb  · 技术社区  · 15 年前

    我需要为 https://github.com/plataformatec/devise 但好像没有医生。怎么样?

    1 回复  |  直到 15 年前
        1
  •  39
  •   Fábio Batista Raza Ahmed    14 年前

    我在 this thread 论设计谷歌集团

    初始化程序/some_initializer.rb:

    Warden::Strategies.add(:custom_strategy_name) do 
      def valid? 
        # code here to check whether to try and authenticate using this strategy; 
        return true/false 
      end 
    
      def authenticate! 
        # code here for doing authentication; 
        # if successful, call  
        success!(resource) # where resource is the whatever you've authenticated, e.g. user;
        # if fail, call 
        fail!(message) # where message is the failure message 
      end 
    end 
    

    在initializers/designe.rb中添加以下内容

      config.warden do |manager| 
         manager.default_strategies.unshift :custom_strategy_name 
      end 
    
    推荐文章