spree_social 1.0.2 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/README.md +10 -0
  2. data/app/controllers/omniauth_callbacks_controller.rb +27 -19
  3. data/app/controllers/user_authentications_controller.rb +12 -3
  4. data/app/controllers/user_registrations_controller_decorator.rb +8 -8
  5. data/app/controllers/user_sessions_controller_decorator.rb +7 -9
  6. data/app/models/social_ability.rb +25 -0
  7. data/app/models/user_decorator.rb +3 -1
  8. data/app/views/admin/authentication_methods/_form.html.erb +1 -1
  9. data/app/views/user_registrations/social_edit.html.erb +6 -6
  10. data/app/views/users/merge.html.erb +2 -2
  11. data/lib/spree_social.rb +19 -14
  12. data/public/images/social/aol_128.png +0 -0
  13. data/public/images/social/aol_256.png +0 -0
  14. data/public/images/social/aol_32.png +0 -0
  15. data/public/images/social/aol_64.png +0 -0
  16. data/public/images/social/campfire_128.png +0 -0
  17. data/public/images/social/campfire_256.png +0 -0
  18. data/public/images/social/campfire_32.png +0 -0
  19. data/public/images/social/campfire_64.png +0 -0
  20. data/public/images/social/myspace_128.png +0 -0
  21. data/public/images/social/myspace_256.png +0 -0
  22. data/public/images/social/myspace_32.png +0 -0
  23. data/public/images/social/myspace_64.png +0 -0
  24. data/public/images/social/openid_128.png +0 -0
  25. data/public/images/social/openid_256.png +0 -0
  26. data/public/images/social/openid_32.png +0 -0
  27. data/public/images/social/openid_64.png +0 -0
  28. data/public/images/social/presently_128.png +0 -0
  29. data/public/images/social/presently_256.png +0 -0
  30. data/public/images/social/presently_32.png +0 -0
  31. data/public/images/social/presently_64.png +0 -0
  32. data/public/images/social/thirty_seven_signals_128.png +0 -0
  33. data/public/images/social/thirty_seven_signals_256.png +0 -0
  34. data/public/images/social/thirty_seven_signals_32.png +0 -0
  35. data/public/images/social/thirty_seven_signals_64.png +0 -0
  36. metadata +39 -17
data/README.md CHANGED
@@ -79,6 +79,16 @@ OAuth Applications @ Facebook, Twitter and / or Github are supported out of the
79
79
 
80
80
  > Coming Soon
81
81
 
82
+ ### 37 Signals
83
+
84
+ [37 Signals](https://integrate.37signals.com): [https://integrate.37signals.com](https://integrate.37signals.com)
85
+
86
+ > This include Basecamp, HighRise, Campfire, and Backpack. It is referred to as Basecamp in the admin
87
+
88
+ 1. Name The Application, Your Company, and Your URL
89
+ 2. Check one or all of the 37 Signals apps you use
90
+ 3. Redirect URI (at the bottom of the page) http://your_computer.local:3000
91
+
82
92
  Setup for Development
83
93
  ---------------------
84
94
 
@@ -3,33 +3,40 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
3
3
  include SpreeBase
4
4
  helper :users, 'spree/base'
5
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")
6
+ SpreeSocial::OAUTH_PROVIDERS.each do |provider|
7
+ method_name = (provider[1]).to_sym
8
+ send :define_method, method_name do
9
+ social_setup(provider[1].capitalize)
10
+ end
16
11
  end
12
+
13
+ #def facebook
14
+ # social_setups("Facebook")
15
+ #end
16
+ #
17
+ #def twitter
18
+ # social_setups("Twitter")
19
+ #end
20
+ #
21
+ #def github
22
+ # social_setups("Github")
23
+ #end
17
24
 
18
25
  private
19
26
 
20
- def social_setups(provider)
27
+ def social_setup(provider)
21
28
  omniauth = request.env["omniauth.auth"]
22
-
29
+
23
30
  if request.env["omniauth.error"].present?
24
31
  flash[:error] = t("devise.omniauth_callbacks.failure", :kind => provider, :reason => "user was not valid")
25
32
  redirect_back_or_default(root_url)
26
33
  return
27
34
  end
28
-
35
+
29
36
  existing_auth = UserAuthentication.where(:provider => omniauth['provider'], :uid => omniauth['uid'].to_s).first
30
-
37
+
31
38
  #signing back in from a social source
32
- if existing_auth
39
+ if existing_auth
33
40
  user = existing_auth.user
34
41
  else # adding a social source
35
42
  user = current_user
@@ -43,10 +50,11 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
43
50
  current_order.associate_user!(user)
44
51
  session[:guest_token] = nil
45
52
  end
46
-
53
+
47
54
  if user.anonymous?
48
- sign_in(user, :event => :authentication) unless current_user
49
- flash[:notice] = t("one_more_step", :kind => omniauth['provider'].capitalize)
55
+ session[:user_access_token] = user.token #set user access token so we can edit this user again later
56
+
57
+ flash.now[:notice] = t("one_more_step", :kind => omniauth['provider'].capitalize)
50
58
  render(:template => "user_registrations/social_edit", :locals => {:user => user, :omniauth => omniauth})
51
59
  elsif current_user
52
60
  flash[:error] = t("attach_error", :kind => omniauth['provider'].capitalize) if existing_auth && (existing_auth.user != current_user)
@@ -56,4 +64,4 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
56
64
  end
57
65
  end
58
66
 
59
- end
67
+ end
@@ -1,20 +1,29 @@
1
1
  class UserAuthenticationsController < Spree::BaseController
2
-
2
+
3
3
  def update
4
4
  @user = User.find(params[:id])
5
+
6
+ authorize! :edit, @user, session[:user_access_token]
7
+
8
+ session[:user_access_token] = nil
9
+
5
10
  @user.email = params[:user][:email]
6
11
  if @user.save
12
+ sign_in(@user, :event => :authentication) unless current_user
7
13
  redirect_back_or_default(products_path)
8
14
  else
9
15
  flash.now[:error] = "There is already an account with that email. Please sign in to associate these accounts."
10
16
  render(:template => 'users/merge')
11
17
  end
12
18
  end
13
-
19
+
14
20
  def destroy
15
21
  @auth = current_user.user_authentications.find(params[:id])
22
+
23
+ authorize! :destroy, @auth
24
+
16
25
  @auth.destroy
17
26
  flash[:notice] = "Successfully deleted authentication source."
18
27
  redirect_to account_path
19
28
  end
20
- end
29
+ end
@@ -1,17 +1,17 @@
1
1
  UserRegistrationsController.class_eval do
2
-
2
+
3
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?
4
+ super.tap do |resp|
5
+ if @user && @user.new_record? && resp.respond_to?(:session)
6
+ @omniauth = resp.session[:session]
7
+ resp.session[:omniauth] = nil unless @user.new_record?
8
8
  end
9
9
  end
10
10
  end
11
-
11
+
12
12
  def delete
13
13
  session[:omniauth] = nil
14
14
  redirect_to signin_path
15
15
  end
16
-
17
- end
16
+
17
+ end
@@ -1,26 +1,24 @@
1
1
  UserSessionsController.class_eval do
2
-
3
- def merge
4
- # lets remove the old user here
5
- sign_out(:user)
2
+
3
+ def merge
6
4
  # now sign in from the login form
7
5
  authenticate_user!
8
-
6
+
9
7
  # prep for all the shifting and do it
10
8
  user = User.find(current_user.id)
11
9
  user.user_authentications << UserAuthentication.find(params[:user_authentication])
12
10
  user.save!
13
-
11
+
14
12
  if current_order
15
13
  current_order.associate_user!(user)
16
14
  session[:guest_token] = nil
17
15
  end
18
16
  # trash the old anonymous that was created
19
17
  User.destroy(params[:user][:id])
20
-
18
+
21
19
  # tell the truth now
22
20
  flash[:alert] = "Succesfully linked your accounts"
23
21
  sign_in_and_redirect(user, :event => :authentication)
24
22
  end
25
-
26
- end
23
+
24
+ end
@@ -0,0 +1,25 @@
1
+ class SocialAbility
2
+ # stuff like class AbilityDecorator goes here
3
+ include CanCan::Ability
4
+
5
+ def initialize(user)
6
+
7
+ can :create, UserAuthentication do
8
+ !user.new_record?
9
+ end
10
+
11
+ can :destroy, UserAuthentication do |user_authentication|
12
+ user_authentication.user == user
13
+ end
14
+
15
+ can :read, User do |resource, token|
16
+ resource == user || resource.token && token == resource.token
17
+ end
18
+
19
+ can :update, User do |resource, token|
20
+ resource == user || resource.token && token == resource.token
21
+ end
22
+ end
23
+ end
24
+
25
+
@@ -1,4 +1,6 @@
1
1
  User.class_eval do
2
+ token_resource
3
+
2
4
  has_many :user_authentications
3
5
 
4
6
  # Associates user to auth source
@@ -12,4 +14,4 @@ User.class_eval do
12
14
  (user_authentications.empty? || !password.blank?) && super
13
15
  end
14
16
 
15
- end
17
+ end
@@ -18,7 +18,7 @@
18
18
 
19
19
  <p>
20
20
  <label><%= t('social_provider') %></label><br />
21
- <%= f.select :preferred_provider, SpreeSocial::PROVIDERS, {:include_blank => true} %>
21
+ <%= f.select :preferred_provider, SpreeSocial::OAUTH_PROVIDERS, {:include_blank => true} %>
22
22
  <br/>
23
23
  <span class="info">
24
24
  <%= t("social_provider") %>
@@ -8,11 +8,11 @@
8
8
  <td><%=submit_tag t("update") %></td>
9
9
  <% end %>
10
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>
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
16
  <% end %>
17
17
  </tr>
18
- </table>
18
+ </table>
@@ -2,7 +2,7 @@
2
2
  <div id="existing-customer">
3
3
  <h2><%= t("login_as_existing") %></h2>
4
4
  <%= form_for(:user, :url => merge_user_path) do |f| %>
5
- <%= hidden_field_tag(:user_authentication, current_user.user_authentications.first.id) %>
5
+ <%= hidden_field_tag(:user_authentication, @user.user_authentications.first.id) %>
6
6
  <%= f.hidden_field(:id) %>
7
7
  <div id='password-credentials'>
8
8
  <p>
@@ -17,4 +17,4 @@
17
17
  <p><%= submit_tag t("log_in"), :class => 'button primary'%></p>
18
18
  <%= link_to t("forgot_password"), new_user_password_path %>
19
19
  <% end %>
20
- </div>
20
+ </div>
@@ -4,41 +4,46 @@ require 'omniauth/oauth'
4
4
  require "spree_social_hooks"
5
5
 
6
6
  module SpreeSocial
7
-
8
- PROVIDERS = [
9
- "facebook",
10
- "twitter",
11
- "github"
7
+
8
+ OAUTH_PROVIDERS = [
9
+ ["Bit.ly", "bitly"], ["Evernote", "evernote"], ["Facebook", "facebook"], ["Foursquare", "foursquare"],
10
+ ["Github", "github"], ["Google", "google"] , ["Gowalla", "gowalla"], ["instagr.am", "instagram"],
11
+ ["Instapaper", "instapaper"], ["LinkedIn", "linked_in"], ["37Signals (Basecamp, Campfire, etc)", "thirty_seven_signals"],
12
+ ["Twitter", "twitter"], ["Vimeo", "vimeo"], ["Yahoo!", "yahoo"], ["YouTube", "you_tube"]
12
13
  ]
13
-
14
+
15
+
16
+
14
17
  class Engine < Rails::Engine
15
18
  def self.activate
16
19
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
17
20
  Rails.env.production? ? require(c) : load(c)
18
21
  end
22
+ Ability.register_ability(SocialAbility)
19
23
  end
20
24
  config.to_prepare &method(:activate).to_proc
21
25
  end
22
-
26
+
23
27
  # We are setting these providers up regardless
24
28
  # This way we can update them when and where necessary
25
29
  def self.init_provider(provider)
26
30
  key, secret = nil
27
31
  AuthenticationMethod.where(:environment => ::Rails.env).each do |user|
28
- if user.preferred_provider == provider
32
+ if user.preferred_provider == provider[1]
29
33
  key = user.preferred_api_key
30
34
  secret = user.preferred_api_secret
35
+ puts("Loaded #{user.preferred_provider.capitalize} as authentication source")
31
36
  end
32
37
  end if self.table_exists?("authentication_methods") # See Below for explanation
33
- self.setup_key_for(provider.to_sym, key, secret)
38
+ self.setup_key_for(provider[1].to_sym, key, secret)
34
39
  end
35
-
40
+
36
41
  def self.setup_key_for(provider, key, secret)
37
42
  Devise.setup do |oa|
38
43
  oa.omniauth provider.to_sym, key, secret
39
44
  end
40
45
  end
41
-
46
+
42
47
  # Coming soon to a server near you: no restart to get new keys setup
43
48
  #def self.reset_key_for(provider, *args)
44
49
  # puts "ARGS: #{args}"
@@ -47,11 +52,11 @@ module SpreeSocial
47
52
  # #Devise.omniauth_configs.merge!(oa_updated_provider)
48
53
  # puts "OmniAuth #{provider}: #{Devise.omniauth_configs[provider.to_sym].inspect}"
49
54
  #end
50
-
55
+
51
56
  private
52
-
57
+
53
58
  # Have to test for this cause Rails migrations and initial setups will fail
54
59
  def self.table_exists?(name)
55
60
  ActiveRecord::Base.connection.tables.include?(name)
56
61
  end
57
- end
62
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_social
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
- - 2
10
- version: 1.0.2
8
+ - 1
9
+ version: "1.1"
11
10
  platform: ruby
12
11
  authors:
13
12
  - John Brien Dilts
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-25 00:00:00 -05:00
17
+ date: 2011-04-19 00:00:00 -04:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -51,35 +50,33 @@ dependencies:
51
50
  type: :runtime
52
51
  version_requirements: *id002
53
52
  - !ruby/object:Gem::Dependency
54
- name: devise
53
+ name: oa-oauth
55
54
  prerelease: false
56
55
  requirement: &id003 !ruby/object:Gem::Requirement
57
56
  none: false
58
57
  requirements:
59
- - - "="
58
+ - - ">="
60
59
  - !ruby/object:Gem::Version
61
- hash: 7712074
60
+ hash: 19
62
61
  segments:
63
- - 1
62
+ - 0
63
+ - 2
64
64
  - 2
65
- - rc
66
- version: 1.2.rc
65
+ version: 0.2.2
67
66
  type: :runtime
68
67
  version_requirements: *id003
69
68
  - !ruby/object:Gem::Dependency
70
- name: oa-oauth
69
+ name: evernote
71
70
  prerelease: false
72
71
  requirement: &id004 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ">="
76
75
  - !ruby/object:Gem::Version
77
- hash: 23
76
+ hash: 3
78
77
  segments:
79
78
  - 0
80
- - 1
81
- - 6
82
- version: 0.1.6
79
+ version: "0"
83
80
  type: :runtime
84
81
  version_requirements: *id004
85
82
  description:
@@ -103,6 +100,7 @@ files:
103
100
  - app/controllers/user_registrations_controller_decorator.rb
104
101
  - app/controllers/user_sessions_controller_decorator.rb
105
102
  - app/models/authentication_method.rb
103
+ - app/models/social_ability.rb
106
104
  - app/models/user_authentication.rb
107
105
  - app/models/user_decorator.rb
108
106
  - app/views/admin/authentication_methods/_form.html.erb
@@ -118,6 +116,14 @@ files:
118
116
  - app/views/users/merge.html.erb
119
117
  - db/migrate/20101117212408_create_user_authentications.rb
120
118
  - db/migrate/20101207152830_create_authentication_methods.rb
119
+ - public/images/social/aol_128.png
120
+ - public/images/social/aol_256.png
121
+ - public/images/social/aol_32.png
122
+ - public/images/social/aol_64.png
123
+ - public/images/social/campfire_128.png
124
+ - public/images/social/campfire_256.png
125
+ - public/images/social/campfire_32.png
126
+ - public/images/social/campfire_64.png
121
127
  - public/images/social/facebook_128.png
122
128
  - public/images/social/facebook_256.png
123
129
  - public/images/social/facebook_32.png
@@ -134,6 +140,22 @@ files:
134
140
  - public/images/social/linkedin_256.png
135
141
  - public/images/social/linkedin_32.png
136
142
  - public/images/social/linkedin_64.png
143
+ - public/images/social/myspace_128.png
144
+ - public/images/social/myspace_256.png
145
+ - public/images/social/myspace_32.png
146
+ - public/images/social/myspace_64.png
147
+ - public/images/social/openid_128.png
148
+ - public/images/social/openid_256.png
149
+ - public/images/social/openid_32.png
150
+ - public/images/social/openid_64.png
151
+ - public/images/social/presently_128.png
152
+ - public/images/social/presently_256.png
153
+ - public/images/social/presently_32.png
154
+ - public/images/social/presently_64.png
155
+ - public/images/social/thirty_seven_signals_128.png
156
+ - public/images/social/thirty_seven_signals_256.png
157
+ - public/images/social/thirty_seven_signals_32.png
158
+ - public/images/social/thirty_seven_signals_64.png
137
159
  - public/images/social/twitter_128.png
138
160
  - public/images/social/twitter_256.png
139
161
  - public/images/social/twitter_32.png
@@ -175,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
197
  requirements:
176
198
  - none
177
199
  rubyforge_project:
178
- rubygems_version: 1.4.2
200
+ rubygems_version: 1.6.2
179
201
  signing_key:
180
202
  specification_version: 3
181
203
  summary: Adds social network login services (OAuth) to Spree