solidus_auth_devise 2.5.9 → 2.6.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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/.git-blame-ignore-revs +2 -0
  3. data/.github/workflows/test.yml +22 -0
  4. data/.rubocop.yml +0 -8
  5. data/Gemfile +36 -19
  6. data/README.md +13 -3
  7. data/Rakefile +5 -5
  8. data/app/models/spree/user.rb +4 -13
  9. data/app/patches/controllers/solidus_auth_devise/application_controller_patch.rb +29 -0
  10. data/bin/rspec +16 -0
  11. data/config/initializers/devise.rb +7 -5
  12. data/config/routes.rb +31 -31
  13. data/db/default/users.rb +18 -6
  14. data/db/migrate/20101026184949_create_users.rb +19 -19
  15. data/db/migrate/20101026184950_rename_columns_for_devise.rb +1 -3
  16. data/db/migrate/20101214150824_convert_user_remember_field.rb +1 -1
  17. data/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb +1 -1
  18. data/db/migrate/20120605211305_make_users_email_index_unique.rb +1 -1
  19. data/db/migrate/20140904000425_add_deleted_at_to_users.rb +1 -1
  20. data/db/migrate/20141002154641_add_confirmable_to_users.rb +1 -1
  21. data/db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb +3 -3
  22. data/db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb +1 -1
  23. data/db/migrate/20260422183113_add_timezone_to_spree_users.rb +6 -0
  24. data/db/seeds.rb +1 -1
  25. data/lib/controllers/backend/spree/admin/user_passwords_controller.rb +6 -5
  26. data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +7 -7
  27. data/lib/controllers/frontend/spree/user_confirmations_controller.rb +1 -1
  28. data/lib/controllers/frontend/spree/user_passwords_controller.rb +3 -3
  29. data/lib/controllers/frontend/spree/user_registrations_controller.rb +2 -2
  30. data/lib/controllers/frontend/spree/user_sessions_controller.rb +6 -6
  31. data/lib/controllers/frontend/spree/users_controller.rb +6 -5
  32. data/lib/generators/solidus/auth/install/install_generator.rb +21 -13
  33. data/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb.erb +4 -0
  34. data/lib/generators/solidus_auth_devise/install/install_generator.rb +2 -2
  35. data/lib/{decorators/backend/controllers/spree/admin/base_controller_decorator.rb → patches/backend/controllers/solidus_auth_devise/admin/base_controller_patch.rb} +2 -2
  36. data/lib/patches/backend/controllers/solidus_auth_devise/admin/orders/customer_details_controller_patch.rb +28 -0
  37. data/lib/{decorators/frontend/controllers/spree/checkout_controller_decorator.rb → patches/frontend/controllers/solidus_auth_devise/checkout_controller_patch.rb} +9 -9
  38. data/lib/solidus_auth_devise/configuration.rb +1 -1
  39. data/lib/solidus_auth_devise/engine.rb +1 -1
  40. data/lib/solidus_auth_devise/version.rb +1 -1
  41. data/lib/solidus_auth_devise.rb +9 -11
  42. data/lib/spree/auth/engine.rb +10 -15
  43. data/lib/spree/auth/version.rb +1 -1
  44. data/lib/tasks/auth.rake +1 -1
  45. data/lib/views/frontend/spree/checkout/registration.html.erb +1 -1
  46. data/solidus_auth_devise.gemspec +20 -21
  47. metadata +20 -96
  48. data/.circleci/config.yml +0 -73
  49. data/.rubocop_todo.yml +0 -397
  50. data/lib/decorators/backend/controllers/spree/admin/orders/customer_details_controller_decorator.rb +0 -22
  51. data/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb +0 -3
  52. data/lib/spree/authentication_helpers.rb +0 -27
  53. data/spec/controllers/spree/admin/base_controller_spec.rb +0 -53
  54. data/spec/controllers/spree/admin/user_passwords_controller_spec.rb +0 -14
  55. data/spec/controllers/spree/admin/user_sessions_controller_spec.rb +0 -20
  56. data/spec/controllers/spree/base_controller_spec.rb +0 -53
  57. data/spec/controllers/spree/checkout_controller_spec.rb +0 -192
  58. data/spec/controllers/spree/products_controller_spec.rb +0 -24
  59. data/spec/controllers/spree/user_passwords_controller_spec.rb +0 -45
  60. data/spec/controllers/spree/user_registrations_controller_spec.rb +0 -97
  61. data/spec/controllers/spree/user_sessions_controller_spec.rb +0 -125
  62. data/spec/controllers/spree/users_controller_spec.rb +0 -79
  63. data/spec/factories/confirmed_user.rb +0 -9
  64. data/spec/features/account_spec.rb +0 -59
  65. data/spec/features/admin/password_reset_spec.rb +0 -80
  66. data/spec/features/admin/products_spec.rb +0 -10
  67. data/spec/features/admin/sign_in_spec.rb +0 -45
  68. data/spec/features/admin/sign_out_spec.rb +0 -42
  69. data/spec/features/admin_permissions_spec.rb +0 -47
  70. data/spec/features/change_email_spec.rb +0 -27
  71. data/spec/features/checkout_spec.rb +0 -158
  72. data/spec/features/confirmation_spec.rb +0 -28
  73. data/spec/features/order_spec.rb +0 -59
  74. data/spec/features/password_reset_spec.rb +0 -37
  75. data/spec/features/sign_in_spec.rb +0 -53
  76. data/spec/features/sign_out_spec.rb +0 -26
  77. data/spec/features/sign_up_spec.rb +0 -31
  78. data/spec/mailers/user_mailer_spec.rb +0 -47
  79. data/spec/models/order_spec.rb +0 -27
  80. data/spec/models/user_spec.rb +0 -103
  81. data/spec/requests/spree/frontend/user_update_spec.rb +0 -42
  82. data/spec/spec_helper.rb +0 -33
  83. data/spec/support/ability.rb +0 -17
  84. data/spec/support/authentication_helpers.rb +0 -16
  85. data/spec/support/confirm_helpers.rb +0 -27
  86. data/spec/support/email.rb +0 -7
  87. data/spec/support/features/fill_addresses_fields.rb +0 -29
  88. data/spec/support/preferences.rb +0 -13
  89. data/spec/support/spree.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '098ee5c680f5383b31766bff2da29911149036a3972e740cc59731c6d05c5f56'
4
- data.tar.gz: 7f6c81439ad91719dc0fe4cee7ba2995370f02d87e1f33d7169472241f50f2c7
3
+ metadata.gz: 9e0d47cfd1b48b91343c2ba368dc685cf3e8c571a79d7d38c5b49538cf00d16b
4
+ data.tar.gz: ad94efe038f6e2fcc044e7e7943b9b62dc2bd43cb36eb3721d2a81708e596c52
5
5
  SHA512:
6
- metadata.gz: 6044f99dbef2b8c35bd664d4a9566a7f7dab506678bed597831f5b818c969647ef72bf00e89395875c64a45f2701ac14c3e7c42d583e292e19ea93595c790bc4
7
- data.tar.gz: 4a44b87bc260b095892bdc0e4477885a7aff5e119c2fac2d3e72c3373db49370b5c05da4d9b824f4d5068df62cbfeaae8d5ff21d27be7550b78f275613785743
6
+ metadata.gz: 3e425503e6ee10e0068856686a84fc60ec0ef38280d24e4882364801ff09c7e280604574ab1d3f4417e0ac06c09ae47ff519a4f64ffe8a56fcce806e285abf73
7
+ data.tar.gz: 4124d2869c44f9dd66f9422d4dd31b1d0e68ae663e4f46ebecfc510e106209966d273d66c8d4978d0a2d949a040bffe5d0a1306cb745b079301f7d914130922a
@@ -0,0 +1,2 @@
1
+ # Ignore standardrb --fix commit
2
+ eaba0e4370a03d10a6064466a9197c330bb92c64
@@ -0,0 +1,22 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ schedule:
9
+ - cron: "0 0 * * 4" # every Thursday
10
+
11
+ concurrency:
12
+ group: test-${{ github.ref_name }}
13
+ cancel-in-progress: ${{ github.ref_name != 'main' }}
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ Test:
20
+ uses: solidusio/test-solidus-extension/.github/workflows/test.yml@v1
21
+ with:
22
+ ruby_versions: "['3.4', '4.0']"
data/.rubocop.yml CHANGED
@@ -1,10 +1,2 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
1
  require:
4
2
  - solidus_dev_support/rubocop
5
-
6
- AllCops:
7
- NewCops: disable
8
-
9
- Gemspec/RequiredRubyVersion:
10
- Enabled: false
data/Gemfile CHANGED
@@ -1,41 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
- branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7
- gem 'solidus', github: 'solidusio/solidus', branch: branch
8
- gem 'solidus_backend', github: 'solidusio/solidus', branch: branch
6
+ branch = ENV.fetch("SOLIDUS_BRANCH", "main")
7
+ gem "solidus", github: "solidusio/solidus", branch: branch
8
+ gem "solidus_backend", github: "solidusio/solidus", branch: branch
9
+
10
+ rails_requirement_string = ENV.fetch("RAILS_VERSION", "7.0")
11
+ gem "rails", "~> #{rails_requirement_string}"
12
+
13
+ # json 3 is incompatible with Rails < 8.1.
14
+ gem "json", "< 3", require: false
9
15
 
10
16
  # The solidus_frontend gem has been pulled out since v3.2
11
- if branch >= 'v3.2'
12
- gem 'solidus_frontend'
13
- elsif branch == 'main'
14
- gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
17
+ if branch >= "v3.2"
18
+ gem "solidus_frontend"
19
+ elsif branch == "main"
20
+ gem "solidus_frontend", github: "solidusio/solidus_frontend"
15
21
  else
16
- gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
22
+ gem "solidus_frontend", github: "solidusio/solidus", branch: branch
17
23
  end
18
24
 
19
- case ENV.fetch('DB', nil)
20
- when 'mysql'
21
- gem 'mysql2'
22
- when 'postgresql'
23
- gem 'pg'
25
+ case ENV.fetch("DB", nil)
26
+ when "mysql"
27
+ gem "mysql2"
28
+ when "postgresql"
29
+ gem "pg"
24
30
  else
25
- gem 'sqlite3'
31
+ rails_version = Gem::Requirement.new(rails_requirement_string).requirements[0][1]
32
+ sqlite_version = (rails_version < Gem::Version.new(7.2)) ? "~> 1.4" : "~> 2.0"
33
+
34
+ gem "sqlite3", sqlite_version
26
35
  end
27
36
 
28
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
37
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3")
29
38
  # While we still support Ruby < 3 we need to workaround a limitation in
30
39
  # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
31
40
  # resolve gems based on the required ruby version.
32
- gem 'async', '< 3', require: false
41
+ gem "async", "< 3", require: false
33
42
  end
34
43
 
35
44
  # 'net/smtp' is required by 'mail', see:
36
45
  # - https://github.com/ruby/net-protocol/issues/10
37
46
  # - https://stackoverflow.com/a/72474475
38
- gem 'net-smtp', require: false
47
+ gem "net-smtp", require: false
39
48
 
40
49
  gemspec
41
50
 
@@ -44,4 +53,12 @@ gemspec
44
53
  #
45
54
  # We use `send` instead of calling `eval_gemfile` to work around an issue with
46
55
  # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
47
- send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
56
+ send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local"
57
+
58
+ # Pin state_machines
59
+ gem "state_machines", "= 0.6.0"
60
+
61
+ if RUBY_VERSION >= "4.0"
62
+ # Necessary for github_changelog_generator
63
+ gem "benchmark", "~> 0.5.0"
64
+ end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Solidus Auth Devise
2
2
 
3
- [![CircleCI](https://circleci.com/gh/solidusio/solidus_auth_devise.svg?style=shield)](https://circleci.com/gh/solidusio/solidus_auth_devise)
3
+ [![Test](https://github.com/solidusio/solidus_auth_devise/actions/workflows/test.yml/badge.svg)](https://github.com/solidusio/solidus_auth_devise/actions/workflows/test.yml)
4
4
  [![codecov](https://codecov.io/gh/solidusio/solidus_auth_devise/branch/main/graph/badge.svg)](https://codecov.io/gh/solidusio/solidus_auth_devise)
5
5
 
6
6
  Provides authentication services for Solidus, using the Devise gem.
@@ -27,7 +27,17 @@ bundle exec rake db:seed
27
27
 
28
28
  #### Default Username/Password
29
29
 
30
- As part of running the above installation steps, you will be asked to set an admin email/password combination. The default values are `admin@example.com` and `test123`, respectively.
30
+ The seed creates an admin user when no admin exists yet. Set the `ADMIN_EMAIL`
31
+ and `ADMIN_PASSWORD` environment variables to choose its credentials:
32
+
33
+ ```shell
34
+ ADMIN_EMAIL=you@example.com ADMIN_PASSWORD=... bundle exec rake spree_auth:admin:create
35
+ ```
36
+
37
+ In the `development` and `test` environments, the credentials default to
38
+ `admin@example.com` and `test123` when the variables are not set. In every other
39
+ environment (`production`, `staging`, etc.) both variables are required, and the
40
+ seed aborts with an error if either is missing.
31
41
 
32
42
  #### Confirmable
33
43
 
@@ -36,7 +46,7 @@ To enable Devise's Confirmable module, which will send the user an email with a
36
46
  * Add this line to an initializer in your Rails project (typically `config/initializers/spree.rb`):
37
47
 
38
48
  ```ruby
39
- Spree::Auth::Config[:confirmable] = true
49
+ Spree::Auth::Config.confirmable = true
40
50
  ```
41
51
 
42
52
  * Add a Devise initializer to your Rails project (typically `config/initializers/devise.rb`):
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Don't build a dummy app with solidus_bolt enabled
4
- ENV['SKIP_SOLIDUS_BOLT'] = 'true'
4
+ ENV["SKIP_SOLIDUS_BOLT"] = "true"
5
5
 
6
- require 'bundler/gem_tasks'
6
+ require "bundler/gem_tasks"
7
7
 
8
- require 'solidus_dev_support/rake_tasks'
9
- SolidusDevSupport::RakeTasks.install
8
+ require "solidus_dev_support/rake_tasks"
9
+ SolidusDevSupport::RakeTasks.install(user_class: "Spree::User")
10
10
 
11
- task default: 'extension:specs'
11
+ task default: "extension:specs"
@@ -3,20 +3,11 @@
3
3
  module Spree
4
4
  class User < Spree::Base
5
5
  include UserMethods
6
+ include Spree::SoftDeletable
6
7
 
7
8
  devise :database_authenticatable, :registerable, :recoverable,
8
- :rememberable, :trackable, :validatable, :encryptable
9
- devise :confirmable if Spree::Auth::Config[:confirmable]
10
-
11
- if defined?(Spree::SoftDeletable)
12
- include Spree::SoftDeletable
13
- else
14
- acts_as_paranoid
15
- include Spree::ParanoiaDeprecations
16
-
17
- include Discard::Model
18
- self.discard_column = :deleted_at
19
- end
9
+ :rememberable, :trackable, :validatable, :encryptable
10
+ devise :confirmable if Spree::Auth::Config.confirmable
20
11
 
21
12
  after_destroy :scramble_email_and_password
22
13
  after_discard :scramble_email_and_password
@@ -35,7 +26,7 @@ module Spree
35
26
  end
36
27
 
37
28
  def admin?
38
- has_spree_role?('admin')
29
+ has_spree_role?("admin")
39
30
  end
40
31
 
41
32
  def confirmed?
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusAuthDevise
4
+ module ApplicationControllerPatch
5
+ def self.prepended(base)
6
+ return unless base.respond_to?(:helper_method)
7
+
8
+ base.send(:helper_method, :spree_current_user)
9
+
10
+ return unless SolidusSupport.frontend_available?
11
+
12
+ base.send(:helper_method, :spree_login_path)
13
+ base.send(:helper_method, :spree_signup_path)
14
+ base.send(:helper_method, :spree_logout_path)
15
+ end
16
+
17
+ def spree_current_user
18
+ current_spree_user
19
+ end
20
+
21
+ if SolidusSupport.frontend_available?
22
+ delegate :login_path, :signup_path, :logout_path,
23
+ to: :spree,
24
+ prefix: :spree
25
+ end
26
+
27
+ ApplicationController.prepend self
28
+ end
29
+ end
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
@@ -5,16 +5,16 @@
5
5
  Devise.setup do |config|
6
6
  # ==> Mailer Configuration
7
7
  # Configure the e-mail address which will be shown in DeviseMailer.
8
- config.mailer_sender = 'please-change-me@config-initializers-devise.com'
8
+ config.mailer_sender = "please-change-me@config-initializers-devise.com"
9
9
 
10
10
  # Configure the class responsible to send e-mails.
11
- config.mailer = 'Spree::UserMailer'
11
+ config.mailer = "Spree::UserMailer"
12
12
 
13
13
  # ==> ORM configuration
14
14
  # Load and configure the ORM. Supports :active_record (default) and
15
15
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
16
16
  # available as additional gems.
17
- require 'devise/orm/active_record'
17
+ require "devise/orm/active_record"
18
18
 
19
19
  # ==> Configuration for any authentication mechanism
20
20
  # Configure which keys are used when authenticating an user. By default is
@@ -34,13 +34,13 @@ Devise.setup do |config|
34
34
  # config.http_authenticatable_on_xhr = false
35
35
 
36
36
  # The realm used in Http Basic Authentication
37
- config.http_authentication_realm = 'Spree Application'
37
+ config.http_authentication_realm = "Spree Application"
38
38
 
39
39
  # ==> Configuration for :database_authenticatable
40
40
  # For bcrypt, this is the cost for hashing the password and defaults to 10. If
41
41
  # using other encryptors, it sets how many times you want the password re-encrypted.
42
42
  config.stretches = 20
43
- config.encryptor = 'authlogic_sha512'
43
+ config.encryptor = "authlogic_sha512"
44
44
 
45
45
  # Setup a pepper to generate the encrypted password.
46
46
  config.pepper = if Rails.configuration.respond_to?(:secret_token) && Rails.configuration.secret_token.present?
@@ -143,4 +143,6 @@ Devise.setup do |config|
143
143
  config.reset_password_within = 6.hours
144
144
 
145
145
  config.case_insensitive_keys = [:email]
146
+
147
+ config.reload_routes = false
146
148
  end
data/config/routes.rb CHANGED
@@ -3,15 +3,15 @@
3
3
  Spree::Core::Engine.routes.draw do
4
4
  if SolidusSupport.frontend_available? && Spree::Auth::Config.draw_frontend_routes
5
5
  devise_for(:spree_user, {
6
- class_name: 'Spree::User',
6
+ class_name: "Spree::User",
7
7
  controllers: {
8
- sessions: 'spree/user_sessions',
9
- registrations: 'spree/user_registrations',
10
- passwords: 'spree/user_passwords',
11
- confirmations: 'spree/user_confirmations'
8
+ sessions: "spree/user_sessions",
9
+ registrations: "spree/user_registrations",
10
+ passwords: "spree/user_passwords",
11
+ confirmations: "spree/user_confirmations"
12
12
  },
13
13
  skip: [:unlocks, :omniauth_callbacks],
14
- path_names: { sign_out: 'logout' },
14
+ path_names: {sign_out: "logout"},
15
15
  path_prefix: :user,
16
16
  router_name: :spree
17
17
  })
@@ -19,48 +19,48 @@ Spree::Core::Engine.routes.draw do
19
19
  resources :users, only: [:edit, :update]
20
20
 
21
21
  devise_scope :spree_user do
22
- get '/login', to: 'user_sessions#new', as: :login
23
- post '/login', to: 'user_sessions#create', as: :create_new_session
24
- match '/logout', to: 'user_sessions#destroy', as: :logout, via: Devise.sign_out_via
25
- get '/signup', to: 'user_registrations#new', as: :signup
26
- post '/signup', to: 'user_registrations#create', as: :registration
27
- get '/password/recover', to: 'user_passwords#new', as: :recover_password
28
- post '/password/recover', to: 'user_passwords#create', as: :reset_password
29
- get '/password/change', to: 'user_passwords#edit', as: :edit_password
30
- put '/password/change', to: 'user_passwords#update', as: :update_password
31
- get '/confirm', to: 'user_confirmations#show', as: :confirmation if Spree::Auth::Config[:confirmable]
22
+ get "/login", to: "user_sessions#new", as: :login
23
+ post "/login", to: "user_sessions#create", as: :create_new_session
24
+ match "/logout", to: "user_sessions#destroy", as: :logout, via: Devise.sign_out_via
25
+ get "/signup", to: "user_registrations#new", as: :signup
26
+ post "/signup", to: "user_registrations#create", as: :registration
27
+ get "/password/recover", to: "user_passwords#new", as: :recover_password
28
+ post "/password/recover", to: "user_passwords#create", as: :reset_password
29
+ get "/password/change", to: "user_passwords#edit", as: :edit_password
30
+ put "/password/change", to: "user_passwords#update", as: :update_password
31
+ get "/confirm", to: "user_confirmations#show", as: :confirmation if Spree::Auth::Config.confirmable
32
32
  end
33
33
 
34
- get '/checkout/registration', to: 'checkout#registration', as: :checkout_registration
35
- put '/checkout/registration', to: 'checkout#update_registration', as: :update_checkout_registration
34
+ get "/checkout/registration", to: "checkout#registration", as: :checkout_registration
35
+ put "/checkout/registration", to: "checkout#update_registration", as: :update_checkout_registration
36
36
 
37
- resource :account, controller: 'users'
37
+ resource :account, controller: "users"
38
38
  end
39
39
 
40
40
  if SolidusSupport.backend_available? && Spree::Auth::Config.draw_backend_routes
41
41
  namespace :admin do
42
42
  devise_for(:spree_user, {
43
- class_name: 'Spree::User',
43
+ class_name: "Spree::User",
44
44
  singular: :spree_user,
45
45
  skip: :all,
46
- path_names: { sign_out: 'logout' },
46
+ path_names: {sign_out: "logout"},
47
47
  controllers: {
48
- sessions: 'spree/admin/user_sessions',
49
- passwords: 'spree/admin/user_passwords'
48
+ sessions: "spree/admin/user_sessions",
49
+ passwords: "spree/admin/user_passwords"
50
50
  },
51
51
  router_name: :spree
52
52
  })
53
53
 
54
54
  devise_scope :spree_user do
55
- get '/authorization_failure', to: 'user_sessions#authorization_failure', as: :unauthorized
56
- get '/login', to: 'user_sessions#new', as: :login
57
- post '/login', to: 'user_sessions#create', as: :create_new_session
58
- match '/logout', to: 'user_sessions#destroy', as: :logout, via: Devise.sign_out_via
55
+ get "/authorization_failure", to: "user_sessions#authorization_failure", as: :unauthorized
56
+ get "/login", to: "user_sessions#new", as: :login
57
+ post "/login", to: "user_sessions#create", as: :create_new_session
58
+ match "/logout", to: "user_sessions#destroy", as: :logout, via: Devise.sign_out_via
59
59
 
60
- get '/password/recover', to: 'user_passwords#new', as: :recover_password
61
- post '/password/recover', to: 'user_passwords#create', as: :reset_password
62
- get '/password/change', to: 'user_passwords#edit', as: :edit_password
63
- put '/password/change', to: 'user_passwords#update', as: :update_password
60
+ get "/password/recover", to: "user_passwords#new", as: :recover_password
61
+ post "/password/recover", to: "user_passwords#create", as: :reset_password
62
+ get "/password/change", to: "user_passwords#edit", as: :edit_password
63
+ put "/password/change", to: "user_passwords#update", as: :update_password
64
64
  end
65
65
  end
66
66
  end
data/db/default/users.rb CHANGED
@@ -1,18 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- admin_role = Spree::Role.find_or_create_by(name: 'admin')
3
+ admin_role = Spree::Role.find_or_create_by(name: "admin")
4
4
 
5
5
  if Spree::User.admin.any?
6
- puts 'No admin user created.'
6
+ puts "No admin user created."
7
7
  return
8
8
  end
9
9
 
10
- email = ENV['ADMIN_EMAIL'] || 'admin@example.com'
11
- password = ENV['ADMIN_PASSWORD'] || 'test123'
10
+ email = ENV["ADMIN_EMAIL"]
11
+ password = ENV["ADMIN_PASSWORD"]
12
+
13
+ if Rails.env.development? || Rails.env.test?
14
+ email ||= "admin@example.com"
15
+ password ||= "test123"
16
+ elsif email.blank? || password.blank?
17
+ abort <<~MSG
18
+ Refusing to create an admin user with default credentials in the #{Rails.env} environment.
19
+ Set ADMIN_EMAIL and ADMIN_PASSWORD and run the task again, for example:
20
+
21
+ ADMIN_EMAIL=you@example.com ADMIN_PASSWORD=... bin/rails spree_auth:admin:create
22
+ MSG
23
+ end
12
24
 
13
25
  puts "Creating admin user with:"
14
26
  puts " - email: #{email}"
15
- puts " - password: #{password}"
27
+ puts " - password: #{ENV["ADMIN_PASSWORD"] ? "(from ADMIN_PASSWORD)" : password}"
16
28
  puts "(please use the ADMIN_EMAIL and ADMIN_PASSWORD environment variables to control how the default admin user is created)"
17
29
 
18
30
  if Spree::User.find_by(email: email)
@@ -24,7 +36,7 @@ admin = Spree::User.new(
24
36
  password: password,
25
37
  password_confirmation: password,
26
38
  email: email,
27
- login: email,
39
+ login: email
28
40
  )
29
41
 
30
42
  if admin.save
@@ -1,30 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class CreateUsers < SolidusSupport::Migration[4.2]
3
+ class CreateUsers < ActiveRecord::Migration[4.2]
4
4
  def up
5
5
  unless table_exists?("spree_users")
6
6
  create_table "spree_users", force: true do |t|
7
- t.string "crypted_password", limit: 128
8
- t.string "salt", limit: 128
9
- t.string "email"
10
- t.string "remember_token"
11
- t.string "remember_token_expires_at"
12
- t.string "persistence_token"
13
- t.string "single_access_token"
14
- t.string "perishable_token"
15
- t.integer "login_count", default: 0, null: false
16
- t.integer "failed_login_count", default: 0, null: false
7
+ t.string "crypted_password", limit: 128
8
+ t.string "salt", limit: 128
9
+ t.string "email"
10
+ t.string "remember_token"
11
+ t.string "remember_token_expires_at"
12
+ t.string "persistence_token"
13
+ t.string "single_access_token"
14
+ t.string "perishable_token"
15
+ t.integer "login_count", default: 0, null: false
16
+ t.integer "failed_login_count", default: 0, null: false
17
17
  t.datetime "last_request_at"
18
18
  t.datetime "current_login_at"
19
19
  t.datetime "last_login_at"
20
- t.string "current_login_ip"
21
- t.string "last_login_ip"
22
- t.string "login"
23
- t.integer "ship_address_id"
24
- t.integer "bill_address_id"
25
- t.datetime "created_at", null: false
26
- t.datetime "updated_at", null: false
27
- t.string "openid_identifier"
20
+ t.string "current_login_ip"
21
+ t.string "last_login_ip"
22
+ t.string "login"
23
+ t.integer "ship_address_id"
24
+ t.integer "bill_address_id"
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
27
+ t.string "openid_identifier"
28
28
  end
29
29
  end
30
30
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class RenameColumnsForDevise < SolidusSupport::Migration[4.2]
3
+ class RenameColumnsForDevise < ActiveRecord::Migration[4.2]
4
4
  def up
5
5
  return if column_exists?(:spree_users, :password_salt)
6
6
 
@@ -14,14 +14,12 @@ class RenameColumnsForDevise < SolidusSupport::Migration[4.2]
14
14
  rename_column :spree_users, :last_login_at, :last_sign_in_at
15
15
  rename_column :spree_users, :current_login_ip, :current_sign_in_ip
16
16
  rename_column :spree_users, :last_login_ip, :last_sign_in_ip
17
- add_column :spree_users, :authentication_token, :string
18
17
  add_column :spree_users, :unlock_token, :string
19
18
  add_column :spree_users, :locked_at, :datetime
20
19
  remove_column :spree_users, :openid_identifier
21
20
  end
22
21
 
23
22
  def down
24
- remove_column :spree_users, :authentication_token
25
23
  remove_column :spree_users, :locked_at
26
24
  remove_column :spree_users, :unlock_token
27
25
  rename_column :spree_users, :last_sign_in_ip, :last_login_ip
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ConvertUserRememberField < SolidusSupport::Migration[4.2]
3
+ class ConvertUserRememberField < ActiveRecord::Migration[4.2]
4
4
  def up
5
5
  remove_column :spree_users, :remember_created_at
6
6
  add_column :spree_users, :remember_created_at, :datetime
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddResetPasswordSentAtToSpreeUsers < SolidusSupport::Migration[4.2]
3
+ class AddResetPasswordSentAtToSpreeUsers < ActiveRecord::Migration[4.2]
4
4
  def change
5
5
  Spree::User.reset_column_information
6
6
  unless Spree::User.column_names.include?("reset_password_sent_at")
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class MakeUsersEmailIndexUnique < SolidusSupport::Migration[4.2]
3
+ class MakeUsersEmailIndexUnique < ActiveRecord::Migration[4.2]
4
4
  def up
5
5
  add_index "spree_users", ["email"], name: "email_idx_unique", unique: true
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddDeletedAtToUsers < SolidusSupport::Migration[4.2]
3
+ class AddDeletedAtToUsers < ActiveRecord::Migration[4.2]
4
4
  def change
5
5
  add_column :spree_users, :deleted_at, :datetime
6
6
  add_index :spree_users, :deleted_at
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddConfirmableToUsers < SolidusSupport::Migration[4.2]
3
+ class AddConfirmableToUsers < ActiveRecord::Migration[4.2]
4
4
  def change
5
5
  add_column :spree_users, :confirmation_token, :string
6
6
  add_column :spree_users, :confirmed_at, :datetime
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddResetPasswordTokenIndexToSpreeUsers < SolidusSupport::Migration[4.2]
3
+ class AddResetPasswordTokenIndexToSpreeUsers < ActiveRecord::Migration[4.2]
4
4
  # We're not using the standard Rails index name because somebody could have
5
5
  #  already added that index to the table. By using a custom name we ensure
6
6
  # that the index can effectively be added and removed via migrations/rollbacks
@@ -8,7 +8,7 @@ class AddResetPasswordTokenIndexToSpreeUsers < SolidusSupport::Migration[4.2]
8
8
  # standard name + "_solidus_auth_devise"; the length is 61 chars which is
9
9
  # still OK for Sqlite, mySQL and Postgres.
10
10
  def custom_index_name
11
- 'index_spree_users_on_reset_password_token_solidus_auth_devise'
11
+ "index_spree_users_on_reset_password_token_solidus_auth_devise"
12
12
  end
13
13
 
14
14
  def default_index_exists?
@@ -21,7 +21,7 @@ class AddResetPasswordTokenIndexToSpreeUsers < SolidusSupport::Migration[4.2]
21
21
 
22
22
  def up
23
23
  Spree::User.reset_column_information
24
- if Spree::User.column_names.include?('reset_password_token') && !default_index_exists? && !custom_index_exists?
24
+ if Spree::User.column_names.include?("reset_password_token") && !default_index_exists? && !custom_index_exists?
25
25
  add_index :spree_users, :reset_password_token, unique: true, name: custom_index_name
26
26
  end
27
27
  end
@@ -1,4 +1,4 @@
1
- class AddUnconfirmedEmailToSpreeUsers < SolidusSupport::Migration[5.1]
1
+ class AddUnconfirmedEmailToSpreeUsers < ActiveRecord::Migration[5.1]
2
2
  def change
3
3
  unless column_exists?(:spree_users, :unconfirmed_email)
4
4
  add_column :spree_users, :unconfirmed_email, :string
@@ -0,0 +1,6 @@
1
+ class AddTimezoneToSpreeUsers < ActiveRecord::Migration[7.2]
2
+ def change
3
+ add_column :spree_users, :timezone, :string, if_not_exists: true,
4
+ comment: "User's timezone, e.g., 'Eastern Time (US & Canada)'"
5
+ end
6
+ end
data/db/seeds.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'default/users.rb'
3
+ require_relative "default/users"