私はDevise with Omniauthを使って、ユーザーがFacebookで自分のアプリにサインインするようにしています。 Railscastチュートリアルを使って起動しました。Devise Omniauth "新しいユーザーのためにencrypted_passwordがNULLになることはありません"
ユーザーがすでにFacebookのメンバーによる認証を受けている場合は、Facebookでの認証がうまく動作します。この問題は、facebookで新しいユーザーを認証するときに発生します。ユーザーモデル用の新しいユーザーを作成すると、「users.encrypted_passwordがNULLでない可能性があります」というエラーが表示されます。 Facebookの情報からパスワードをUserモデルに渡す方法を理解できません。
は、これは私が持っているものです。
authentations_controller.rb
class AuthenticationsController < ApplicationController
def index
@authentications = current_user.authentications if current_user
end
def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => 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
すべてのヘルプは素晴らしいことだ、事前に感謝!
おかげで多くのことを、私は前にこれを実装しようとしたが、明らかに間違っていました。すべては現在正常に動作しています。うまくいけば、そのリンクは他の誰かを助けるかもしれない。 – looloobs
これはまた、google_oauth2 –
と私を助け、ユーザーはパスワードが何であるか知ることができますか? –