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

AuthLogic多密码验证

  •  0
  • Hock  · 技术社区  · 16 年前

    我正在使用AuthLogic管理我的用户会话。我正在使用LDAP附加组件,因此我的用户模型中有以下内容

      acts_as_authentic do |c|
         c.validate_password_field = false
      end
    

    问题是,最近我发现应用程序中会有一些用户不属于LDAP(并且无法添加!)。因此,我需要针对数据库验证一些密码,而针对LDAP验证其他密码。

    其密码将根据数据库进行验证的用户将具有特定的属性,该属性将告诉我该密码将在我的数据库中进行验证。

    我该怎么办?“验证密码”字段是否可能接收到“变量”?这样我就可以创建一些方法,根据密码验证的位置返回真/假?

    谢谢!

    尼古拉·伊萨扎

    2 回复  |  直到 15 年前
        1
  •  2
  •   awaage    15 年前

    您应该能够做到:

      acts_as_authentic do |u|
        u.validate_password_field = true
        authentic_options = {:unless => Proc.new{|c| c.ldap}}
        u.merge_validates_confirmation_of_password_field_options(authentic_options)
        u.merge_validates_length_of_password_confirmation_field_options(authentic_options)
        u.merge_validates_length_of_password_field_options(authentic_options)
      end
    

    如果您自己编写验证(而不是使用AuthLogic),您将希望在验证中执行以下操作:

    验证_是否存在:password,:除非=>proc.new u u.ldap

    由于AuthLogic提供了3个助手方法来向validates方法的末尾添加选项,因此您可以使用此方法在使用LDAP时关闭验证。

        2
  •  0
  •   Damien MATHIEU    16 年前

    你应该能做到 unless 在您的验证中。

    acts_as_authentic do |c|
        c.validate_password_field = false if c.ldap
    end
    

    或者甚至(因为模型字段是布尔值):

    acts_as_authentic do |c|
        c.validate_password_field = c.ldap
    end