Class: ApiUserAuth::ProviderToken

Inherits:
ApplicationRecord show all
Defined in:
app/models/api_user_auth/provider_token.rb

Overview

Model for social provider registration

Class Method Summary collapse

Class Method Details

.create_auth_user(data) ⇒ Object



33
34
35
36
# File 'app/models/api_user_auth/provider_token.rb', line 33

def self.create_auth_user(data)
  email = data[:id] + '@' + data[:provider] + '.com'
  AuthUser.create(email: email, password: SecureRandom.uuid)
end

.create_by_data(data, auth_user) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/api_user_auth/provider_token.rb', line 16

def self.create_by_data(data, auth_user)
  if find_by_data(data).blank?
    a_user = if auth_user.blank?
               create_auth_user(data)
             else
               auth_user
             end
    a_user.provider_tokens.create(
      provider: data[:provider],
      user_id: data[:id],
      user_data: data
    )
  else
    nil
  end
end

.find_by_data(data) ⇒ Object



9
10
11
12
13
14
# File 'app/models/api_user_auth/provider_token.rb', line 9

def self.find_by_data(data)
  find_by(
    provider: data[:provider],
    user_id: data[:id]
  )
end