Created
June 23, 2020 03:05
-
-
Save stephancom/2e2f37f12d7fd07e72e49ff6f00d309a to your computer and use it in GitHub Desktop.
pretty version of oath creation
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
# ___ _ _ __ __ | |
# .' `. (_) / |_[ | | ] | |
# / .-. \ _ .--..--. _ .--. __ ,--. __ _ `| |-'| |--. .---. .--.| | | |
# | | | |[ `.-. .-. | [ `.-. | [ | `'_\ :[ | | | | | | .-. |/ /__\\/ /'`\' | | |
# \ `-' / | | | | | | | | | | | | // | |,| \_/ |,| |, | | | || \__.,| \__/ | | |
# `.___.' [___||__||__][___||__][___]\'-;__/'.__.'_/\__/[___]|__]'.__.' '.__.;__] | |
# | |
# Facebook, Google, Apple, the world? | |
module Omniauthed | |
extend ActiveSupport::Concern | |
included do | |
has_many :authorizations, dependent: :destroy | |
end | |
class_methods do | |
def from_omniauth(oauth) | |
auth = Authorization.where(oauth.slice(:provider, :uid)).first_or_create do |new_auth| | |
new_auth.user = User.where(email: oauth.info.email).first_or_create do |new_user| | |
new_user.password = Devise.friendly_token | |
new_user.full_name = oauth.info.name | |
new_user.avatar = auth.info.image | |
end | |
end | |
auth.user | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment