Module: User::OmniauthCallbacks

Included in:
User
Defined in:
app/models/user/omniauth_callbacks.rb

Instance Method Summary collapse

Instance Method Details

#new_from_provider_data(provider, uid, data) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/user/omniauth_callbacks.rb', line 24

def new_from_provider_data(provider, uid, data)
  User.new do |user|
    if data['email'].present? && !User.where(email: data['email']).exists?
      user.email = data['email']
    else
      user.email = "#{provider}+#{uid}@example.com"
    end

    user.name = data['name']
    user. = data['nickname']
    user..gsub!(/[^\w]/, '_')
    user.github = data['nickname'] if provider == 'github'

    if user..blank?
      user. = "u#{Time.now.to_i}"
    end

    if User.where(login: user.).exists?
      user. = "#{user.github}-github" # TODO: possibly duplicated user login here. What should we do?
    end

    user.password = Devise.friendly_token[0, 20]
    user.location = data['location']
    user.tagline = data['description']
  end
end