Class: User

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

Instance Method Summary collapse

Instance Method Details

#get_args(omniauth) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/user.rb', line 17

def get_args omniauth
  data = omniauth['extra']['raw_info']
  case omniauth['privider']
  when 'twitter' then
    return {
      provider: omniauth['provider'], uid: omniauth['uid'],
      access_token: omniauth['credentials']['token'],
      access_secret: omniauth['credentials']['secret'],
      screen_name: data['screen_name'],
      bio: data['description'],
      image_url: data['profile_image_url'],
      web_url: data['url'],
      last_tid: nil
    }
  when 'github' then
    return {
      provider: omniauth['provider'], uid: omniauth['uid'],
      access_token: omniauth['credentials']['token'],
      access_secret: omniauth['credentials']['secret'],
      screen_name: data['login'],
    }
  when 'facebook' then
    return {
      provider: omniauth['provider'], uid: omniauth['uid'],
      access_token: omniauth['credentials']['token'],
      access_secret: omniauth['credentials']['secret'],
      screen_name: data['name'],
    }
  end
end

#set_params(omniauth) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/models/user.rb', line 5

def set_params omniauth
  User.transaction do
    oauth_lock = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'], lock: true)
    if oauth_lock.nil?
      self.authentications.build self.get_args(omniauth)
    else
      oauth_lock.update_attributes self.get_args(omniauth)
    end
    self.save!
  end
end