为什么将 validate_password_field 设置为 false 会禁用所有 authlogic 验证?
我试图允许用户使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找的是一种简单地忽略密码验证的方法。这是一个称为渐进参与的过程,最常用于创建用户帐户,但不需要特定的东西,直到用户真正需要它们进行更高级的系统操作。您想要做的是修改模型中的 authlogic 配置,如下所示:
我从以下要点中获取了此信息: 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:
I got this information from the following gist: http://gist.github.com/436707/
如果您不将 crypted_password 字段放入用户模型中,您将不会加载密码模块,因此验证将不会运行。
您会发现这是 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.