2010-03-17 2 views
1

나는 나에게 그 이야기 검증 메시지를 제거 할 수 방법 :이 map_openid_registration가 이렇게 나에게 돌려 등록 Hash에서 무언가 로그인을 채울 수있는 기회를 제공하지,라고하기도 전에 발생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) 

. 로그인/비밀번호를 입력하지 않아도 OpenID 자동 등록 (로그인시)을하고 싶습니다.

또한 필자는 이전 학교 로그인/비밀번호 등록에 필요하기 때문에이 필드를 "필요하지 않음"또는 "유효성을 검증하지 않음"으로 만들지 않습니다. 감사합니다

답변

0

loginpassword의 존재를 확인하는 것 중 하나는 identity_url이 비어있는 경우입니다. identity_url가있는 경우 저장하기 전에 기본 loginpassword을 설정할 수 있습니다, 또는

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 

: Authlogic는 대한 후크를 제공

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