Skip to content

Instantly share code, notes, and snippets.

@jacek213
Created February 8, 2017 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacek213/b50d34a06be7742ee9fa01a24f54c48f to your computer and use it in GitHub Desktop.
Save jacek213/b50d34a06be7742ee9fa01a24f54c48f to your computer and use it in GitHub Desktop.
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