railsのdeviseを使ってフェイスブック認証機能を作っているのですが、FBログインのボタンを押すと通常のサインアップフォームへリダイレクトされてしまいます。
その際user.rbは以下のようになっています。
class User < ActiveRecord::Base
Include default devise modules. Others available are:
:confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
has_and_belongs_to_many :roles
mount_uploader :image, ImageUploader
def has_role?(name)
self.roles.where(name: name).length > 0
end
def self.find_for_oauth(auth)
user = User.where(uid: auth.uid, provider: auth.provider).first
unless user
user = User.create(
uid: auth.uid,
provider: auth.provider,
name: auth.info.name,
email: auth.info.email,
password: Devise.friendly_token[4, 30])
end
end
end
しかし、emailの部分にダミーのメールアドレスを入れるよう、user.rbを書き換えると、きちんと登録する事ができます。
class User < ActiveRecord::Base
Include default devise modules. Others available are:
:confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
has_and_belongs_to_many :roles
mount_uploader :image, ImageUploader
def has_role?(name)
self.roles.where(name: name).length > 0
end
def self.find_for_oauth(auth)
user = User.where(uid: auth.uid, provider: auth.provider).first
unless user
user = User.create(
uid: auth.uid,
provider: auth.provider,
name: auth.info.name,
email: User.dummy_email(auth),
password: Devise.friendly_token[4, 30])
end
user
end
private
def self.dummy_email(auth)
"#{auth.uid}-#{auth.provider}@example.com"
end
end
こちら何が問題なのでしょうか。
わかる方、どうがご教授いただけますでしょうか。
あなたの回答
tips
プレビュー