solidus_auth_devise_devise_token_auth 2.1.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.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +20 -0
  5. data/CHANGELOG.md +173 -0
  6. data/Gemfile +36 -0
  7. data/LICENSE.md +26 -0
  8. data/README.md +98 -0
  9. data/Rakefile +21 -0
  10. data/app/mailers/spree/user_mailer.rb +15 -0
  11. data/app/models/spree/auth_configuration.rb +9 -0
  12. data/app/models/spree/user.rb +47 -0
  13. data/app/overrides/auth_admin_login_navigation_bar.rb +10 -0
  14. data/app/overrides/auth_shared_login_bar.rb +10 -0
  15. data/bin/rails +7 -0
  16. data/circle.yml +6 -0
  17. data/config/initializers/devise.rb +141 -0
  18. data/config/initializers/warden.rb +14 -0
  19. data/config/locales/de.yml +53 -0
  20. data/config/locales/en.yml +54 -0
  21. data/config/locales/es.yml +50 -0
  22. data/config/locales/fr.yml +50 -0
  23. data/config/locales/it.yml +76 -0
  24. data/config/locales/nl.yml +50 -0
  25. data/config/locales/pt-BR.yml +52 -0
  26. data/config/locales/tr.yml +50 -0
  27. data/config/locales/zh-CN.yml +54 -0
  28. data/config/routes.rb +71 -0
  29. data/db/default/users.rb +75 -0
  30. data/db/migrate/20101026184949_create_users.rb +29 -0
  31. data/db/migrate/20101026184950_rename_columns_for_devise.rb +41 -0
  32. data/db/migrate/20101214150824_convert_user_remember_field.rb +11 -0
  33. data/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb +8 -0
  34. data/db/migrate/20120605211305_make_users_email_index_unique.rb +9 -0
  35. data/db/migrate/20140904000425_add_deleted_at_to_users.rb +6 -0
  36. data/db/migrate/20141002154641_add_confirmable_to_users.rb +7 -0
  37. data/db/seeds.rb +1 -0
  38. data/lib/assets/javascripts/spree/backend/solidus_auth.js +1 -0
  39. data/lib/assets/javascripts/spree/frontend/solidus_auth.js +1 -0
  40. data/lib/assets/stylesheets/spree/backend/solidus_auth.css +3 -0
  41. data/lib/assets/stylesheets/spree/frontend/solidus_auth.css +3 -0
  42. data/lib/controllers/backend/spree/admin/admin_controller_decorator.rb +11 -0
  43. data/lib/controllers/backend/spree/admin/orders/customer_details_controller_decorator.rb +15 -0
  44. data/lib/controllers/backend/spree/admin/user_passwords_controller.rb +41 -0
  45. data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +43 -0
  46. data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +66 -0
  47. data/lib/controllers/frontend/spree/user_confirmations_controller.rb +14 -0
  48. data/lib/controllers/frontend/spree/user_passwords_controller.rb +50 -0
  49. data/lib/controllers/frontend/spree/user_registrations_controller.rb +40 -0
  50. data/lib/controllers/frontend/spree/user_sessions_controller.rb +64 -0
  51. data/lib/controllers/frontend/spree/users_controller.rb +57 -0
  52. data/lib/generators/solidus/auth/install/install_generator.rb +25 -0
  53. data/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb +1 -0
  54. data/lib/solidus/auth.rb +2 -0
  55. data/lib/solidus_auth_devise.rb +13 -0
  56. data/lib/spree/auth/devise.rb +14 -0
  57. data/lib/spree/auth/engine.rb +80 -0
  58. data/lib/spree/authentication_helpers.rb +33 -0
  59. data/lib/tasks/auth.rake +9 -0
  60. data/lib/views/backend/spree/admin/shared/_navigation_footer.html.erb +25 -0
  61. data/lib/views/backend/spree/admin/user_passwords/edit.html.erb +15 -0
  62. data/lib/views/backend/spree/admin/user_passwords/new.html.erb +17 -0
  63. data/lib/views/backend/spree/admin/user_sessions/authorization_failure.html.erb +4 -0
  64. data/lib/views/backend/spree/admin/user_sessions/new.html.erb +31 -0
  65. data/lib/views/backend/spree/layouts/admin/_login_nav.html.erb +13 -0
  66. data/lib/views/frontend/spree/checkout/registration.html.erb +22 -0
  67. data/lib/views/frontend/spree/shared/_flashes.html.erb +9 -0
  68. data/lib/views/frontend/spree/shared/_login.html.erb +18 -0
  69. data/lib/views/frontend/spree/shared/_login_bar.html.erb +2 -0
  70. data/lib/views/frontend/spree/shared/_login_bar_items.html.erb +6 -0
  71. data/lib/views/frontend/spree/shared/_user_form.html.erb +17 -0
  72. data/lib/views/frontend/spree/user_mailer/confirmation_instructions.text.erb +5 -0
  73. data/lib/views/frontend/spree/user_mailer/reset_password_instructions.text.erb +10 -0
  74. data/lib/views/frontend/spree/user_passwords/edit.html.erb +17 -0
  75. data/lib/views/frontend/spree/user_passwords/new.html.erb +17 -0
  76. data/lib/views/frontend/spree/user_registrations/new.html.erb +21 -0
  77. data/lib/views/frontend/spree/user_sessions/authorization_failure.html.erb +4 -0
  78. data/lib/views/frontend/spree/user_sessions/new.html.erb +13 -0
  79. data/lib/views/frontend/spree/users/edit.html.erb +14 -0
  80. data/lib/views/frontend/spree/users/show.html.erb +43 -0
  81. data/solidus_auth_devise.gemspec +41 -0
  82. data/spec/controllers/spree/checkout_controller_spec.rb +196 -0
  83. data/spec/controllers/spree/products_controller_spec.rb +27 -0
  84. data/spec/controllers/spree/user_passwords_controller_spec.rb +44 -0
  85. data/spec/controllers/spree/user_registrations_controller_spec.rb +96 -0
  86. data/spec/controllers/spree/user_sessions_controller_spec.rb +113 -0
  87. data/spec/controllers/spree/users_controller_spec.rb +38 -0
  88. data/spec/factories/confirmed_user.rb +7 -0
  89. data/spec/features/account_spec.rb +58 -0
  90. data/spec/features/admin/orders_spec.rb +30 -0
  91. data/spec/features/admin/password_reset_spec.rb +24 -0
  92. data/spec/features/admin/products_spec.rb +9 -0
  93. data/spec/features/admin/sign_in_spec.rb +44 -0
  94. data/spec/features/admin/sign_out_spec.rb +22 -0
  95. data/spec/features/admin_permissions_spec.rb +46 -0
  96. data/spec/features/change_email_spec.rb +26 -0
  97. data/spec/features/checkout_spec.rb +181 -0
  98. data/spec/features/confirmation_spec.rb +32 -0
  99. data/spec/features/order_spec.rb +62 -0
  100. data/spec/features/password_reset_spec.rb +24 -0
  101. data/spec/features/sign_in_spec.rb +52 -0
  102. data/spec/features/sign_out_spec.rb +25 -0
  103. data/spec/features/sign_up_spec.rb +30 -0
  104. data/spec/mailers/user_mailer_spec.rb +46 -0
  105. data/spec/models/order_spec.rb +26 -0
  106. data/spec/models/user_spec.rb +63 -0
  107. data/spec/spec_helper.rb +17 -0
  108. data/spec/support/ability.rb +15 -0
  109. data/spec/support/authentication_helpers.rb +14 -0
  110. data/spec/support/confirm_helpers.rb +13 -0
  111. data/spec/support/email.rb +5 -0
  112. data/spec/support/preferences.rb +5 -0
  113. data/spec/support/spree.rb +10 -0
  114. metadata +446 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e80fd8e5351b0d71fac358c522288c37f7829b578d407e556d5bf83523617c1c
4
+ data.tar.gz: 8cef39af520395863bbffe5dbd821a6c462477e79c472b70c07ad4ba1e980729
5
+ SHA512:
6
+ metadata.gz: 54ea0b9bdd421cb88bc59549ab7faf5c60f991b10ab03f992becb5ff282ea4cf654e1f1484d83d4a6fb20a2507383358e325d9b6c6d432aa162ce2d5479ab6c7
7
+ data.tar.gz: b5acef055e1b52999b5190a93e33ffcefb43a4456435eb928d5451bc7affbc39493e7882a1c361d37bbc8b92efbfe2ee07c74af9c75fe18820316ccc977d9412
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ spec/dummy
2
+ spec/examples.txt
3
+ .sass-cache
4
+ coverage
5
+ Gemfile.lock
6
+ *.swp
7
+ .rvmrc
8
+ .ruby-gemsets
9
+ .ruby-version
10
+ .bundle
11
+ pkg
12
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ env:
6
+ matrix:
7
+ - SOLIDUS_BRANCH=v2.2 DB=postgres
8
+ - SOLIDUS_BRANCH=v2.3 DB=postgres
9
+ - SOLIDUS_BRANCH=v2.4 DB=postgres
10
+ - SOLIDUS_BRANCH=v2.5 DB=postgres
11
+ - SOLIDUS_BRANCH=v2.6 DB=postgres
12
+ - SOLIDUS_BRANCH=v2.7 DB=postgres
13
+ - SOLIDUS_BRANCH=master DB=postgres
14
+ - SOLIDUS_BRANCH=v2.2 DB=mysql
15
+ - SOLIDUS_BRANCH=v2.3 DB=mysql
16
+ - SOLIDUS_BRANCH=v2.4 DB=mysql
17
+ - SOLIDUS_BRANCH=v2.5 DB=mysql
18
+ - SOLIDUS_BRANCH=v2.6 DB=mysql
19
+ - SOLIDUS_BRANCH=v2.7 DB=mysql
20
+ - SOLIDUS_BRANCH=master DB=mysql
data/CHANGELOG.md ADDED
@@ -0,0 +1,173 @@
1
+ ## Master (unreleased)
2
+
3
+ ## Solidus Auth Devise v2.1.0 (devise_token_auth version) (2018-10-25)
4
+
5
+ * Stop generating spree_api_key (because it's supposed to be replaced by devise_token_auth stuff)
6
+ * Remove spree_api_key functionality entirely
7
+
8
+ ## Solidus Auth Devise v2.1.0 (2018-01-22)
9
+
10
+ * Avoid requiring deface on Solidus 2.5+.
11
+
12
+ On older versions, you may need to add `gem 'deface'` to your gemfile.
13
+
14
+ * Remove reference to unused admin tables helper removed from Solidus 2.5
15
+
16
+ ## Solidus Auth Devise v2.0.0 (2017-09-20)
17
+
18
+ * Drop support for Solidus v1.0 and v1.1
19
+ * Use `match` for Devise logout route
20
+ * Remove references to dash
21
+ * Leverage `*_available?` helpers from `solidus-support`
22
+ * Use `spec_helper` from `solidus-support`
23
+ * Correct `set_current_order` callback for newer versions of Solidus
24
+
25
+ ## Solidus Auth Devise v1.6.4 (2017-07-24)
26
+
27
+ * Fix error trying to call helper_method in api-only applications
28
+ * Fix deprecated devise `bypass` option
29
+ * Pin development dependencies to minor versions
30
+ * Update outdated development dependencies
31
+ * Remove implicit dependency on highline
32
+
33
+ ## Solidus Auth Devise v1.6.3 (2017-05-09)
34
+
35
+ * Add missing translations for already_authenticated
36
+ * Do not require core email validator
37
+ * Remove dependency on `json`, `multi_json`
38
+ * Remove unnecessary sass/coffeescript requires
39
+ * Fix warnings on Rails 5, support Rails 5.1
40
+ * Change deface dependency from `~> 1.0.0` to `~> 1.0`
41
+
42
+ ## Solidus Auth Devise v1.6.2 (2016-11-18)
43
+
44
+ * Fix an issue where invalid addresses could be persisted after starting a
45
+ checkout as a guest and then returning to the cart page.
46
+
47
+ ## Solidus Auth Devise v1.6.1 (2016-08-24)
48
+
49
+ * Replace usages of `before_filter` with `before_action` (#73)
50
+
51
+ ## Solidus Auth Devise v1.6.0 (2016-08-23)
52
+
53
+ * Loading of routes can be disabled through config (#71)
54
+
55
+ * Support for Solidus 2.0 and Rails 5.0
56
+
57
+ * Remove load-time manipulation of the Devise secret key (#67)
58
+
59
+ ## Solidus Auth Devise v1.5.0 (2016-07-18)
60
+
61
+ * Add call to set_current_order on sign in. This replaces a before filter that
62
+ is being eliminated from Solidus controllers where set_current_order was
63
+ called excessively.
64
+
65
+ * Update backend views to only reference backend routes (#57)
66
+
67
+ * Devise dependency updates
68
+
69
+ The locked versions of Devise and Devise-Encryptable have been updated.
70
+ Devise, in particular, has been bumped to a new major version, which removes
71
+ support for the following:
72
+
73
+ - Rails 3.2. and 4.0
74
+ - Ruby 1.9 and 2.0
75
+
76
+ These losses are deemed acceptable, as Solidus' core itself does not
77
+ support any of these versions.
78
+
79
+ For more details on the changes, see the Devise changelog:
80
+ https://github.com/plataformatec/devise/blob/master/CHANGELOG.md
81
+
82
+ Similar changes in `devise-encryptable`, with details in the changelog:
83
+ https://github.com/plataformatec/devise-encryptable/blob/master/Changelog.md
84
+
85
+ * Addition of Chinese translations (#64)
86
+
87
+ ## Solidus Auth Devise v1.4.0 (2016-05-16)
88
+
89
+ * Update hash syntax for routes.rb
90
+ * Make route syntax consistent and modern
91
+ * Make devise_for routes conditional
92
+ * Test against solidus 1.3
93
+ * check_authorization first in CheckoutController
94
+ * Ensure current_order exists checking registration
95
+ * Add vendor to .gitignore
96
+ * Revert "ChcktController checks auth and registration first"
97
+ * ChcktController checks auth and registration first
98
+ * Remove obsolete regression test
99
+ * Remove superfluous call to associate_user
100
+ * Test and fix order association
101
+ * Re-add Solidus 1.0 compatability
102
+ * Improve readability of check_registration
103
+ * Force registration when guest checkout not allowed
104
+ * Improve check_registration spec for guest case
105
+ * Add pg and mysql2 to Gemfile
106
+ * Also test against v1.1 and v1.2
107
+ * Allow https instead of git in gemfile
108
+ * Ignore pkg directory
109
+ * Update .travis.yml
110
+ * Update README testing section
111
+ * Fix specs now that order's store is required
112
+ * Moved the encryptor setting for the User model into the devise config, allowing it to be easily overridden from the local devise config.
113
+
114
+ ## Solidus Auth Devise v1.3.0 (2016-01-12)
115
+
116
+ * Add capybara-screenshot
117
+ * Remove restriction on sass-rails and coffee-rails
118
+ * Remove the "Logged in as:" message
119
+ * Correct use of font-awesome
120
+ * Swap .inline-menu for specific hook
121
+ * Add new template override
122
+ * remove duplicate translation
123
+ * add missing translations for German locale
124
+
125
+ ## Solidus Auth Devise v1.2.3 (2015-11-30)
126
+
127
+ * Add an explicit require to deface
128
+ * Check if front/backend are available before decorating the controllers
129
+ * Rename spree@example.com to admin@example.com
130
+ * Skip the confirmation spec
131
+ * Permit editing email
132
+
133
+ ## Solidus Auth Devise v1.2.2 (2015-10-01)
134
+
135
+ * Automatically regenerate a user's spree_api_key upon password change.
136
+ * Inherit from Spree::Base
137
+ * Explicitely add deface to gemfile
138
+ * Remove some redundant includes
139
+ * Remove unneeded monkey patching
140
+ * Remove brittle spec
141
+ * Pass store to from_address helper
142
+ * Fix broken specs
143
+
144
+ ## Solidus Auth Devise v1.2.0 (2015-07-22)
145
+
146
+ * Use new extension point for access denied.
147
+ * Explicitly include UserMethods on Spree::User
148
+ * Bump rspec to 3.3 and remove minor patch restriction.
149
+ * We no longer redirect to admin/orders by default.
150
+ * Skip adding devise.rb if it already exists.
151
+ * Fix checkout spec
152
+ * Bump to RSpec 3.2
153
+ * Use non-deprecated `deliver_now` in mailer spec.
154
+ * Fix generator name.
155
+
156
+ ## Solidus Auth Devise v1.1.0 (2015-06-03)
157
+
158
+ * Updates for devise 3.5.1
159
+ * Bump devise to ~> 3.5.1
160
+ * Avoid stubbing to fix checkout spec
161
+ * Minor update to README.md
162
+ * Remove Spree::Core::ControllerHelpers::SSL
163
+ * Add circle.yml
164
+ * Use git+ssh for solidus gem
165
+ * Remove dead code.
166
+ * Refactor UserSessionsController and specs
167
+ * Remove @user from UserRegistrationsController
168
+ * Add specs for UserRegistrationsController
169
+ * Remove empty overrides in registrations controller
170
+
171
+ ## Solidus Auth Devise v1.0.0 (2015-05-26)
172
+
173
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,36 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
9
+ gem 'solidus_devise_token_auth', github: 'skycocker/solidus_devise_token_auth', branch: branch
10
+
11
+ group :test do
12
+ if branch == 'master' || branch >= "v2.0"
13
+ gem "rails-controller-testing"
14
+ else
15
+ gem "rails_test_params_backport"
16
+ end
17
+ if branch < "v2.5"
18
+ gem 'factory_bot', '4.10.0'
19
+ else
20
+ gem 'factory_bot', '> 4.10.0'
21
+ end
22
+ end
23
+
24
+ if ENV['DB'] == 'mysql'
25
+ gem 'mysql2', '~> 0.4.10'
26
+ else
27
+ gem 'pg', '~> 0.21'
28
+ end
29
+
30
+ group :development, :test do
31
+ gem "pry-rails"
32
+ end
33
+
34
+ gem 'deface', require: false
35
+
36
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2014, Spree Commerce, Inc. and other contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ Solidus Auth (Devise)
2
+ =====================
3
+
4
+ Provides authentication services for Solidus, using the Devise gem.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Just add this line to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem "solidus_auth_devise"
13
+
14
+ # For Solidus versions < 2.5
15
+ # gem 'deface'
16
+ ```
17
+
18
+ Then, run `bundle install`.
19
+
20
+ After that's done, you can install and run the necessary migrations, then seed the database:
21
+
22
+ ```shell
23
+ bundle exec rake solidus_auth:install:migrations
24
+ bundle exec rake db:migrate
25
+ bundle exec rake db:seed
26
+ ```
27
+
28
+ ### Default Username/Password
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.
31
+
32
+ ### Confirmable
33
+
34
+ To enable Devise's Confirmable module, which will send the user an email with a link to confirm their account, you must do the following:
35
+
36
+ * Add this line to an initializer in your Rails project (typically `config/initializers/spree.rb`):
37
+
38
+ ```ruby
39
+ Spree::Auth::Config[:confirmable] = true
40
+ ```
41
+
42
+ * Add a Devise initializer to your Rails project (typically `config/initializers/devise.rb`):
43
+
44
+ ```ruby
45
+ Devise.setup do |config|
46
+ # Required so users don't lose their carts when they need to confirm.
47
+ config.allow_unconfirmed_access_for = 1.days
48
+
49
+ # Fixes the bug where Confirmation errors result in a broken page.
50
+ config.router_name = :spree
51
+
52
+ # Add any other devise configurations here, as they will override the defaults provided by solidus_auth_devise.
53
+ end
54
+ ```
55
+
56
+ Using in an existing application
57
+ --------------------------------
58
+
59
+ If you are installing Solidus inside of a host application in which you want your own permission setup, you can do this using the `register_ability` method.
60
+
61
+ First create your own CanCan Ability class following the CanCan documentation.
62
+
63
+ For example: `app/models/super_abilities.rb`
64
+
65
+ ```ruby
66
+ class SuperAbilities
67
+ include CanCan::Ability
68
+
69
+ def initialize user
70
+ if user.is? "Superman"
71
+ can :stop, Bullet
72
+ end
73
+ end
74
+ end
75
+ ```
76
+
77
+ Then register your class in your spree initializer: config/initializers/spree.rb
78
+
79
+ ```ruby
80
+ Spree::Ability.register_ability(SuperAbilities)
81
+ ```
82
+
83
+ Inside of your host application you can then use CanCan like you normally would.
84
+
85
+ ```erb
86
+ <% if can? :stop Bullet %>
87
+ ...
88
+ <% end %>
89
+ ```
90
+
91
+ Testing
92
+ -------
93
+
94
+ Run the following to automatically build a dummy app if necessary and run the tests:
95
+
96
+ ```shell
97
+ bundle exec rake
98
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/common_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
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
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'solidus/auth'
20
+ Rake::Task['common:test_app'].invoke("Spree::User")
21
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ class UserMailer < BaseMailer
3
+ def reset_password_instructions(user, token, *args)
4
+ @store = Spree::Store.default
5
+ @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @store.url)
6
+ mail to: user.email, from: from_address(@store), subject: "#{@store.name} #{I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])}"
7
+ end
8
+
9
+ def confirmation_instructions(user, token, opts={})
10
+ @store = Spree::Store.default
11
+ @confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: @store.url)
12
+ mail to: user.email, from: from_address(@store), subject: "#{@store.name} #{I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions])}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Spree
2
+ class AuthConfiguration < Preferences::Configuration
3
+ preference :registration_step, :boolean, default: true
4
+ preference :signout_after_password_change, :boolean, default: true
5
+ preference :confirmable, :boolean, default: false
6
+ preference :draw_frontend_routes, :boolean, default: true
7
+ preference :draw_backend_routes, :boolean, default: true
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ module Spree
2
+ class User < Spree::Base
3
+ include UserMethods
4
+
5
+ devise :database_authenticatable, :registerable, :recoverable,
6
+ :rememberable, :trackable, :validatable, :encryptable
7
+ devise :confirmable if Spree::Auth::Config[:confirmable]
8
+
9
+ acts_as_paranoid
10
+ after_destroy :scramble_email_and_password
11
+
12
+ before_validation :set_login
13
+
14
+ users_table_name = User.table_name
15
+ roles_table_name = Role.table_name
16
+
17
+ scope :admin, -> { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") }
18
+
19
+ def self.admin_created?
20
+ User.admin.count > 0
21
+ end
22
+
23
+ def admin?
24
+ has_spree_role?('admin')
25
+ end
26
+
27
+ protected
28
+ def password_required?
29
+ !persisted? || password.present? || password_confirmation.present?
30
+ end
31
+
32
+ private
33
+
34
+ def set_login
35
+ # for now force login to be same as email, eventually we will make this configurable, etc.
36
+ self.login ||= self.email if self.email
37
+ end
38
+
39
+ def scramble_email_and_password
40
+ self.email = SecureRandom.uuid + "@example.net"
41
+ self.login = self.email
42
+ self.password = SecureRandom.hex(8)
43
+ self.password_confirmation = self.password
44
+ self.save
45
+ end
46
+ end
47
+ end