Module: User::OAuthAuthorizable::ClassMethods

Defined in:
app/models/user/oauth_authorizable.rb

Overview

ClassMethods defines OAuth authorization processes

Instance Method Summary collapse

Instance Method Details

#create_from_oauth(auth) ⇒ Object


20
21
22
23
24
25
# File 'app/models/user/oauth_authorizable.rb', line 20

def create_from_oauth(auth)
  user = User.new(email: auth.info.email, password: dummy_password)
  user.skip_confirmation!
  user.save!
  user
end

#dummy_passwordObject


27
28
29
# File 'app/models/user/oauth_authorizable.rb', line 27

def dummy_password
  Devise.friendly_token[0, 20]
end

#oauth_authorize(auth) ⇒ Object


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

def oauth_authorize(auth)
  identity = Identity.find_or_create_with_oauth(auth)

  user = identity.user
  if user.nil?
    user = create_from_oauth(auth)
    user.identities << identity
  end

  user
end