87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/action_interceptor/controller.rb', line 87
def acts_as_interceptor(options = {})
return if is_interceptor
self.is_interceptor = true
@override_url_options = options[:override_url_options].nil? ? \
ActionInterceptor.override_url_options : \
options[:override_url_options]
class_eval do
attr_writer :intercepted_url
helper_method :intercepted_url
def intercepted_url
return @intercepted_url if @intercepted_url
key = ActionInterceptor.intercepted_url_key
begin
@intercepted_url = Encryptor.decrypt_and_verify(params[key])
rescue ActiveSupport::MessageVerifier::InvalidSignature
@intercepted_url = session[key] || request.referer || '/'
end
session[key] = @intercepted_url
@intercepted_url
end
def intercepted_url_hash
return @intercepted_url_hash if @intercepted_url_hash
url = Encryptor.encrypt_and_sign(intercepted_url)
key = ActionInterceptor.intercepted_url_key
@intercepted_url_hash = {key => url}
end
alias_method :url_options_without_interceptor, :url_options
def url_options_with_interceptor
return @url_options_with_interceptor \
if @url_options_with_interceptor
@url_options_with_interceptor = intercepted_url_hash.merge(
url_options_without_interceptor)
end
alias_method :url_options, :url_options_with_interceptor \
if @override_url_options.nil? || @override_url_options
def without_interceptor(&block)
previous_url_options = url_options_with_interceptor
begin
@url_options_with_interceptor = url_options_without_interceptor
yield block
ensure
@url_options_with_interceptor = previous_url_options
end
end
def redirect_back(options = {})
url = intercepted_url
without_interceptor do
url = root_url if url == '/' || current_page?(url)
redirect_to url, options
end
end
end
end
|