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:
parent
3a8ec5d85a
commit
ec0f64938b
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user