Created
September 10, 2019 02:01
-
-
Save ParthivPatel-BTC/a2f50f5230d8358cdbbce86d72dc90c7 to your computer and use it in GitHub Desktop.
OAuthUserModel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
# Include default devise modules. Others available are: | |
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable | |
devise :omniauthable, :omniauth_providers => [:google_oauth2] | |
has_many :tasks | |
def self.from_omniauth(access_token) | |
data = access_token.info | |
user = User.where(:email => data["email"]).first | |
unless user | |
user = User.create( | |
name: data["name"], | |
email: data["email"], | |
encrypted_password: Devise.friendly_token[0,20] | |
) | |
end | |
user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment