Class: OauthAccessCard

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/oauth_access_card.rb

Instance Method Summary collapse

Instance Method Details

#check_card_avatarObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/oauth_access_card.rb', line 8

def check_card_avatar
# при смене авы в соцсети
  if saved_change_to_attribute?(:photourl)
    download_avatar
  end
# при переносе соц.скрепы на другого юзера(мутация ролей) переставление ему авы
  if saved_change_to_attribute?(:user_card_id)
    self.user_card.set_active_card
    download_avatar
  end
end

#download_avatarObject

аватару юзеру после создания соц.скрепы



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/oauth_access_card.rb', line 21

def download_avatar
  begin
    if self.photourl.present?
      image_url = self.photourl
      f = open(image_url)
      file = Tempfile.new [File.basename(URI.unescape image_url), '.jpg']
      file.binmode
      file.write f.read
      file.rewind
      self.user_card.userable.create_avatar(uploaded_file: file)
      file.close
      file.unlink
    end
  rescue
  end
end