authenticates beta testers in beta site

This commit is contained in:
rgarcia
2015-08-29 15:43:15 +02:00
parent 814744e1af
commit f92b6de22d

View File

@@ -1,7 +1,11 @@
require "application_responder" require "application_responder"
class ApplicationController < ActionController::Base 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? check_authorization unless: :devise_controller?
include SimpleCaptcha::ControllerHelpers include SimpleCaptcha::ControllerHelpers
self.responder = ApplicationResponder self.responder = ApplicationResponder
@@ -16,20 +20,35 @@ 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
private 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 def set_locale
if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
session[:locale] = params[:locale] session[:locale] = params[:locale]