lib/omnicontacts/middleware/base_oauth.rb in omnicontacts-0.3.4 vs lib/omnicontacts/middleware/base_oauth.rb in omnicontacts-0.3.5
- old
+ new
@@ -11,11 +11,11 @@
attr_reader :ssl_ca_file
def initialize app, options
@app = app
- @listening_path = "/contacts/" + class_name
+ @listening_path = MOUNT_PATH + class_name
@ssl_ca_file = options[:ssl_ca_file]
end
def class_name
self.class.name.split('::').last.downcase
@@ -67,10 +67,14 @@
end
@app.call(@env)
end
end
+ def set_current_user user
+ @env["omnicontacts.user"] = user
+ end
+
# This method rescues executes a block of code and
# rescue all exceptions. In case of an exception the
# user is redirected to the failure endpoint.
def execute_and_rescue_exceptions
yield
@@ -81,12 +85,14 @@
rescue ::RuntimeError => e
handle_error :internal_error, e
end
def handle_error error_type, exception
- logger << ("Error #{error_type} while processing #{@env["PATH_INFO"]}: #{exception.message}") if logger
- [302, {"Content-Type" => "text/html", "location" => "/contacts/failure?error_message=#{error_type}&importer=#{class_name}"}, []]
+ logger.puts("Error #{error_type} while processing #{@env["PATH_INFO"]}: #{exception.message}") if logger
+ failure_url = "#{ MOUNT_PATH }failure?error_message=#{error_type}&importer=#{class_name}"
+ target_url = append_state_query(failure_url)
+ [302, {"Content-Type" => "text/html", "location" => target_url}, []]
end
def session
raise "You must provide a session to use OmniContacts" unless @env["rack.session"]
@env["rack.session"]
@@ -98,8 +104,17 @@
def base_prop_name
"omnicontacts." + class_name
end
+ def append_state_query(target_url)
+ state = Rack::Utils.parse_query(@env['QUERY_STRING'])['state']
+
+ unless state.nil?
+ target_url = target_url + (target_url.include?("?")?"&":"?") + 'state=' + state
+ end
+
+ return target_url
+ end
end
end
end