Class: User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- User
- Defined in:
- app/models/user.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_omniauth(auth) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/user.rb', line 9 def self.from_omniauth(auth) new_user = false user = User.find_by(provider: auth.provider, provider_id: auth.uid) unless user.present? user = User.create!(provider: auth.provider, provider_id: auth.uid) new_user = true end user.username = auth.info.nickname user.email = auth.info.email user.name = auth.info.name user.token = auth.credentials.token user.refresh_token = auth.credentials.refresh_token user.save! user.sync if new_user user end |
Instance Method Details
#client ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/models/user.rb', line 35 def client if provider == 'github' GithubClient.new(username, token) else nil end end |
#sync ⇒ Object
29 30 31 32 33 |
# File 'app/models/user.rb', line 29 def sync client.teams.each do |team| teams.create!(provider: provider, provider_id: team[:id], name: team[:name]) end end |