Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LoginUser
- include Interactor
- def call
- oauthprovider = OauthProvider.where(provider: context.provider, uid: context.uid.to_s).first
- return oauthprovider.user if oauthprovider
- #byebug
- return unless context.auth.info['email']
- email = context.auth.info['email']
- user = User.where(email: email).first
- if user
- #byebug
- user.find_for_oauth(provider: context.auth.provider, uid: context.auth.uid)
- else
- password = Devise.friendly_token[0, 20]
- user = User.create!(email: email, password: password, password_confirmation: password)
- user.find_for_oauth(provider: context.auth.provider, uid: context.auth.uid)
- end
- end
- def self.find_for_oauth(auth)
- find_or_create_by(uid: context.auth.uid, provider: context.auth.provider)
- end
- end
Add Comment
Please, Sign In to add comment