diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9df8c4874..d611d79b2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,11 @@ require "application_responder" class ApplicationController < ActionController::Base - before_filter :authenticate + before_filter :authenticate_http_basic + + before_filter :authenticate_user!, unless: :devise_controller?, if: :beta_site? + before_filter :authenticate_beta_tester!, unless: :devise_controller?, if: :beta_site? + check_authorization unless: :devise_controller? include SimpleCaptcha::ControllerHelpers self.responder = ApplicationResponder @@ -16,20 +20,35 @@ class ApplicationController < ActionController::Base 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| redirect_to main_app.root_url, alert: exception.message end private + def authenticate_http_basic + 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 + + def authenticate_beta_tester! + unless beta_testers.include?(current_user.email) + sign_out(current_user) + redirect_to new_user_session_path, alert: "Sorry only Beta Testers are allowed access at the moment" + end + end + + def beta_testers + File.readlines('config/beta-testers.txt').map {|email| email } + end + + def beta_site? + Rails.application.secrets.beta_site + end + def set_locale if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) session[:locale] = params[:locale]