-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathengine.rb
80 lines (66 loc) · 2.56 KB
/
engine.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require 'devise'
require 'devise-encryptable'
module Spree
module Auth
class Engine < Rails::Engine
isolate_namespace Spree
engine_name 'solidus_auth'
initializer "spree.auth.environment", before: :load_config_initializers do |app|
Spree::Auth::Config = Spree::AuthConfiguration.new
end
initializer "solidus_auth_devise.set_user_class", after: :load_config_initializers do
Spree.user_class = "Spree::User"
end
config.to_prepare do
auth = Spree::Auth::Engine
auth.prepare_backend if SolidusSupport.backend_available?
auth.prepare_frontend if SolidusSupport.frontend_available?
ApplicationController.send :include, Spree::AuthenticationHelpers
end
def self.prepare_backend
Rails.application.config.assets.precompile += %w[
lib/assets/javascripts/spree/backend/solidus_auth.js
lib/assets/javascripts/spree/backend/solidus_auth.css
]
Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/backend/*/*/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
Spree::Admin::BaseController.unauthorized_redirect = -> do
if try_spree_current_user
flash[:error] = I18n.t('spree.authorization_failure')
redirect_to spree.admin_unauthorized_path
else
store_location
redirect_to spree.admin_login_path
end
end
end
def self.prepare_frontend
Rails.application.config.assets.precompile += %w[
lib/assets/javascripts/spree/frontend/solidus_auth.js
lib/assets/javascripts/spree/frontend/solidus_auth.css
]
Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/*/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
Spree::BaseController.unauthorized_redirect = -> do
if try_spree_current_user
flash[:error] = I18n.t('spree.authorization_failure')
redirect_to spree.unauthorized_path
else
store_location
redirect_to spree.login_path
end
end
end
if SolidusSupport.backend_available?
paths["app/controllers"] << "lib/controllers/backend"
paths["app/views"] << "lib/views/backend"
end
if SolidusSupport.frontend_available?
paths["app/controllers"] << "lib/controllers/frontend"
paths["app/views"] << "lib/views/frontend"
end
end
end
end