spree_auth_devise 4.1.0.rc1 → 4.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +32 -23
  3. data/Appraisals +1 -1
  4. data/README.md +3 -12
  5. data/Rakefile +9 -3
  6. data/app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb +20 -0
  7. data/app/controllers/spree/api/v2/storefront/passwords_controller.rb +35 -0
  8. data/app/controllers/spree/user_confirmations_controller.rb +45 -1
  9. data/app/controllers/spree/user_passwords_controller.rb +15 -1
  10. data/app/controllers/spree/user_registrations_controller.rb +33 -1
  11. data/app/controllers/spree/user_sessions_controller.rb +8 -0
  12. data/app/mailers/spree/user_mailer.rb +11 -4
  13. data/app/models/spree/user.rb +42 -0
  14. data/app/services/spree/account/create.rb +19 -0
  15. data/app/services/spree/account/update.rb +17 -0
  16. data/app/views/spree/user_mailer/confirmation_instructions.html.erb +20 -0
  17. data/app/views/spree/user_mailer/confirmation_instructions.text.erb +8 -5
  18. data/app/views/spree/user_mailer/reset_password_instructions.html.erb +20 -0
  19. data/app/views/spree/user_mailer/reset_password_instructions.text.erb +7 -5
  20. data/app/views/spree/user_passwords/new.html.erb +2 -3
  21. data/config/locales/de.yml +16 -0
  22. data/config/locales/en.yml +21 -6
  23. data/config/locales/zh-TW.yml +58 -0
  24. data/config/routes.rb +12 -2
  25. data/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb +2 -2
  26. data/gemfiles/spree_4_1.gemfile +1 -1
  27. data/lib/controllers/api/spree/api/v2/storefront/account_controller_decorator.rb +41 -0
  28. data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +3 -2
  29. data/lib/controllers/frontend/spree/users_controller.rb +3 -3
  30. data/lib/spree/auth/engine.rb +14 -1
  31. data/lib/spree_auth_devise.rb +0 -1
  32. data/lib/views/backend/spree/admin/user_passwords/new.html.erb +1 -1
  33. data/lib/views/backend/spree/admin/user_sessions/new.html.erb +1 -1
  34. data/spec/controllers/spree/api/v2/storefront/passwords_controller_spec.rb +63 -0
  35. data/spec/controllers/spree/user_registrations_controller_spec.rb +1 -1
  36. data/spec/features/admin/sign_in_spec.rb +8 -2
  37. data/spec/features/checkout_spec.rb +4 -4
  38. data/spec/features/confirmation_spec.rb +3 -3
  39. data/spec/features/sign_in_spec.rb +13 -7
  40. data/spec/features/sign_out_spec.rb +1 -3
  41. data/spec/features/sign_up_spec.rb +2 -2
  42. data/spec/mailers/user_mailer_spec.rb +3 -3
  43. data/spec/models/user_spec.rb +10 -8
  44. data/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +48 -0
  45. data/spec/requests/spree/api/v2/storefront/account_spec.rb +101 -0
  46. data/spec/spec_helper.rb +7 -38
  47. data/spree_auth_devise.gemspec +12 -29
  48. metadata +29 -359
  49. data/app/overrides/spree/admin/shared/_header/auth_admin_login_navigation_bar.html.erb.deface +0 -4
  50. data/spec/support/add_to_cart.rb +0 -22
  51. data/spec/support/authentication_helpers.rb +0 -14
  52. data/spec/support/cache_helpers.rb +0 -5
  53. data/spec/support/capybara.rb +0 -23
  54. data/spec/support/database_cleaner.rb +0 -17
  55. data/spec/support/factory_girl.rb +0 -5
  56. data/spec/support/spree.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11fab6b968334f977554a9a95b6a80e37047b42add498201ea0db74ca0701a6a
4
- data.tar.gz: cab55c1d0e6344a72c5e11ee8621f43fce3787d99e412515bf9f8059a1727e7c
3
+ metadata.gz: 632dbf0ba8467163e8cff132261a9173f5c4a9b9b670c3e93599d66bb07575a1
4
+ data.tar.gz: 2e400ddce6368507961c686f4e094eb9c09ab47ebb8ecd97ade3c1f425e5ce5d
5
5
  SHA512:
6
- metadata.gz: 83bfc852ef5ac9cd03c19f6a9f8bcbdd17aac744d565102777f4ef1b2910f53d80b6663eee3d7f1dce2dc6f66f0e553270f366086f8e303963f995b72b9d8598
7
- data.tar.gz: 66b5fe7c4364a068ee0b2169713480afb3b0064cc3c883f0ddbf6ee6086cd9b5caac2058b2c5c2cab9da82230a6441659df89ce071bc973a2278fd50a73e5341
6
+ metadata.gz: b07a757183970dc752ad4187daf50acca0783f1914ee4f0ed99a68f533a5e98ee5525dac009bd509760f70c74577f3f6de0d3acf30060bd4319f1b24a495bd02
7
+ data.tar.gz: 1c0fb11dbf07ed2c308a7bd693118254a933c5204e535d0765958679ae6576a098f71671eb18c42b7943e7b1fd18af32eaf1b8273664090e6a8e7dd625a804b6
@@ -1,38 +1,47 @@
1
- sudo: required
2
- dist: trusty
3
-
4
- script:
5
- - bundle exec rake test_app
6
- - bundle exec rake spec
1
+ os: linux
2
+ dist: bionic
7
3
 
8
4
  addons:
9
- chrome: stable
10
- postgresql: 9.4
5
+ apt:
6
+ sources:
7
+ - google-chrome
8
+ packages:
9
+ - google-chrome-stable
11
10
 
12
- env:
13
- - DB=mysql
14
- - DB=postgres
11
+ services:
12
+ - mysql
13
+ - postgresql
15
14
 
16
15
  language: ruby
17
16
 
18
17
  rvm:
19
- - 2.5.1
20
- # - 2.6.5
18
+ - 2.7
19
+ - 3.0
20
+
21
+ env:
22
+ - DB=mysql
23
+ - DB=postgres
21
24
 
22
25
  gemfile:
23
26
  - gemfiles/spree_4_1.gemfile
24
27
  - gemfiles/spree_master.gemfile
25
28
 
26
- matrix:
27
- allow_failures:
28
- - gemfile: gemfiles/spree_master.gemfile
29
+ jobs:
30
+ exclude:
31
+ - rvm: 3.0
32
+ gemfile: gemfiles/spree_4_1.gemfile
33
+ allow_failures:
34
+ - gemfile: gemfiles/spree_master.gemfile
29
35
 
30
36
  before_install:
31
- - gem update bundler
32
37
  - mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
33
- - wget -N https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip -P ~/
34
- - unzip ~/chromedriver_linux64.zip -d ~/
35
- - rm ~/chromedriver_linux64.zip
36
- - sudo mv -f ~/chromedriver /usr/local/share/
37
- - sudo chmod +x /usr/local/share/chromedriver
38
- - sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
38
+
39
+ before_script:
40
+ - CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'`
41
+ - CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"`
42
+ - curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
43
+ - unzip chromedriver_linux64.zip -d ~/bin
44
+
45
+ script:
46
+ - bundle exec rake test_app
47
+ - bundle exec rake spec
data/Appraisals CHANGED
@@ -1,6 +1,6 @@
1
1
  appraise 'spree-4-1' do
2
2
  gem 'rails-controller-testing'
3
- gem 'spree', github: 'spree/spree', branch: 'master'
3
+ gem 'spree', '~> 4.1'
4
4
  end
5
5
 
6
6
  appraise 'spree-master' do
data/README.md CHANGED
@@ -10,20 +10,11 @@ Provides authentication services for [Spree](https://spreecommerce.org), using t
10
10
 
11
11
  1. Add this extension to your Gemfile with this line:
12
12
 
13
- #### Spree >= 3.1
14
-
15
- ```ruby
16
- gem 'spree_auth_devise', '~> 3.3'
17
- ```
18
-
19
- #### Spree 3.0 and Spree 2.x
20
-
21
13
  ```ruby
22
- gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'X-X-stable'
14
+ gem 'spree_auth_devise'
23
15
  ```
24
-
25
- The `branch` option is important: it must match the version of Spree you're using.
26
- For example, use `3-0-stable` if you're using Spree `3-0-stable` or any `3.0.x` version.
16
+
17
+ if you run into any version-mismatch problems please run `bundle update`
27
18
 
28
19
  2. Install the gem using Bundler:
29
20
  ```ruby
data/Rakefile CHANGED
@@ -2,14 +2,20 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
- require 'spree/testing_support/common_rake'
5
+ require 'spree/testing_support/extension_rake'
6
6
 
7
7
  RSpec::Core::RakeTask.new
8
8
 
9
- task default: :spec
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
10
16
 
11
17
  desc 'Generates a dummy app for testing'
12
18
  task :test_app do
13
19
  ENV['LIB_NAME'] = 'spree/auth'
14
- Rake::Task['common:test_app'].invoke("Spree::User")
20
+ Rake::Task['extension:test_app'].invoke
15
21
  end
@@ -0,0 +1,20 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ class AccountConfirmationsController < ::Spree::Api::V2::BaseController
6
+
7
+ def show
8
+ user = Spree.user_class.confirm_by_token(params[:id])
9
+
10
+ if user.errors.empty?
11
+ render json: { data: { state: user.respond_to?(:state) ? user.state : '' } }, status: :ok
12
+ else
13
+ render json: { error: user.errors.full_messages.to_sentence }, status: :unprocessable_entity
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ class PasswordsController < ::Spree::Api::V2::BaseController
6
+ include Spree::Core::ControllerHelpers::Store
7
+
8
+ def create
9
+ user = Spree.user_class.find_by(email: params[:user][:email])
10
+
11
+ if user&.send_reset_password_instructions(current_store)
12
+ head :ok
13
+ else
14
+ head :not_found
15
+ end
16
+ end
17
+
18
+ def update
19
+ user = Spree.user_class.reset_password_by_token(
20
+ password: params[:user][:password],
21
+ password_confirmation: params[:user][:password_confirmation],
22
+ reset_password_token: params[:id]
23
+ )
24
+
25
+ if user.errors.empty?
26
+ head :ok
27
+ else
28
+ render json: { error: user.errors.full_messages.to_sentence }, status: :unprocessable_entity
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -6,8 +6,52 @@ class Spree::UserConfirmationsController < Devise::ConfirmationsController
6
6
  include Spree::Core::ControllerHelpers::Order
7
7
  include Spree::Core::ControllerHelpers::Store
8
8
 
9
+ if defined?(Spree::Core::ControllerHelpers::Currency)
10
+ include Spree::Core::ControllerHelpers::Currency
11
+ end
12
+
13
+ if defined?(Spree::Core::ControllerHelpers::Locale)
14
+ include Spree::Core::ControllerHelpers::Locale
15
+ end
16
+
9
17
  before_action :set_current_order
10
-
18
+
19
+ if Spree.version.to_f >= 4.2
20
+ # POST /resource/confirmation
21
+ def create
22
+ self.resource = resource_class.send_confirmation_instructions(resource_params, current_store)
23
+ yield resource if block_given?
24
+
25
+ if successfully_sent?(resource)
26
+ respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
27
+ else
28
+ respond_with(resource)
29
+ end
30
+ end
31
+ end
32
+
33
+ # GET /resource/confirmation?confirmation_token=abcdef
34
+ def show
35
+ self.resource = resource_class.confirm_by_token(params[:confirmation_token])
36
+ yield resource if block_given?
37
+
38
+ if resource.errors.empty?
39
+ set_flash_message!(:notice, :confirmed)
40
+ respond_with_navigational(resource) do
41
+ redirect_to after_confirmation_path_for(resource_name, resource)
42
+ end
43
+ elsif resource.confirmed?
44
+ set_flash_message(:error, :already_confirmed)
45
+ respond_with_navigational(resource) do
46
+ redirect_to after_confirmation_path_for(resource_name, resource)
47
+ end
48
+ else
49
+ respond_with_navigational(resource.errors, status: :unprocessable_entity) do
50
+ render :new
51
+ end
52
+ end
53
+ end
54
+
11
55
  protected
12
56
 
13
57
  def after_confirmation_path_for(resource_name, resource)
@@ -6,6 +6,14 @@ class Spree::UserPasswordsController < Devise::PasswordsController
6
6
  include Spree::Core::ControllerHelpers::Order
7
7
  include Spree::Core::ControllerHelpers::Store
8
8
 
9
+ if defined?(Spree::Core::ControllerHelpers::Currency)
10
+ include Spree::Core::ControllerHelpers::Currency
11
+ end
12
+
13
+ if defined?(Spree::Core::ControllerHelpers::Locale)
14
+ include Spree::Core::ControllerHelpers::Locale
15
+ end
16
+
9
17
  if defined?(SpreeI18n::ControllerLocaleHelper)
10
18
  include SpreeI18n::ControllerLocaleHelper
11
19
  end
@@ -20,7 +28,7 @@ class Spree::UserPasswordsController < Devise::PasswordsController
20
28
  # respond_with resource, :location => spree.login_path
21
29
  #
22
30
  def create
23
- self.resource = resource_class.send_reset_password_instructions(params[resource_name])
31
+ self.resource = resource_class.send_reset_password_instructions(params[resource_name], current_store)
24
32
 
25
33
  if resource.errors.empty?
26
34
  set_flash_message(:notice, :send_instructions) if is_navigational_format?
@@ -53,4 +61,10 @@ class Spree::UserPasswordsController < Devise::PasswordsController
53
61
  def new_session_path(resource_name)
54
62
  spree.send("new_#{resource_name}_session_path")
55
63
  end
64
+
65
+ private
66
+
67
+ def accurate_title
68
+ Spree.t(:reset_password)
69
+ end
56
70
  end
@@ -6,6 +6,14 @@ class Spree::UserRegistrationsController < Devise::RegistrationsController
6
6
  include Spree::Core::ControllerHelpers::Order
7
7
  include Spree::Core::ControllerHelpers::Store
8
8
 
9
+ if defined?(Spree::Core::ControllerHelpers::Currency)
10
+ include Spree::Core::ControllerHelpers::Currency
11
+ end
12
+
13
+ if defined?(Spree::Core::ControllerHelpers::Locale)
14
+ include Spree::Core::ControllerHelpers::Locale
15
+ end
16
+
9
17
  if defined?(SpreeI18n::ControllerLocaleHelper)
10
18
  include SpreeI18n::ControllerLocaleHelper
11
19
  end
@@ -23,6 +31,7 @@ class Spree::UserRegistrationsController < Devise::RegistrationsController
23
31
  # POST /resource/sign_up
24
32
  def create
25
33
  @user = build_resource(spree_user_params)
34
+ resource.skip_confirmation_notification! if Spree::Auth::Config[:confirmable]
26
35
  resource_saved = resource.save
27
36
  yield resource if block_given?
28
37
  if resource_saved
@@ -30,10 +39,12 @@ class Spree::UserRegistrationsController < Devise::RegistrationsController
30
39
  set_flash_message :notice, :signed_up
31
40
  sign_up(resource_name, resource)
32
41
  session[:spree_user_signup] = true
33
- respond_with resource, location: after_sign_up_path_for(resource)
42
+ resource.send_confirmation_instructions(current_store) if Spree::Auth::Config[:confirmable]
43
+ redirect_to_checkout_or_account_path(resource)
34
44
  else
35
45
  set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}"
36
46
  expire_data_after_sign_in!
47
+ resource.send_confirmation_instructions(current_store) if Spree::Auth::Config[:confirmable]
37
48
  respond_with resource, location: after_inactive_sign_up_path_for(resource)
38
49
  end
39
50
  else
@@ -80,8 +91,19 @@ class Spree::UserRegistrationsController < Devise::RegistrationsController
80
91
  after_sign_in_redirect(resource) if is_navigational_format?
81
92
  end
82
93
 
94
+ def after_inactive_sign_up_path_for(resource)
95
+ scope = Devise::Mapping.find_scope!(resource)
96
+ router_name = Devise.mappings[scope].router_name
97
+ context = router_name ? send(router_name) : self
98
+ context.respond_to?(:login_path) ? context.login_path : "/login"
99
+ end
100
+
83
101
  private
84
102
 
103
+ def accurate_title
104
+ Spree.t(:sign_up)
105
+ end
106
+
85
107
  def spree_user_params
86
108
  params.require(:spree_user).permit(Spree::PermittedAttributes.user_attributes)
87
109
  end
@@ -89,4 +111,14 @@ class Spree::UserRegistrationsController < Devise::RegistrationsController
89
111
  def after_sign_in_redirect(resource_or_scope)
90
112
  stored_location_for(resource_or_scope) || account_path
91
113
  end
114
+
115
+ def redirect_to_checkout_or_account_path(resource)
116
+ resource_path = after_sign_up_path_for(resource)
117
+
118
+ if resource_path == spree.checkout_state_path(:address)
119
+ respond_with resource, location: spree.checkout_state_path(:address)
120
+ else
121
+ respond_with resource, location: spree.account_path
122
+ end
123
+ end
92
124
  end
@@ -6,6 +6,14 @@ class Spree::UserSessionsController < Devise::SessionsController
6
6
  include Spree::Core::ControllerHelpers::Order
7
7
  include Spree::Core::ControllerHelpers::Store
8
8
 
9
+ if defined?(Spree::Core::ControllerHelpers::Currency)
10
+ include Spree::Core::ControllerHelpers::Currency
11
+ end
12
+
13
+ if defined?(Spree::Core::ControllerHelpers::Locale)
14
+ include Spree::Core::ControllerHelpers::Locale
15
+ end
16
+
9
17
  if defined?(SpreeI18n::ControllerLocaleHelper)
10
18
  include SpreeI18n::ControllerLocaleHelper
11
19
  end
@@ -1,16 +1,23 @@
1
1
  module Spree
2
2
  class UserMailer < BaseMailer
3
3
  def reset_password_instructions(user, token, *_args)
4
- @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: Spree::Store.current.url)
4
+ current_store_id = _args.inject(:merge)[:current_store_id]
5
+ @current_store = Spree::Store.find(current_store_id) || Spree::Store.current
6
+ @locale = @current_store.has_attribute?(:default_locale) ? @current_store.default_locale : I18n.default_locale
7
+ I18n.locale = @locale if @locale.present?
8
+ @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @current_store.url)
9
+ @user = user
5
10
 
6
- mail to: user.email, from: from_address, subject: Spree::Store.current.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
11
+ mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions]), store_url: @current_store.url
7
12
  end
8
13
 
9
14
  def confirmation_instructions(user, token, _opts = {})
10
- @confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: Spree::Store.current.url)
15
+ current_store_id = _opts[:current_store_id]
16
+ @current_store = Spree::Store.find(current_store_id) || Spree::Store.current
17
+ @confirmation_url = spree_user_confirmation_url(confirmation_token: token, host: Spree::Store.current.url)
11
18
  @email = user.email
12
19
 
13
- mail to: user.email, from: from_address, subject: Spree::Store.current.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions])
20
+ mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions]), store_url: @current_store.url
14
21
  end
15
22
  end
16
23
  end
@@ -27,6 +27,48 @@ module Spree
27
27
  has_spree_role?('admin')
28
28
  end
29
29
 
30
+ def self.send_confirmation_instructions(attributes = {}, current_store)
31
+ confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable
32
+ unless confirmable.try(:persisted?)
33
+ confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
34
+ end
35
+ confirmable.resend_confirmation_instructions(current_store) if confirmable.persisted?
36
+ confirmable
37
+ end
38
+
39
+ def resend_confirmation_instructions(current_store)
40
+ pending_any_confirmation do
41
+ send_confirmation_instructions(current_store)
42
+ end
43
+ end
44
+
45
+ def send_confirmation_instructions(current_store)
46
+ unless @raw_confirmation_token
47
+ generate_confirmation_token!
48
+ end
49
+
50
+ opts = pending_reconfirmation? ? { to: unconfirmed_email } : {}
51
+ opts[:current_store_id] = current_store.id
52
+ send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
53
+ end
54
+
55
+ def self.send_reset_password_instructions(attributes={}, current_store)
56
+ recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
57
+ recoverable.send_reset_password_instructions(current_store) if recoverable.persisted?
58
+ recoverable
59
+ end
60
+
61
+ def send_reset_password_instructions(current_store)
62
+ token = set_reset_password_token
63
+ send_reset_password_instructions_notification(token, current_store.id)
64
+
65
+ token
66
+ end
67
+
68
+ def send_reset_password_instructions_notification(token, current_store_id)
69
+ send_devise_notification(:reset_password_instructions, token, { current_store_id: current_store_id })
70
+ end
71
+
30
72
  protected
31
73
 
32
74
  def password_required?