Class: Apple::Login

Inherits:
Object
  • Object
show all
Defined in:
app/managers/apple/login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Login

Returns a new instance of Login.


5
6
7
8
9
# File 'app/managers/apple/login.rb', line 5

def initialize(options={})
  @info = options[:resource]

  @user_type = options[:user_type] || 'User'
end

Instance Attribute Details

#auth_headerObject

Returns the value of attribute auth_header.


3
4
5
# File 'app/managers/apple/login.rb', line 3

def auth_header
  @auth_header
end

Instance Method Details

#processObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/managers/apple/login.rb', line 11

def process
  return false if @user_type.constantize.where(email: @info['email']).where.not(provider: :apple).count > 0

  user = @user_type.constantize.find_or_create_by(uid: @info['email']) do |user|
           user.email    = @info['email']
           user.password = build_pasword()
           user.name     = @info['name']
           user.provider = :apple
         end

  build_token(user)

  user.reload
end