From d394f7d83cf8a3bcc80251e2a2cb3b6537cd123d Mon Sep 17 00:00:00 2001 From: Gudata Date: Mon, 16 Jan 2012 16:00:54 +0200 Subject: [PATCH] Simple authentication using translate/current hostname --- app/controllers/translate_controller.rb | 10 ++++++++++ config/routes.rb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/translate_controller.rb b/app/controllers/translate_controller.rb index 219a75e..59b8aa9 100644 --- a/app/controllers/translate_controller.rb +++ b/app/controllers/translate_controller.rb @@ -1,7 +1,17 @@ class TranslateController < ActionController::Base # It seems users with active_record_store may get a "no :secret given" error if we don't disable csrf protection, skip_before_filter :verify_authenticity_token + + before_filter :authenticate + + protected + def authenticate + authenticate_or_request_with_http_basic do |username, password| + username == "translate" && password == `hostname`.chomp + end + end + prepend_view_path(File.join(File.dirname(__FILE__), "..", "views")) layout 'translate' diff --git a/config/routes.rb b/config/routes.rb index de5fe9b..bea8ccd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,4 +2,4 @@ match 'translate' => 'translate#index', :as => :translate_list match 'translate/translate' => 'translate#translate', :as => :translate match 'translate/reload' => 'translate#reload', :as => :translate_reload -end if Rails.env.development? +end \ No newline at end of file