2010-03-17 102 views
1

我怎样才能摆脱验证消息告诉我的:OpenID和Authlogic - 登录名和密码?

Login is too short (minimum is 3 characters) 
Login should use only letters, numbers, spaces, and [email protected] please. 
Password is too short (minimum is 4 characters) 
Password confirmation is too short (minimum is 4 characters) 

发生这种情况甚至在map_openid_registration被调用,因此没有给我任何机会,以填补登录与返回登记Hash东西。我希望在不需要用户提供登录/密码的情况下进行OpenID自动注册(登录时)。

我也不会使这个字段“不需要”或“未验证”,因为我仍然需要他们与旧学校登录/密码注册。谢谢

回答

0

一个选项是只验证loginpassword如果identity_url是空白的存在。 Authlogic提供了一个钩:

openid_validation_options = { :unless => :has_openid? } 
Authlogic::ActsAsAuthentic.class_eval do 
    Login::Config.validates_length_of_login_field_options.merge  openid_validation_options 
    Login::Config.validates_format_of_login_field_options.merge  openid_validation_options 
    Password::Config.validates_length_of_password_field_options.merge openid_validation_options 
    Password::Config.validates_format_of_password_field_options.merge openid_validation_options 
end 

class MyUserClass 
    acts_as_authentic 

    protected 
    def has_openid? 
    identity_url.present? 
    end 
end 

或者,你可以保存之前设置默认loginpassword如果identity_url存在:

class MyUserClass 
    acts_as_authentic 
    before_create :set_login_and_password_if_openid 

    protected 
    def set_login_and_password_if_openid 
    if new_record? && identity_url.present? 
     self.login ||= identity_url 
     if password.blank? && password_confirmation.blank? 
     self.password = self.password_confirmation = generate_random_password 
     end 
    end 
    end 

    def generate_random_password 
    ... 
    end 
end