spree_social 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +23 -0
- data/README.md +119 -0
- data/app/controllers/admin/authentication_methods_controller.rb +7 -0
- data/app/controllers/omniauth_callbacks_controller.rb +59 -0
- data/app/controllers/user_authentications_controller.rb +20 -0
- data/app/controllers/user_registrations_controller_decorator.rb +17 -0
- data/app/controllers/user_sessions_controller_decorator.rb +26 -0
- data/app/models/authentication_method.rb +19 -0
- data/app/models/user_authentication.rb +8 -0
- data/app/models/user_decorator.rb +15 -0
- data/app/views/admin/authentication_methods/_form.html.erb +49 -0
- data/app/views/admin/authentication_methods/edit.html.erb +10 -0
- data/app/views/admin/authentication_methods/index.html.erb +45 -0
- data/app/views/admin/authentication_methods/new.html.erb +10 -0
- data/app/views/admin/shared/_configurations_menu.html.erb +4 -0
- data/app/views/admin/shared/_sidebar_menu.html.erb +1 -0
- data/app/views/shared/_socials.html.erb +6 -0
- data/app/views/user_registrations/new.html.erb +29 -0
- data/app/views/user_registrations/social_edit.html.erb +18 -0
- data/app/views/users/_social.html.erb +42 -0
- data/app/views/users/merge.html.erb +20 -0
- data/lib/spree_social.rb +57 -0
- data/lib/spree_social_hooks.rb +7 -0
- data/lib/tasks/install.rake +26 -0
- data/lib/tasks/spree_social.rake +1 -0
- metadata +156 -0
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.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
SpreeSocial
|
2
|
+
===========
|
3
|
+
|
4
|
+
Core for all Social media related functionality for Spree. The Spree Social gem handles authorization, account creation and association through social media sources such as, Twitter and Facebook. This requires the edge source of [Spree](https://github.com/railsdog/spree). This gem is beta at best and should be treated as such. Features and code base will change rapidly as this is under active development. Use with caution.
|
5
|
+
|
6
|
+
Setup for Production
|
7
|
+
--------------------
|
8
|
+
Add this to your gem file Gemfile
|
9
|
+
|
10
|
+
gem "spree_social", :path => "../spree_social"
|
11
|
+
|
12
|
+
bundle update
|
13
|
+
|
14
|
+
rake spree_social:install
|
15
|
+
|
16
|
+
rake db:migrate
|
17
|
+
|
18
|
+
|
19
|
+
Spree Setup to Utilize OAuth Sources
|
20
|
+
------------------------------------
|
21
|
+
|
22
|
+
Login as an admin user and navigate to Configuration > Social Network Providers
|
23
|
+
|
24
|
+
Click on the New Provider button to enter the key obtained from their respective source
|
25
|
+
(See below for instructions on setting up the various providers)
|
26
|
+
|
27
|
+
Multiple key entries can now be entered based on the rails environment. This allows for portability and the lack of need to check in your key to your repository. You also have the ability to enable and disable sources. These setting will be reflected on the client UI as well.
|
28
|
+
|
29
|
+
Please note that you will still need to restart you server after entering you keys. This is required otherwise Devise and OmniAuth will not have the key pair available to them for use. Also if you are running Spree with SSL, make sure you setup you applications at the social network of you choice EXACTLY as it in seen in the browser, OAuth will fail if it experiences a local redirect through the various handshakes (e.g. if you have https://www.example.com as your domain for SSL, that is the URL that need to be uses as the domain at the OAuth source of your choice).
|
30
|
+
|
31
|
+
Setup the Applications at the Respective Sources
|
32
|
+
------------------------------------------------
|
33
|
+
|
34
|
+
OAuth Applications @ Facebook, Twitter and / or Github are supported out of the box but you will need to setup applications are each respective site as follows for public use and for development.
|
35
|
+
|
36
|
+
> All URLs must be in the form of domain.tld you may add a port as well for development
|
37
|
+
|
38
|
+
### Facebook
|
39
|
+
|
40
|
+
[Facebook](http://www.facebook.com/developers/createapp.php): [http://www.facebook.com/developers/createapp.php](http://www.facebook.com/developers/createapp.php)
|
41
|
+
|
42
|
+
1. Name the app what you will and agree to the terms.
|
43
|
+
2. Fill out the capcha
|
44
|
+
3. Under the Web Site tab
|
45
|
+
4. Site URL: http://your_computer.local:3000 for development / http://your-site.com for production
|
46
|
+
5. Site domain: your-computer.local / your-site.com respectively
|
47
|
+
|
48
|
+
### Twitter
|
49
|
+
|
50
|
+
[Twitter](http://dev.twitter.com/apps/new): [http://dev.twitter.com/apps/new](http://dev.twitter.com/apps/new)
|
51
|
+
|
52
|
+
1. Name and Description must be filled in with something
|
53
|
+
2. Application Website: http://your_computer.local:3000 for development / http://your-site.com for production
|
54
|
+
3. Application Type: Browser
|
55
|
+
4. Callback URL: http://your_computer.local:3000 for development / http://your-site.com for production
|
56
|
+
5. Default Access Type: Read & Write
|
57
|
+
6. Save Application
|
58
|
+
|
59
|
+
### Github
|
60
|
+
|
61
|
+
[Github](http://github.com/account/applications/new): [http://github.com/account/applications/new](http://github.com/account/applications/new)
|
62
|
+
|
63
|
+
1. Name The Application
|
64
|
+
2. Main URL: http://your_computer.local:3000 for development / http://your-site.com for production
|
65
|
+
3. Callback URL: http://your_computer.local:3000 for development / http://your-site.com for production
|
66
|
+
4. Click Create
|
67
|
+
|
68
|
+
> This does not seem to be a listed Github item right now. To View and / or edit your applications goto [http://github.com/account/applications/]([http://github.com/account/applications/])
|
69
|
+
|
70
|
+
### LinkedIn
|
71
|
+
|
72
|
+
> Coming Soon
|
73
|
+
|
74
|
+
### Google / GMail
|
75
|
+
|
76
|
+
> Coming Soon
|
77
|
+
|
78
|
+
### Yahoo!
|
79
|
+
|
80
|
+
> Coming Soon
|
81
|
+
|
82
|
+
Setup for Development
|
83
|
+
---------------------
|
84
|
+
|
85
|
+
git clone git://github.com/railsdog/spree --depth 1
|
86
|
+
|
87
|
+
cd spree
|
88
|
+
|
89
|
+
rake sandbox (and get a sandwich)
|
90
|
+
|
91
|
+
git clone git://github.com/spree/spree_social --depth 1
|
92
|
+
|
93
|
+
add this to sandbox/Gemfile
|
94
|
+
|
95
|
+
gem "spree_social", :path => "../spree_social"
|
96
|
+
|
97
|
+
bundle update
|
98
|
+
|
99
|
+
rake spree_social:install
|
100
|
+
|
101
|
+
rake db:migrate
|
102
|
+
|
103
|
+
Testing
|
104
|
+
-------
|
105
|
+
|
106
|
+
rake testapp inside of cloned spree_social folder
|
107
|
+
|
108
|
+
cucumber features
|
109
|
+
|
110
|
+
rspec spec
|
111
|
+
|
112
|
+
|
113
|
+
Adding your own Auth Source
|
114
|
+
---------------------------
|
115
|
+
|
116
|
+
> Coming Soon
|
117
|
+
|
118
|
+
|
119
|
+
Copyright (c) 2010 John Brien Dilts, released under the New BSD License
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
2
|
+
include Spree::CurrentOrder
|
3
|
+
include SpreeBase
|
4
|
+
helper :users, 'spree/base'
|
5
|
+
|
6
|
+
def facebook
|
7
|
+
social_setups("Facebook")
|
8
|
+
end
|
9
|
+
|
10
|
+
def twitter
|
11
|
+
social_setups("Twitter")
|
12
|
+
end
|
13
|
+
|
14
|
+
def github
|
15
|
+
social_setups("Github")
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def social_setups(provider)
|
21
|
+
omniauth = request.env["omniauth.auth"]
|
22
|
+
|
23
|
+
if request.env["omniauth.error"].present?
|
24
|
+
flash[:error] = t("devise.omniauth_callbacks.failure", :kind => provider, :reason => "user was not valid")
|
25
|
+
redirect_back_or_default(root_url)
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
existing_auth = UserAuthentication.where(:provider => omniauth['provider'], :uid => omniauth['uid'].to_s).first
|
30
|
+
|
31
|
+
#signing back in from a social source
|
32
|
+
if existing_auth
|
33
|
+
user = existing_auth.user
|
34
|
+
else # adding a social source
|
35
|
+
user = current_user
|
36
|
+
end
|
37
|
+
|
38
|
+
user ||= User.anonymous!
|
39
|
+
|
40
|
+
user.associate_auth(omniauth) unless existing_auth
|
41
|
+
|
42
|
+
if current_order
|
43
|
+
current_order.associate_user!(user)
|
44
|
+
session[:guest_token] = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
if user.anonymous?
|
48
|
+
sign_in(user, :event => :authentication) unless current_user
|
49
|
+
flash[:notice] = t("one_more_step", :kind => omniauth['provider'].capitalize)
|
50
|
+
render(:template => "user_registrations/social_edit", :locals => {:user => user, :omniauth => omniauth})
|
51
|
+
elsif current_user
|
52
|
+
flash[:error] = t("attach_error", :kind => omniauth['provider'].capitalize) if existing_auth && (existing_auth.user != current_user)
|
53
|
+
redirect_back_or_default(account_url)
|
54
|
+
else
|
55
|
+
sign_in_and_redirect(user, :event => :authentication)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class UserAuthenticationsController < Spree::BaseController
|
2
|
+
|
3
|
+
def update
|
4
|
+
@user = User.find(params[:id])
|
5
|
+
@user.email = params[:user][:email]
|
6
|
+
if @user.save
|
7
|
+
redirect_back_or_default(products_path)
|
8
|
+
else
|
9
|
+
flash.now[:error] = "There is already an account with that email. Please sign in to associate these accounts."
|
10
|
+
render(:template => 'users/merge')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroy
|
15
|
+
@auth = current_user.user_authentications.find(params[:id])
|
16
|
+
@auth.destroy
|
17
|
+
flash[:notice] = "Successfully deleted authentication source."
|
18
|
+
redirect_to account_path
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
UserRegistrationsController.class_eval do
|
2
|
+
|
3
|
+
def create
|
4
|
+
super.tap do |u|
|
5
|
+
if @user && @user.new_record?
|
6
|
+
@omniauth = u.session[:session]
|
7
|
+
u.session[:omniauth] = nil unless @user.new_record?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete
|
13
|
+
session[:omniauth] = nil
|
14
|
+
redirect_to signin_path
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
UserSessionsController.class_eval do
|
2
|
+
|
3
|
+
def merge
|
4
|
+
# lets remove the old user here
|
5
|
+
sign_out(:user)
|
6
|
+
# now sign in from the login form
|
7
|
+
authenticate_user!
|
8
|
+
|
9
|
+
# prep for all the shifting and do it
|
10
|
+
user = User.find(current_user.id)
|
11
|
+
user.user_authentications << UserAuthentication.find(params[:user_authentication])
|
12
|
+
user.save!
|
13
|
+
|
14
|
+
if current_order
|
15
|
+
current_order.associate_user!(user)
|
16
|
+
session[:guest_token] = nil
|
17
|
+
end
|
18
|
+
# trash the old anonymous that was created
|
19
|
+
User.destroy(params[:user][:id])
|
20
|
+
|
21
|
+
# tell the truth now
|
22
|
+
flash[:alert] = "Succesfully linked your accounts"
|
23
|
+
sign_in_and_redirect(user, :event => :authentication)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class AuthenticationMethod < ActiveRecord::Base
|
2
|
+
|
3
|
+
preference :provider, :string
|
4
|
+
preference :api_key, :string
|
5
|
+
preference :api_secret, :string
|
6
|
+
preference :environment, :string
|
7
|
+
|
8
|
+
#after_save :reset_devise
|
9
|
+
#
|
10
|
+
#private
|
11
|
+
#
|
12
|
+
#def reset_devise
|
13
|
+
# logger.debug("Self: #{self.environment}\nRails: #{RAILS_ENV}")
|
14
|
+
# if (self.environment == RAILS_ENV)
|
15
|
+
# SpreeSocial.reset_key_for(self.preferred_provider,self.preferred_api_key, self.preferred_api_secret)
|
16
|
+
# end
|
17
|
+
#end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
User.class_eval do
|
2
|
+
has_many :user_authentications
|
3
|
+
|
4
|
+
# Associates user to auth source
|
5
|
+
def associate_auth(source)
|
6
|
+
return if user_authentications.where(:provider => source['provider'], :uid => source['uid'].to_s).count > 0
|
7
|
+
self.user_authentications.create!(:provider => source['provider'], :uid => source['uid'], :nickname => source["user_info"]['nickname'])
|
8
|
+
end
|
9
|
+
|
10
|
+
# Thx Ryan
|
11
|
+
def password_required?
|
12
|
+
(user_authentications.empty? || !password.blank?) && super
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<div class="yui-g">
|
2
|
+
<div class="yui-u first">
|
3
|
+
<p>
|
4
|
+
<label><%=t("environment")%></label>
|
5
|
+
<br/>
|
6
|
+
<%= f.collection_select(:environment,
|
7
|
+
Configuration.configurations.keys.sort,
|
8
|
+
:to_s, :titleize,
|
9
|
+
{}, {:id => "gtwy-env"}) %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<p>
|
13
|
+
<%= f.check_box :active, {:style => "vertical-align:middle;"} %>
|
14
|
+
<label>
|
15
|
+
<%= t('social_enable_provider') %>
|
16
|
+
</label>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<p>
|
20
|
+
<label><%= t('social_provider') %></label><br />
|
21
|
+
<%= f.select :preferred_provider, SpreeSocial::PROVIDERS, {:include_blank => true} %>
|
22
|
+
<br/>
|
23
|
+
<span class="info">
|
24
|
+
<%= t("social_provider") %>
|
25
|
+
</span>
|
26
|
+
</p>
|
27
|
+
|
28
|
+
<p>
|
29
|
+
<label><%= t('social_api_key') %></label><br />
|
30
|
+
<%= f.text_field :preferred_api_key, :size => 40, :maxlength => 256 %>
|
31
|
+
<br/>
|
32
|
+
<span class="info">
|
33
|
+
<%= t("social_api_key") %>
|
34
|
+
</span>
|
35
|
+
</p>
|
36
|
+
|
37
|
+
<p>
|
38
|
+
<label><%= t('social_api_secret') %></label><br />
|
39
|
+
<%= f.text_field :preferred_api_secret, :size => 40, :maxlength => 256 %>
|
40
|
+
<br/>
|
41
|
+
<span class="info">
|
42
|
+
<%= t("social_api_secret") %>
|
43
|
+
</span>
|
44
|
+
</p>
|
45
|
+
|
46
|
+
</fieldset>
|
47
|
+
|
48
|
+
</div>
|
49
|
+
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t("edit_social_method") %></h1>
|
4
|
+
<h4><%= t("edit_social_method_warning") %></h4>
|
5
|
+
<%= render 'shared/error_messages', :target => @authentication_method %>
|
6
|
+
|
7
|
+
<%= form_for(:authentication_method, :url => admin_authentication_method_path(@authentication_method), :html => {:method => :put}) do |f| %>
|
8
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
9
|
+
<p class="form-buttons"><%= button t("edit") %></p>
|
10
|
+
<% end %>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<div class='toolbar'>
|
4
|
+
<ul class='actions'>
|
5
|
+
<li>
|
6
|
+
<%= button_link_to t("new_social_method"), new_object_url, :icon => 'add' %>
|
7
|
+
</li>
|
8
|
+
</ul>
|
9
|
+
<br class='clear' />
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<h1><%= t("social_methods") %></h1>
|
13
|
+
|
14
|
+
<table class="index">
|
15
|
+
<thead>
|
16
|
+
<%= hook :admin_social_methods_index_headers do %>
|
17
|
+
<th><%= t("provider") %></th>
|
18
|
+
<th><%= t("social_api_key") %></th>
|
19
|
+
<th><%= t("social_api_secret") %></th>
|
20
|
+
<th><%= t("environment") %></th>
|
21
|
+
<th><%= t("active") %></th>
|
22
|
+
<% end %>
|
23
|
+
<th>
|
24
|
+
<%= hook :admin_social_methods_index_header_actions %>
|
25
|
+
</th>
|
26
|
+
</thead>
|
27
|
+
<tbody>
|
28
|
+
<% @authentication_methods.each do |method|%>
|
29
|
+
<tr id="<%= dom_id method %>">
|
30
|
+
<%- locals = {:method => method} %>
|
31
|
+
<%= hook :admin_trackers_index_rows, locals do %>
|
32
|
+
<td><%= method.preferred_provider %></td>
|
33
|
+
<td><%= method.preferred_api_key %></td>
|
34
|
+
<td><%= method.preferred_api_secret %></td>
|
35
|
+
<td><%= method.environment.to_s.titleize %></td>
|
36
|
+
<td><%= method.active ? t(:yes) : t(:no) %></td>
|
37
|
+
<% end %>
|
38
|
+
<td>
|
39
|
+
<%= link_to_edit method %>
|
40
|
+
<%= link_to_delete method %>
|
41
|
+
</td>
|
42
|
+
</tr>
|
43
|
+
<% end %>
|
44
|
+
</tbody>
|
45
|
+
</table>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= render :partial => 'admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<h1><%= t("new_social_method") %></h1>
|
4
|
+
<h4><%= t("new_social_method_warning") %></h4>
|
5
|
+
<%= render 'shared/error_messages', :target => @authentication_method %>
|
6
|
+
|
7
|
+
<%= form_for(:authentication_method, :url => collection_url) do |f| %>
|
8
|
+
<%= render :partial => "form", :locals => { :f => f } %>
|
9
|
+
<p class="form-buttons"><%= button t("create") %></p>
|
10
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<li<%= raw(' class="active"') if controller.controller_name == 'authentication_methods' %>><%= link_to t("social_servers"), admin_authentication_methods_path %></li>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% if !current_user || !current_user.user_authentications %>
|
2
|
+
<h2>Sign in through one of these services:</h2>
|
3
|
+
<% end %>
|
4
|
+
<% AuthenticationMethod.where(:environment => ::Rails.env).each do |user| %>
|
5
|
+
<%= link_to(image_tag("social/#{user.preferred_provider}_32.png", :size => "32x32", :alt => "#{user.preferred_provider}"), user_authentication_omniauth_authorize_path(user.preferred_provider.to_sym), :title => "Sign in with #{user.preferred_provider}") if user.active %>
|
6
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<% @body_id = 'signup' %>
|
2
|
+
|
3
|
+
<%= render "shared/error_messages", :target => @user %>
|
4
|
+
|
5
|
+
<div id="new-customer">
|
6
|
+
<h2><%= t("new_customer") %></h2>
|
7
|
+
|
8
|
+
<%= hook :signup do %>
|
9
|
+
|
10
|
+
<%= form_for(:user, :url => registration_path(@user)) do |f| %>
|
11
|
+
|
12
|
+
<%= hook :signup_inside_form do %>
|
13
|
+
<% if session[:omniauth] %>
|
14
|
+
<p>
|
15
|
+
<%= f.label :email, t("email") %><br />
|
16
|
+
<%= f.text_field :email, :class => 'title' %>
|
17
|
+
</p>
|
18
|
+
<p><%= submit_tag t("create"), :class => 'button primary' %></p>
|
19
|
+
<% else %>
|
20
|
+
<%= render 'shared/user_form', :f => f %>
|
21
|
+
<p><%= submit_tag t("create"), :class => 'button primary' %></p>
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
<% end %>
|
26
|
+
<%= t("or") %> <%= session[:omniauth] ? link_to( t("login_as_existing"), user_registration_path, :method => :delete) : link_to( t("login_as_existing"), login_path) %>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
</div>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<div id="existing-customer">
|
2
|
+
<table>
|
3
|
+
<tr>
|
4
|
+
<% if user.anonymous? %>
|
5
|
+
<%= form_for(:user, :url => user_authentication_path(user), :html => { :method => :put }) do |f| %>
|
6
|
+
<td><%= f.label :email, t("email") %></td>
|
7
|
+
<td><%= f.text_field :email, :class => 'title', :value => (omniauth["extra"]["user_hash"]["email"] unless omniauth.nil? ) %></td>
|
8
|
+
<td><%=submit_tag t("update") %></td>
|
9
|
+
<% end %>
|
10
|
+
<% else %>
|
11
|
+
<td><%= t("email") %>:</td>
|
12
|
+
<td>
|
13
|
+
<%= user.email %>
|
14
|
+
</td>
|
15
|
+
<td><p><%= link_to t('edit'), edit_account_path %></p></td>
|
16
|
+
<% end %>
|
17
|
+
</tr>
|
18
|
+
</table>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<% @body_id = 'login' %>
|
2
|
+
<div id="existing-customer">
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<% if @user.anonymous? %>
|
6
|
+
<%= render :partial => 'shared/social_registrations', :locals => {:user => @user, :omniauth => @omniauth} %>
|
7
|
+
<% else %>
|
8
|
+
<td><%= t("email") %>:</td>
|
9
|
+
<td>
|
10
|
+
<%= @user.email %>
|
11
|
+
</td>
|
12
|
+
<td><p><%= link_to t('edit'), edit_account_path %></p></td>
|
13
|
+
<% end %>
|
14
|
+
</tr>
|
15
|
+
</table>
|
16
|
+
|
17
|
+
<% if @user.user_authentications %>
|
18
|
+
<% unless @user.user_authentications.empty? %>
|
19
|
+
<p><strong>You have signed in with these services:</strong></p>
|
20
|
+
<div class="authentications">
|
21
|
+
<% for user_authentication in @user.user_authentications %>
|
22
|
+
<div class="authentication">
|
23
|
+
<%= image_tag "social/#{user_authentication.provider}_32.png", :size => "32x32" %>
|
24
|
+
<div class="provider"><%= user_authentication.provider %></div>
|
25
|
+
<div class="uid"><%= user_authentication.nickname %></div>
|
26
|
+
<%= link_to( "X", user_authentication, :confirm => 'Are you sure you want to remove this authentication option?', :method => :delete, :class => "remove") %>
|
27
|
+
</div>
|
28
|
+
<% end %>
|
29
|
+
<div class="clear"></div>
|
30
|
+
</div>
|
31
|
+
<% end %>
|
32
|
+
</div>
|
33
|
+
<p><strong>Add another service to sign in with:</strong></p>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<%= hook :login_extras %>
|
37
|
+
|
38
|
+
<div class="clear"></div>
|
39
|
+
|
40
|
+
<% content_for :head do %>
|
41
|
+
<%= stylesheet_link_tag 'social.css' %>
|
42
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<% @body_id = 'login' %>
|
2
|
+
<div id="existing-customer">
|
3
|
+
<h2><%= t("login_as_existing") %></h2>
|
4
|
+
<%= form_for(:user, :url => merge_user_path) do |f| %>
|
5
|
+
<%= hidden_field_tag(:user_authentication, current_user.user_authentications.first.id) %>
|
6
|
+
<%= f.hidden_field(:id) %>
|
7
|
+
<div id='password-credentials'>
|
8
|
+
<p>
|
9
|
+
<%= f.label(:email, t("email")) %><br />
|
10
|
+
<%= f.text_field('email', :class => 'title') %>
|
11
|
+
</p>
|
12
|
+
<p>
|
13
|
+
<%= f.label :password, t("password") %><br />
|
14
|
+
<%= f.password_field 'password', :class => 'title' %>
|
15
|
+
</p>
|
16
|
+
</div>
|
17
|
+
<p><%= submit_tag t("log_in"), :class => 'button primary'%></p>
|
18
|
+
<%= link_to t("forgot_password"), new_user_password_path %>
|
19
|
+
<% end %>
|
20
|
+
</div>
|
data/lib/spree_social.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'spree_auth'
|
3
|
+
require 'omniauth/oauth'
|
4
|
+
require "spree_social_hooks"
|
5
|
+
|
6
|
+
module SpreeSocial
|
7
|
+
|
8
|
+
PROVIDERS = [
|
9
|
+
"facebook",
|
10
|
+
"twitter",
|
11
|
+
"github"
|
12
|
+
]
|
13
|
+
|
14
|
+
class Engine < Rails::Engine
|
15
|
+
def self.activate
|
16
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
17
|
+
Rails.env.production? ? require(c) : load(c)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
config.to_prepare &method(:activate).to_proc
|
21
|
+
end
|
22
|
+
|
23
|
+
# We are setting these providers up regardless
|
24
|
+
# This way we can update them when and where necessary
|
25
|
+
def self.init_provider(provider)
|
26
|
+
key, secret = nil
|
27
|
+
AuthenticationMethod.where(:environment => ::Rails.env).each do |user|
|
28
|
+
if user.preferred_provider == provider
|
29
|
+
key = user.preferred_api_key
|
30
|
+
secret = user.preferred_api_secret
|
31
|
+
end
|
32
|
+
end if self.table_exists?("authentication_methods") # See Below for explanation
|
33
|
+
self.setup_key_for(provider.to_sym, key, secret)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.setup_key_for(provider, key, secret)
|
37
|
+
Devise.setup do |oa|
|
38
|
+
oa.omniauth provider.to_sym, key, secret
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Coming soon to a server near you: no restart to get new keys setup
|
43
|
+
#def self.reset_key_for(provider, *args)
|
44
|
+
# puts "ARGS: #{args}"
|
45
|
+
# Devise.omniauth_configs[provider] = Devise::OmniAuth::Config.new(provider, args)
|
46
|
+
# #oa_updated_provider
|
47
|
+
# #Devise.omniauth_configs.merge!(oa_updated_provider)
|
48
|
+
# puts "OmniAuth #{provider}: #{Devise.omniauth_configs[provider.to_sym].inspect}"
|
49
|
+
#end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# Have to test for this cause Rails migrations and initial setups will fail
|
54
|
+
def self.table_exists?(name)
|
55
|
+
ActiveRecord::Base.connection.tables.include?(name)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class SocialHooks < Spree::ThemeSupport::HookListener
|
2
|
+
replace :account_summary , 'users/social'
|
3
|
+
insert_after :login_extras, 'shared/socials'
|
4
|
+
insert_after :admin_configurations_sidebar_menu, 'admin/shared/sidebar_menu'
|
5
|
+
insert_after :admin_configurations_menu, 'admin/shared/configurations_menu'
|
6
|
+
|
7
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :spree_social 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_social:install:migrations'].invoke
|
5
|
+
Rake::Task['spree_social: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,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_social
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- John Brien Dilts
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-14 00:00:00 -05: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: 191
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 40
|
33
|
+
- 0
|
34
|
+
version: 0.40.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: spree_auth
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 191
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 40
|
49
|
+
- 0
|
50
|
+
version: 0.40.0
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: devise
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - "="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 7712074
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 2
|
65
|
+
- rc
|
66
|
+
version: 1.2.rc
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: oa-oauth
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 1
|
81
|
+
- 6
|
82
|
+
version: 0.1.6
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
description:
|
86
|
+
email: jdilts@railsdog.com
|
87
|
+
executables: []
|
88
|
+
|
89
|
+
extensions: []
|
90
|
+
|
91
|
+
extra_rdoc_files: []
|
92
|
+
|
93
|
+
files:
|
94
|
+
- README.md
|
95
|
+
- LICENSE
|
96
|
+
- lib/spree_social.rb
|
97
|
+
- lib/spree_social_hooks.rb
|
98
|
+
- lib/tasks/install.rake
|
99
|
+
- lib/tasks/spree_social.rake
|
100
|
+
- app/controllers/admin/authentication_methods_controller.rb
|
101
|
+
- app/controllers/omniauth_callbacks_controller.rb
|
102
|
+
- app/controllers/user_authentications_controller.rb
|
103
|
+
- app/controllers/user_registrations_controller_decorator.rb
|
104
|
+
- app/controllers/user_sessions_controller_decorator.rb
|
105
|
+
- app/models/authentication_method.rb
|
106
|
+
- app/models/user_authentication.rb
|
107
|
+
- app/models/user_decorator.rb
|
108
|
+
- app/views/admin/authentication_methods/_form.html.erb
|
109
|
+
- app/views/admin/authentication_methods/edit.html.erb
|
110
|
+
- app/views/admin/authentication_methods/index.html.erb
|
111
|
+
- app/views/admin/authentication_methods/new.html.erb
|
112
|
+
- app/views/admin/shared/_configurations_menu.html.erb
|
113
|
+
- app/views/admin/shared/_sidebar_menu.html.erb
|
114
|
+
- app/views/shared/_socials.html.erb
|
115
|
+
- app/views/user_registrations/new.html.erb
|
116
|
+
- app/views/user_registrations/social_edit.html.erb
|
117
|
+
- app/views/users/_social.html.erb
|
118
|
+
- app/views/users/merge.html.erb
|
119
|
+
has_rdoc: true
|
120
|
+
homepage: http://spreecommerce.com
|
121
|
+
licenses: []
|
122
|
+
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 57
|
134
|
+
segments:
|
135
|
+
- 1
|
136
|
+
- 8
|
137
|
+
- 7
|
138
|
+
version: 1.8.7
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
hash: 3
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
requirements:
|
149
|
+
- none
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.4.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Adds social network login services (OAuth) to Spree
|
155
|
+
test_files: []
|
156
|
+
|