我怎样才能摆脱验证消息告诉我:
Login is too short (minimum is 3 characters)
Login should use only letters, numbers, spaces, and .-_@ please.
Password is too short (minimum is 4 characters)
Password confirmation is too short (minimum is 4 characters)这甚至在调用map_openid_registration之前就发生了,因此我没有任何机会用返回的注册Hash中的内容填充登录。我希望有OpenID自动注册(在登录时),而不需要用户提供登录/密码。
我也不会将此字段设置为“非必填”或“未验证”,因为我仍然需要使用旧学校的登录/密码注册。谢谢
发布于 2010-03-18 02:46:41
一种选择是,如果identity_url为空,则仅验证是否存在login和password。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或者,如果存在identity_url,则可以在保存之前设置默认的login和password:
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
endhttps://stackoverflow.com/questions/2464505
复制相似问题