spree_omni 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,21 @@
1
+ class OmniController < ApplicationController
2
+ def callback
3
+ =begin
4
+ 1. ищем пользователя по uid + provider
5
+ 2. если его нет то создаем пользователя и запись в o_datas
6
+ 3 создаем сессию для пользователя
7
+ =end
8
+ auth = request.env['rack.auth']
9
+ user = User.find_by_provider_and_uid(auth['provider'],auth['uid'])
10
+ if user.nil?
11
+ user = User.create_by_auth(auth)
12
+ end
13
+ @user_session = UserSession.new(user)
14
+ puts @user_session.save!
15
+ if @user_session
16
+ redirect_to '/', :notice => "Welcome, #{auth['user_info']['name']}"
17
+ else
18
+ redirect_to '/login', :alert => "Error login"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ module OmniHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class OData < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,11 @@
1
+ <div>
2
+ <%= link_to image_tag('twitter_32.png'), '/auth/twitter' %>
3
+ <%= link_to image_tag('facebook_32.png'), '/auth/facebook' %>
4
+ <%= link_to image_tag('github_32.png'), '/auth/github' %>
5
+ <%= link_to image_tag('linkedin_32.png'), '/auth/linked_in' %>
6
+ <%= link_to image_tag('google_32.png'), '/auth/google_apps' %><br/>
7
+ <%= raw mailru_login_button %>
8
+ <%= raw vkontakte_login_button %>
9
+ <div id='vk_login'><%= link_to image_tag('vkontakte.png', :onclick => 'vkLogin.doLogin();'),'#' %></div>
10
+ </div>
11
+
data/lib/spree_omni.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'spree_core'
2
+ require 'spree_omni_hooks'
3
+
4
+ module SpreeOmni
5
+ class Engine < Rails::Engine
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+ paths.app.views = "app/views"
9
+ paths.app.models = "app/models"
10
+ paths.app.controllers = "app/controllers"
11
+ paths.app.helpers = "app/helpers"
12
+ paths.config.initializers = "config/initializers/omniauth.rb"
13
+
14
+ def self.activate
15
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
16
+ Rails.env.production? ? require(c) : load(c)
17
+ end
18
+
19
+ # each user can use different socialnetwork for same account
20
+ User.class_eval do
21
+ has_many :o_datas
22
+ # search user by provider and data
23
+ # in migration exist index
24
+ def self.find_by_provider_and_uid(provider,uid)
25
+ self.joins(:o_datas).where(:o_datas => {:provider => provider,:uid => uid }).limit(1).first
26
+ end
27
+
28
+ def self.create_by_auth(auth)
29
+ begin
30
+ user = self.new
31
+ user.login = auth['user_info']['nickname']
32
+ user.persistence_token = Authlogic::Random.hex_token
33
+ user.save!(false) # save without validation
34
+ user.o_datas.create(
35
+ :provider => auth['provider'],
36
+ :uid => auth['uid'],
37
+ :user_info => auth['user_info'],
38
+ :name => auth['user_info']['name']
39
+ )
40
+ return user
41
+ rescue =>e
42
+ puts e
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ config.to_prepare &method(:activate).to_proc
49
+ end
50
+ end
@@ -0,0 +1,8 @@
1
+ class SpreeOmniHooks < Spree::ThemeSupport::HookListener
2
+ insert_before :signup do
3
+ %(<%= render :partial => 'shared/social_auth'%>)
4
+ end
5
+ insert_before :login do
6
+ %(<%= render :partial => 'shared/social_auth'%>)
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ namespace :spree_omni do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_omni:install:migrations'].invoke
5
+ Rake::Task['spree_omni:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
14
+ Spree::FileUtilz.mirror_files(source, destination)
15
+ end
16
+
17
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
18
+ task :assets do
19
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
20
+ destination = File.join(Rails.root, 'public')
21
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
22
+ Spree::FileUtilz.mirror_files(source, destination)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_omni
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors: []
13
+
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-14 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spree_core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 103
30
+ segments:
31
+ - 0
32
+ - 30
33
+ - 0
34
+ version: 0.30.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rack-openid
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: ruby-openid
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: omniauth
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: oa-vkontakte
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :runtime
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: oa-mailru
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :runtime
106
+ version_requirements: *id006
107
+ description:
108
+ email:
109
+ executables: []
110
+
111
+ extensions: []
112
+
113
+ extra_rdoc_files: []
114
+
115
+ files:
116
+ - LICENSE
117
+ - lib/spree_omni_hooks.rb
118
+ - lib/tasks/spree_omni.rake
119
+ - lib/tasks/install.rake
120
+ - lib/spree_omni.rb
121
+ - app/helpers/omni_helper.rb
122
+ - app/models/o_data.rb
123
+ - app/views/shared/_social_auth.html.erb
124
+ - app/controllers/omni_controller.rb
125
+ has_rdoc: true
126
+ homepage:
127
+ licenses: []
128
+
129
+ post_install_message:
130
+ rdoc_options: []
131
+
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ hash: 57
140
+ segments:
141
+ - 1
142
+ - 8
143
+ - 7
144
+ version: 1.8.7
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ requirements:
155
+ - none
156
+ rubyforge_project:
157
+ rubygems_version: 1.3.7
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Add gem summary here
161
+ test_files: []
162
+