2010-03-17 267 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