spree_auth 0.30.2 → 0.40.0

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.

Potentially problematic release.


This version of spree_auth might be problematic. Click here for more details.

Files changed (42) hide show
  1. data/app/controllers/checkout_controller_decorator.rb +2 -2
  2. data/app/controllers/orders_controller_decorator.rb +4 -3
  3. data/app/controllers/resource_controller_decorator.rb +6 -2
  4. data/app/controllers/spree/base_controller_decorator.rb +8 -25
  5. data/app/controllers/user_password_resets_controller.rb +20 -0
  6. data/app/controllers/user_registrations_controller.rb +56 -0
  7. data/app/controllers/user_sessions_controller.rb +21 -82
  8. data/app/controllers/users_controller.rb +1 -13
  9. data/app/helpers/users_helper.rb +13 -0
  10. data/app/models/ability.rb +4 -4
  11. data/app/models/order_decorator.rb +4 -3
  12. data/app/models/spree_current_order_decorator.rb +1 -1
  13. data/app/models/tokenized_permission.rb +3 -0
  14. data/app/models/user.rb +14 -16
  15. data/app/models/user_mailer.rb +2 -3
  16. data/app/views/checkout/registration.html.erb +1 -1
  17. data/app/views/shared/_error_messages.html.erb +1 -1
  18. data/app/views/shared/_login.html.erb +20 -0
  19. data/app/views/shared/_login_bar.html.erb +1 -1
  20. data/app/views/shared/_user_form.html.erb +17 -0
  21. data/app/views/user_mailer/{password_reset_instructions.erb → reset_password_instructions.text.erb} +0 -0
  22. data/app/views/user_password_resets/edit.html.erb +15 -0
  23. data/app/views/{password_resets → user_password_resets}/new.html.erb +4 -4
  24. data/app/views/{users → user_registrations}/new.html.erb +2 -2
  25. data/app/views/user_sessions/new.html.erb +6 -2
  26. data/app/views/users/edit.html.erb +1 -1
  27. data/config/initializers/devise.rb +136 -0
  28. data/config/locales/en.yml +45 -0
  29. data/config/routes.rb +14 -7
  30. data/db/migrate/20101101185116_rename_columns_for_devise.rb +38 -0
  31. data/db/migrate/20101214150824_convert_user_remember_field.rb +11 -0
  32. data/db/migrate/20101217012656_create_tokenized_permissions.rb +18 -0
  33. data/db/migrate/20101219201531_tokens_for_legacy_orders.rb +12 -0
  34. data/db/sample/users.rb +1 -1
  35. data/lib/spree/token_resource.rb +23 -0
  36. data/lib/spree_auth.rb +13 -2
  37. data/lib/tasks/install.rake +0 -1
  38. metadata +35 -23
  39. data/app/models/user_session.rb +0 -3
  40. data/app/views/password_resets/edit.html.erb +0 -12
  41. data/lib/cancan/controller_additions.rb +0 -60
  42. data/lib/spree/auth_user.rb +0 -16
@@ -0,0 +1,12 @@
1
+ class TokensForLegacyOrders < ActiveRecord::Migration
2
+ def self.up
3
+ # add token permissions for legacy orders (stop relying on user persistence token)
4
+ Order.all.each do |order|
5
+ next unless order.user
6
+ order.create_tokenized_permission(:token => order.user.persistence_token)
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ end
12
+ end
data/db/sample/users.rb CHANGED
@@ -21,7 +21,7 @@ end
21
21
 
22
22
  def create_admin_user
23
23
  if ENV['AUTO_ACCEPT']
24
- password = "spree"
24
+ password = "spree123"
25
25
  email = "spree@example.com"
26
26
  else
27
27
  require 'highline/import'
@@ -0,0 +1,23 @@
1
+ module Spree::TokenResource
2
+
3
+ module ClassMethods
4
+ def token_resource
5
+ has_one :tokenized_permission, :as => :permissable
6
+ delegate :token, :to => :tokenized_permission, :allow_nil => true
7
+ after_create :create_token
8
+ end
9
+ end
10
+
11
+ module InstanceMethods
12
+ def create_token
13
+ create_tokenized_permission(:token => ActiveSupport::SecureRandom::hex(8))
14
+ token
15
+ end
16
+ end
17
+
18
+ def self.included(receiver)
19
+ receiver.extend ClassMethods
20
+ receiver.send :include, InstanceMethods
21
+ end
22
+
23
+ end
data/lib/spree_auth.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'spree_core'
2
- require 'authlogic'
2
+ require 'devise'
3
3
  require 'cancan'
4
4
 
5
- require 'spree/auth_user'
6
5
  require 'spree/auth/config'
6
+ require 'spree/token_resource'
7
7
 
8
8
  module SpreeAuth
9
9
  class Engine < Rails::Engine
@@ -11,7 +11,18 @@ module SpreeAuth
11
11
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
12
12
  Rails.env.production? ? require(c) : load(c)
13
13
  end
14
+
15
+ # monkey patch until new version of devise comes out
16
+ # https://github.com/plataformatec/devise/commit/ec5bfe9119d0e1e633629793b0de1f58f89622dc
17
+ Devise::IndifferentHash.class_eval do
18
+ def [](key)
19
+ super(convert_key(key))
20
+ end
21
+ def to_hash; Hash.new.update(self) end
22
+ end
14
23
  end
24
+
15
25
  config.to_prepare &method(:activate).to_proc
26
+ ActiveRecord::Base.class_eval { include Spree::TokenResource }
16
27
  end
17
28
  end
@@ -11,7 +11,6 @@ namespace :spree_auth do
11
11
  task :migrations do
12
12
  source = File.join(File.dirname(__FILE__), '..', '..', 'db')
13
13
  destination = File.join(Rails.root, 'db')
14
- puts "INFO: Mirroring assets from #{source} to #{destination}"
15
14
  Spree::FileUtilz.mirror_files(source, destination)
16
15
  end
17
16
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_auth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 99
5
- prerelease:
4
+ hash: 191
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 30
9
- - 2
10
- version: 0.30.2
8
+ - 40
9
+ - 0
10
+ version: 0.40.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Schofield
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-23 00:00:00 Z
18
+ date: 2010-12-22 00:00:00 -05:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: spree_core
@@ -25,28 +26,28 @@ dependencies:
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
28
- hash: 99
29
+ hash: 191
29
30
  segments:
30
31
  - 0
31
- - 30
32
- - 2
33
- version: 0.30.2
32
+ - 40
33
+ - 0
34
+ version: 0.40.0
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  - !ruby/object:Gem::Dependency
37
- name: authlogic
38
+ name: devise
38
39
  prerelease: false
39
40
  requirement: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - "="
43
44
  - !ruby/object:Gem::Version
44
- hash: 7
45
+ hash: 7712074
45
46
  segments:
46
- - 2
47
47
  - 1
48
- - 6
49
- version: 2.1.6
48
+ - 2
49
+ - rc
50
+ version: 1.2.rc
50
51
  type: :runtime
51
52
  version_requirements: *id002
52
53
  - !ruby/object:Gem::Dependency
@@ -81,36 +82,47 @@ files:
81
82
  - app/controllers/orders_controller_decorator.rb
82
83
  - app/controllers/resource_controller_decorator.rb
83
84
  - app/controllers/spree/base_controller_decorator.rb
85
+ - app/controllers/user_password_resets_controller.rb
86
+ - app/controllers/user_registrations_controller.rb
84
87
  - app/controllers/user_sessions_controller.rb
85
88
  - app/controllers/users_controller.rb
89
+ - app/helpers/users_helper.rb
86
90
  - app/models/ability.rb
87
91
  - app/models/order_decorator.rb
88
92
  - app/models/spree_auth_configuration.rb
89
93
  - app/models/spree_current_order_decorator.rb
94
+ - app/models/tokenized_permission.rb
90
95
  - app/models/user.rb
91
96
  - app/models/user_mailer.rb
92
- - app/models/user_session.rb
93
97
  - app/views/checkout/registration.html.erb
94
- - app/views/password_resets/edit.html.erb
95
- - app/views/password_resets/new.html.erb
96
98
  - app/views/shared/_error_messages.html.erb
97
99
  - app/views/shared/_flashes.html.erb
100
+ - app/views/shared/_login.html.erb
98
101
  - app/views/shared/_login_bar.html.erb
102
+ - app/views/shared/_user_form.html.erb
99
103
  - app/views/shared/unauthorized.html.erb
100
- - app/views/user_mailer/password_reset_instructions.erb
104
+ - app/views/user_mailer/reset_password_instructions.text.erb
105
+ - app/views/user_password_resets/edit.html.erb
106
+ - app/views/user_password_resets/new.html.erb
107
+ - app/views/user_registrations/new.html.erb
101
108
  - app/views/user_sessions/authorization_failure.html.erb
102
109
  - app/views/user_sessions/new.html.erb
103
110
  - app/views/users/edit.html.erb
104
- - app/views/users/new.html.erb
105
111
  - app/views/users/show.html.erb
112
+ - config/initializers/devise.rb
113
+ - config/locales/en.yml
106
114
  - config/routes.rb
107
- - lib/cancan/controller_additions.rb
108
115
  - lib/spree/auth/config.rb
109
- - lib/spree/auth_user.rb
116
+ - lib/spree/token_resource.rb
110
117
  - lib/spree_auth.rb
111
118
  - lib/tasks/auth.rake
112
119
  - lib/tasks/install.rake
120
+ - db/migrate/20101101185116_rename_columns_for_devise.rb
121
+ - db/migrate/20101214150824_convert_user_remember_field.rb
122
+ - db/migrate/20101217012656_create_tokenized_permissions.rb
123
+ - db/migrate/20101219201531_tokens_for_legacy_orders.rb
113
124
  - db/sample/users.rb
125
+ has_rdoc: true
114
126
  homepage: http://spreecommerce.com
115
127
  licenses: []
116
128
 
@@ -142,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
154
  requirements:
143
155
  - none
144
156
  rubyforge_project: spree_auth
145
- rubygems_version: 1.8.10
157
+ rubygems_version: 1.3.7
146
158
  signing_key:
147
159
  specification_version: 3
148
160
  summary: Provides authentication and authorization services for use with Spree.
@@ -1,3 +0,0 @@
1
- class UserSession < Authlogic::Session::Base
2
- end
3
-
@@ -1,12 +0,0 @@
1
- <h1><%= t(:change_my_password) %></h1>
2
-
3
- <%= form_for @user, :url => password_reset_path, :method => :put do |f| %>
4
- <%= f.error_messages %>
5
- <%= f.label :password %><br />
6
- <%= f.password_field :password %><br />
7
- <br />
8
- <%= f.label :password_confirmation %><br />
9
- <%= f.password_field :password_confirmation %><br />
10
- <br />
11
- <%= f.submit t("update_password") %>
12
- <% end %>
@@ -1,60 +0,0 @@
1
- # Overrides the default current_ability method used by Cancan so that we can use the guest_token in addition to current_user.
2
- # We were having problems layering the custom logic on top of ActionController::Base in certain situations but overriding
3
- # this file within spree_auth seems to do the trick. Documentation has been stripped (see cancan for the original docs.)
4
- # Only the current_ability method has been changed.
5
-
6
- module CanCan
7
-
8
- module ControllerAdditions
9
- module ClassMethods
10
-
11
- def load_and_authorize_resource(*args)
12
- ControllerResource.add_before_filter(self, :load_and_authorize_resource, *args)
13
- end
14
-
15
- def load_resource(*args)
16
- ControllerResource.add_before_filter(self, :load_resource, *args)
17
- end
18
-
19
- def authorize_resource(*args)
20
- ControllerResource.add_before_filter(self, :authorize_resource, *args)
21
- end
22
- end
23
-
24
- def self.included(base)
25
- base.extend ClassMethods
26
- base.helper_method :can?, :cannot?
27
- end
28
-
29
- def authorize!(action, subject, *args)
30
- message = nil
31
- if args.last.kind_of?(Hash) && args.last.has_key?(:message)
32
- message = args.pop[:message]
33
- end
34
- raise AccessDenied.new(message, action, subject) if cannot?(action, subject, *args)
35
- end
36
-
37
- def unauthorized!(message = nil)
38
- raise ImplementationRemoved, "The unauthorized! method has been removed from CanCan, use authorize! instead."
39
- end
40
-
41
- def current_ability
42
- # HACKED to use Spree's auth_user instead of current_user
43
- @current_ability ||= ::Ability.new(auth_user)
44
- end
45
-
46
- def can?(*args)
47
- current_ability.can?(*args)
48
- end
49
-
50
- def cannot?(*args)
51
- current_ability.cannot?(*args)
52
- end
53
- end
54
- end
55
-
56
- if defined? ActionController
57
- ActionController::Base.class_eval do
58
- include CanCan::ControllerAdditions
59
- end
60
- end
@@ -1,16 +0,0 @@
1
- module Spree
2
- module AuthUser
3
-
4
- # Gives controllers the ability to learn the +auth_user+ as opposed to limiting them to just the standard
5
- # +current_user.+ The +auth_user+ method will return the user corresponding to the +guest_token+ if present,
6
- # otherwise it will return the +current_user.+ This allows us to check authorization against a guest user
7
- # without requiring that user to be signed in. This means the guest can later sign up for
8
- # an acccount (or log in to an existing account.)
9
- def auth_user
10
- return current_user if current_user
11
- return nil if session[:guest_token].blank?
12
- User.find_by_persistence_token(session[:guest_token])
13
- end
14
-
15
- end
16
- end