为新用户设计Omniauth“encrypted_password可能不为NULL”
我正在使用Devise与Omniauth让用户通过Facebook登录我的应用程序。 我使用Railscast教程来启动并运行它。
如果用户已经是我的网站的成员通过Facebook进行身份validation工作正常。 在使用facebookvalidation新用户时会出现此问题。 当它为我的用户模型创建一个新用户时,我得到“users.encrypted_password可能不是NULL”错误。 我无法弄清楚如何从Facebook信息将密码传递给用户模型。
这就是我所拥有的:
authentations_controller.rb
class AuthenticationsController omniauth['provider'], :uid => omniauth['uid']) flash[:notice] = "Authentication successful." redirect_to authentications_url else user = User.new user.apply_omniauth(omniauth) if user.save flash[:notice] = "Signed in successfully." sign_in_and_redirect(:user, user) else session[:omniauth] = omniauth.except('extra') redirect_to new_user_registration_url end end end
user.rb
def apply_omniauth(omniauth) self.email = omniauth['user_info']['email'] if email.blank? authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid']) end def password_required? (authentications.empty? || !password.blank?) && super end
任何帮助都会很棒,提前谢谢!
从facebook omniauth创建新用户时添加:password => Devise.friendly_token [0,20]。
我相信Devise期望在密码字段中创建一个用户。 由于在做facebook oauth时没有密码(至少在你的应用程序端没有),你只需要创建一个虚拟密码,如上图所示。
有关详细信息,请参阅此内容: https : //github.com/plataformatec/devise/wiki/OmniAuth : -Overview
- Rails facebook app返回422“你想要的改变被拒绝”错误
- 单一登录与设计和OmniAuth
- Unicorn和omniauth-facebook – 未初始化的恒定OmniAuth
- 如何在设计中使用http身份validation,并使用可选的omniauth令牌作为身份validation令牌
- LinkedIn photo_urls或picture-urls ::(原创)未被退回
- instagram api – 神秘的回应; 不确定是否工作,无法用此测试omniauth
- 什么是omniauth和电子邮件密码注册最佳实践?
- OmniAuth不适用于Rails3中的Route Globbing
- OmniAuth Railscast中的DangerousAttributeError教程:create由ActiveRecord定义