为什么将 validate_password_field 设置为 false 会禁用所有 authlogic 验证?

发布于 2024-11-01 05:25:39 字数 738 浏览 0 评论 0原文

我试图允许用户使用 Twitter 等外部服务注册我的应用程序。因此,我不需要 Authlogic 尝试验证的用户模型的密码。因此,我禁用了密码验证,如下所示:

acts_as_authentic
before_validation :update_authlogic_config
#In the case that the user has signed up with an omniauth service.
attr_accessor :needs_no_password
def update_authlogic_config     
    validate_password_field = !needs_no_password
end

这一切都运行良好,但它似乎也禁用了我想保留的电子邮件/用户名验证。

因此,我更新了我的方法以确保电子邮件字段像这样进行验证:

def update_authlogic_config
   validate_password_field = !needs_no_password
   ignore_blank_passwords = needs_no_password
   validate_email_field = true
end

使用此方法会拖回密码验证,从而出现以下错误:

密码太短(最少为 4 字符)

密码确认是 太短(最少 4 个字符)

有什么想法吗?

I'm trying to allow users to sign up to my app with external services such as twitter etc. Consequently I don't need a password for the user model which Authlogic tries to validate. As a result I'm disabling the password validations like so:

acts_as_authentic
before_validation :update_authlogic_config
#In the case that the user has signed up with an omniauth service.
attr_accessor :needs_no_password
def update_authlogic_config     
    validate_password_field = !needs_no_password
end

This all works well enough however it also seems to disable the email / username validations which I want to keep.

As a result, I updated my method to make sure the email field validates like so:

def update_authlogic_config
   validate_password_field = !needs_no_password
   ignore_blank_passwords = needs_no_password
   validate_email_field = true
end

Using this it drags back in the password validations giving me the following errors:

Password is too short (minimum is 4
characters)

Password confirmation is
too short (minimum is 4 characters)

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给不了的爱 2024-11-08 05:25:39

您正在寻找的是一种简单地忽略密码验证的方法。这是一个称为渐进参与的过程,最常用于创建用户帐户,但不需要特定的东西,直到用户真正需要它们进行更高级的系统操作。您想要做的是修改模型中的 authlogic 配置,如下所示:

acts_as_authentic do |c|
  c.merge_validates_confirmation_of_password_field_options({:unless => :networked?})
  c.merge_validates_length_of_password_field_options({:unless => :networked?})
  c.merge_validates_length_of_password_confirmation_field_options({:unless => :networked?})
end

def networked?
  self.authentications.any? # or true/false boolean of some kind
end

我从以下要点中获取了此信息: http ://gist.github.com/436707/

What you are looking for is a way to simply ignore password validation. This is a process called gradual engagement and is most commonly used to create a User account but not require specific things until the user truly needs them for more advanced systems operations. What you want to do is modify the authlogic config in your model like this:

acts_as_authentic do |c|
  c.merge_validates_confirmation_of_password_field_options({:unless => :networked?})
  c.merge_validates_length_of_password_field_options({:unless => :networked?})
  c.merge_validates_length_of_password_confirmation_field_options({:unless => :networked?})
end

def networked?
  self.authentications.any? # or true/false boolean of some kind
end

I got this information from the following gist: http://gist.github.com/436707/

紫﹏色ふ单纯 2024-11-08 05:25:39

如果您不将 crypted_pa​​ssword 字段放入用户模型中,您将不会加载密码模块,因此验证将不会运行。

您会发现这是 Authlogic 中每个模块的常规行为。

If you don't put the crypted_password field in the User model you won't get the Password module loaded and therefor the validations won't run.

You'll find this is the regular behaviour of each of the modules in Authlogic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文