Class: SpreeOmni::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/spree_omni.rb

Class Method Summary collapse

Class Method Details

.activateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/spree_omni.rb', line 14

def self.activate
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
    Rails.env.production? ? require(c) : load(c)
  end

  # each user can use different socialnetwork for same account
  User.class_eval do
    has_many :o_datas
    # search user by provider and data
    # in migration exist index
    def self.find_by_provider_and_uid(provider,uid)
      self.joins(:o_datas).where(:o_datas => {:provider => provider,:uid => uid }).limit(1).first
    end

    def self.create_by_auth(auth)
      begin
      user = self.new
      user. = auth['user_info']['nickname']
      user.persistence_token = Authlogic::Random.hex_token
      user.save!(false) # save without validation
      user.o_datas.create( 
                          :provider => auth['provider'],
                          :uid => auth['uid'],
                          :user_info => auth['user_info'],
                          :name => auth['user_info']['name']
                         )
      return user
      rescue =>e
        puts e
      end
    end
  end
end