-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathengine.rb
97 lines (78 loc) · 2.92 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# frozen_string_literal: true
require 'solidus_auth_devise'
require 'devise'
require 'devise-encryptable'
require 'spree/auth/version'
module Spree
module Auth
class Engine < Rails::Engine
include SolidusSupport::EngineExtensions
isolate_namespace Spree
engine_name 'solidus_auth'
Spree.user_class = "Spree::User"
initializer "spree.auth.environment", before: :load_config_initializers do |_app|
require 'spree/auth_configuration'
Spree::Auth::Config = Spree::AuthConfiguration.new
end
config.to_prepare do
Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available?
Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available?
ApplicationController.include Spree::AuthenticationHelpers
end
def self.redirect_back_on_unauthorized?
return false unless Spree::Config.respond_to?(:redirect_back_on_unauthorized)
if Spree::Config.redirect_back_on_unauthorized
true
else
Spree::Deprecation.warn <<-WARN.strip_heredoc, caller
Having Spree::Config.redirect_back_on_unauthorized set
to `false` is deprecated and will not be supported in Solidus 3.0.
Please change this configuration to `true` and be sure that your
application does not break trying to redirect back when there is
an unauthorized access.
WARN
false
end
end
def self.prepare_backend
Spree::Admin::BaseController.unauthorized_redirect = -> do
if spree_current_user
flash[:error] = I18n.t('spree.authorization_failure')
if Spree::Auth::Engine.redirect_back_on_unauthorized?
redirect_back(fallback_location: spree.admin_unauthorized_path)
else
redirect_to spree.admin_unauthorized_path
end
else
store_location
if Spree::Auth::Engine.redirect_back_on_unauthorized?
redirect_back(fallback_location: spree.admin_login_path)
else
redirect_to spree.admin_login_path
end
end
end
end
def self.prepare_frontend
Spree::BaseController.unauthorized_redirect = -> do
if spree_current_user
flash[:error] = I18n.t('spree.authorization_failure')
if Spree::Auth::Engine.redirect_back_on_unauthorized?
redirect_back(fallback_location: spree.unauthorized_path)
else
redirect_to spree.unauthorized_path
end
else
store_location
if Spree::Auth::Engine.redirect_back_on_unauthorized?
redirect_back(fallback_location: spree.login_path)
else
redirect_to spree.login_path
end
end
end
end
end
end
end
SolidusAuthDevise::Engine = Spree::Auth::Engine