Created
February 8, 2017 19:19
-
-
Save jacek213/b50d34a06be7742ee9fa01a24f54c48f to your computer and use it in GitHub Desktop.
This file contains 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
def self.from_omniauth(auth, opts = {}) | |
where('(provider = :provider AND uid = :uid) OR email = :email', | |
provider: auth.provider, | |
uid: auth.uid, | |
email: auth.info.email).first_or_initialize.tap do |user| | |
user.provider = auth.provider | |
user.uid = auth.uid | |
user.oauth_token = auth.credentials.token | |
user.refresh_token = auth.credentials.refresh_token unless auth.credentials.refresh_token.blank? | |
user.email = auth.info.email | |
user.password = Devise.friendly_token[0,20] unless user.persisted? | |
user.firstname = auth.info.first_name | |
user.lastname = auth.info.last_name | |
user.save! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment