Module: Concerns::User::AuthDefinitions::ClassMethods

Defined in:
app/models/faalis/concerns/user/auth_definitions.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) find_from_oauth(auth, signed_in_resource = nil)



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/faalis/concerns/user/auth_definitions.rb', line 61

def find_from_oauth(auth, signed_in_resource = nil)
  user = User.where(:provider => auth.provider, :uid => auth.uid).first

  first_name = auth.info.first_name
  last_name = auth.info.last_name

  if first_name.blank?
    # With first_name being blank last_name is probably is blank too
    name = auth.info.name.split(' ')
    first_name = name[0]
    last_name = name[1,] || ''
  end
  unless user
    user = User.create(first_name: first_name,
                       last_name: last_name,
                       provider: auth.provider,
                       uid: auth.uid,
                       email: auth.info.email,
                       password: Devise.friendly_token[0,20])
  end
  user
end