adds password protection for staging and production servers

This commit is contained in:
rgarcia
2015-08-28 17:27:14 +02:00
parent b9333c7bbe
commit fe9586bc29

View File

@@ -1,6 +1,7 @@
require "application_responder" require "application_responder"
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_filter :authenticate
check_authorization unless: :devise_controller? check_authorization unless: :devise_controller?
include SimpleCaptcha::ControllerHelpers include SimpleCaptcha::ControllerHelpers
self.responder = ApplicationResponder self.responder = ApplicationResponder
@@ -15,6 +16,14 @@ class ApplicationController < ActionController::Base
before_action :ensure_signup_complete before_action :ensure_signup_complete
def authenticate
if Rails.env.staging? || Rails.env.production?
authenticate_or_request_with_http_basic do |username, password|
username == Rails.application.secrets.username && password == Rails.application.secrets.password
end
end
end
rescue_from CanCan::AccessDenied do |exception| rescue_from CanCan::AccessDenied do |exception|
redirect_to main_app.root_url, alert: exception.message redirect_to main_app.root_url, alert: exception.message
end end