Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create_for_doorkeeper_oauth(oauth_data) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/user.rb', line 13

def self.find_or_create_for_doorkeeper_oauth(oauth_data)
  ap oauth_data
  User.find_or_initialize_by_doorkeeper_uid(oauth_data.uid).tap do |user|
    user.email = oauth_data.info.email
    user.name = oauth_data.info.name
  end
end

Instance Method Details

#connectObject



37
38
39
40
# File 'app/models/user.rb', line 37

def connect
  @jid, @sid, @rid = RubyBOSH.initialize_session("#{self.encrypted_data}@idlecampus.com", "#{ENV['DOORKEEPER_APP_SECRET']}", "http://idlecampus.com:5280/http-bind")
 return {jid: @jid, id: @sid, rid: @rid }
end

#github_auth_tokenObject



26
27
28
# File 'app/models/user.rb', line 26

def github_auth_token
  identities.find_by(provider:"github").auth_token
end

#register_userObject



30
31
32
33
# File 'app/models/user.rb', line 30

def register_user
  self.encrypted_data = RubyBOSH.register(self)
  self.save
end

#update_doorkeeper_credentials(oauth_data) ⇒ Object



21
22
23
# File 'app/models/user.rb', line 21

def update_doorkeeper_credentials(oauth_data)
  self.doorkeeper_access_token = oauth_data.credentials.token
end