Class: Google::Login

Inherits:
Object
  • Object
show all
Defined in:
app/managers/google/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/google/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/google/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
25
# File 'app/managers/google/login.rb', line 11

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

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

  build_token(user)

  user.reload
end