Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.

Commit f3066b7

Browse files
Allow turning on/off different devise features (#588)
* Allow turning on/off different devise features * Update lib/views/frontend/spree/user_sessions/new.html.erb * admin user class can be set on its own * options must be last to not be overwritten * fixed specs --------- Co-authored-by: Damian Legawiec <damian@getvendo.com> Co-authored-by: Damian Legawiec <damian@sparksolutions.co>
1 parent 2dcc528 commit f3066b7

5 files changed

Lines changed: 45 additions & 19 deletions

File tree

app/models/spree/user.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ class User < Spree::Base
33
include UserAddress
44
include UserMethods
55
include UserPaymentSource
6-
if defined?(Spree::Metadata)
7-
include Metadata
8-
end
6+
include Metadata if defined?(Spree::Metadata)
97

10-
devise :database_authenticatable, :registerable, :recoverable,
11-
:rememberable, :trackable, :encryptable, encryptor: 'authlogic_sha512'
8+
devise :database_authenticatable if Spree::Auth::Config[:database_authenticatable]
9+
devise :recoverable if Spree::Auth::Config[:recoverable]
10+
devise :registerable if Spree::Auth::Config[:registerable]
1211
devise :confirmable if Spree::Auth::Config[:confirmable]
1312
devise :validatable if Spree::Auth::Config[:validatable]
1413

14+
devise :rememberable, :trackable, :encryptable, encryptor: 'authlogic_sha512'
15+
1516
acts_as_paranoid
1617
after_destroy :scramble_email_and_password
1718

config/routes.rb

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@
1111
path_prefix: :user
1212

1313
devise_scope :spree_user do
14-
get '/login' => 'user_sessions#new', :as => :login
15-
post '/login' => 'user_sessions#create', :as => :create_new_session
1614
get '/logout' => 'user_sessions#destroy', :as => :logout
17-
get '/signup' => 'user_registrations#new', :as => :signup
18-
post '/signup' => 'user_registrations#create', :as => :registration
19-
get '/password/recover' => 'user_passwords#new', :as => :recover_password
20-
post '/password/recover' => 'user_passwords#create', :as => :reset_password
21-
get '/password/change' => 'user_passwords#edit', :as => :edit_password
22-
put '/password/change' => 'user_passwords#update', :as => :update_password
23-
get '/confirm' => 'user_confirmations#show', :as => :confirmation
15+
16+
if Spree::Auth::Config[:database_authenticatable]
17+
get '/login' => 'user_sessions#new', :as => :login
18+
post '/login' => 'user_sessions#create', :as => :create_new_session
19+
20+
get '/password/change' => 'user_passwords#edit', :as => :edit_password
21+
put '/password/change' => 'user_passwords#update', :as => :update_password
22+
end
23+
24+
if Spree::Auth::Config[:registerable]
25+
get '/signup' => 'user_registrations#new', :as => :signup
26+
post '/signup' => 'user_registrations#create', :as => :registration
27+
end
28+
29+
if Spree::Auth::Config[:recoverable]
30+
get '/password/recover' => 'user_passwords#new', :as => :recover_password
31+
post '/password/recover' => 'user_passwords#create', :as => :reset_password
32+
end
33+
34+
if Spree::Auth::Config[:confirmable]
35+
get '/confirm' => 'user_confirmations#show', :as => :confirmation
36+
end
2437
end
2538

2639
if Spree::Core::Engine.frontend_available?
@@ -33,12 +46,13 @@
3346
if Spree.respond_to?(:admin_path) && Spree::Core::Engine.backend_available?
3447
namespace :admin, path: Spree.admin_path do
3548
devise_for :spree_user,
36-
class_name: Spree.user_class.to_s,
49+
class_name: Spree.admin_user_class.to_s,
3750
controllers: { sessions: 'spree/admin/user_sessions',
38-
passwords: 'spree/admin/user_passwords' },
51+
passwords: 'spree/admin/user_passwords' },
3952
skip: [:unlocks, :omniauth_callbacks, :registrations],
4053
path_names: { sign_out: 'logout' },
4154
path_prefix: :user
55+
4256
devise_scope :spree_user do
4357
get '/authorization_failure', to: 'user_sessions#authorization_failure', as: :unauthorized
4458
get '/login' => 'user_sessions#new', :as => :login

lib/spree/auth/configuration.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ class Configuration
44
attr_accessor :registration_step,
55
:signout_after_password_change,
66
:confirmable,
7+
:database_authenticatable,
8+
:recoverable,
9+
:registerable,
710
:validatable
811

912
def initialize
1013
self.registration_step = true
1114
self.signout_after_password_change = true
1215
self.confirmable = false
16+
self.database_authenticatable = true
17+
self.recoverable = true
18+
self.registerable = true
1319
self.validatable = true
1420
end
1521

lib/views/frontend/spree/user_sessions/new.html.erb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
<%= render partial: 'spree/shared/login' %>
88
<div data-hook="login_extras"></div>
99
</div>
10-
<div class="col-lg-11 mx-auto" data-hook="registration">
11-
<%= render partial: 'spree/shared/registration', locals: { registration_button: 'registration-button' } %>
12-
</div>
10+
11+
<% if Spree::Auth::Config[:registerable] %>
12+
<div class="col-lg-11 mx-auto" data-hook="registration">
13+
<%= render partial: 'spree/shared/registration', locals: { registration_button: 'registration-button' } %>
14+
</div>
15+
<% end %>
1316
</div>
1417
</div>
1518
</div>

spec/models/user_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
describe "#send_confirmation_instructions", retry: 2 do
107107
let(:default_store) { Spree::Store.default }
108108

109+
before { Rails.application.reload_routes! }
110+
109111
context "when current store not exists" do
110112
it 'takes default store and sends confirmation instruction', confirmable: true do
111113
user = Spree.user_class.new

0 commit comments

Comments
 (0)