1
0
mirror of https://github.com/danbee/my-images synced 2025-03-04 08:49:05 +00:00

Refactor user OAuth stuff.

This commit is contained in:
Dan Barber 2014-03-24 18:02:58 +00:00
parent 3a8ec5d85a
commit ec0f64938b

View File

@ -2,14 +2,14 @@ class User < ActiveRecord::Base
dragonfly_accessor :avatar
def self.find_or_create_from_auth(auth)
user = User.find_by(provider: auth.provider, uid: auth.uid)
if user.blank?
user = User.create(provider: auth.provider,
uid: auth.uid,
username: auth.info.nickname,
name: auth.info.name,
avatar_url: auth.info.image)
end
user
find_by(auth.slice(:provider, :uid)) || create_from_auth(auth)
end
def self.create_from_auth(auth)
create(provider: auth.provider,
uid: auth.uid,
username: auth.info.nickname,
name: auth.info.name,
avatar_url: auth.info.image)
end
end