Guest User

Untitled

a guest
Jul 9th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class LoginUser
  2. include Interactor
  3.  
  4. def call
  5. oauthprovider = OauthProvider.where(provider: context.provider, uid: context.uid.to_s).first
  6. return oauthprovider.user if oauthprovider
  7. #byebug
  8. return unless context.auth.info['email']
  9.  
  10. email = context.auth.info['email']
  11. user = User.where(email: email).first
  12. if user
  13. #byebug
  14. user.find_for_oauth(provider: context.auth.provider, uid: context.auth.uid)
  15. else
  16. password = Devise.friendly_token[0, 20]
  17. user = User.create!(email: email, password: password, password_confirmation: password)
  18. user.find_for_oauth(provider: context.auth.provider, uid: context.auth.uid)
  19. end
  20. end
  21.  
  22. def self.find_for_oauth(auth)
  23. find_or_create_by(uid: context.auth.uid, provider: context.auth.provider)
  24. end
  25. end
Add Comment
Please, Sign In to add comment