Class: Authentication

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/minimum/omniauth/scaffold/templates/models/authentication.rb

Instance Method Summary collapse

Instance Method Details

#auth_update(auth) ⇒ Object

auth情報更新



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/minimum/omniauth/scaffold/templates/models/authentication.rb', line 9

def auth_update(auth)
  case auth["provider"]
  when "facebook"
    image_path = "https://graph.facebook.com/#{auth['info']['nickname'].presence || auth["uid"]}/picture?width=200&height=200"
  when "twitter"
    image_path = auth["info"]["image"].to_s.gsub('_normal', '') rescue nil
  when "github"
    image_path = "#{auth['info']['image']}&size=200" rescue nil
  end

  gender   = auth["extra"]["raw_info"]["gender"] rescue nil
  location = (auth["info"]["location"].presence || auth["extra"]["raw_info"]["location"]) rescue nil

  self.name     = auth["info"]["name"]     if auth["info"]["name"].present?
  self.nickname = auth["info"]["nickname"] if auth["info"]["nickname"].present?
  self.image    = image_path               if image_path.present?
  self.email    = auth["info"]["email"]    if auth["info"]["email"].present?
  self.gender   = gender                   if gender.present?
  self.location = location                 if location.present?
  self.save!
rescue => e
  puts "[ ---------- e ---------- ]" ; e.tapp ;
  return nil
end