Defined User.find_for_facebook_oauth to find or create a User based on their Facebook Oauth token

This commit is contained in:
Prelang Builder
2014-02-27 23:58:30 +00:00
committed by u7482
parent 81f898af22
commit 37314d439c

View File

@@ -4,4 +4,21 @@ class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
devise :omniauthable
#->Prelang (user_login/devise)
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
# The User was found in our database
return user if user
# The User was not found and we need to create them
User.create(name: auth.extra.raw_info.name,
provider: auth.provider,
uid: auth.uid,
email: auth.info.email,
password: Devise.friendly_token[0,20])
end
end