summaryrefslogtreecommitdiff
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2016-05-16 22:07:12 -0600
committermo khan <mo@mokhan.ca>2016-05-16 22:07:12 -0600
commit388e86afe55c25a7c48ee5889a2dbf90c07f4c0c (patch)
tree85c2de911a7c8a7b428aa15047d6b940d64fa112 /app/controllers/application_controller.rb
parentcd0503b929f7247481ebbe7c7a90c3a4847aa75f (diff)
extract authenticatable module.
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb25
1 files changed, 2 insertions, 23 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index f238bd0..f8ef68d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,39 +1,18 @@
class ApplicationController < ActionController::Base
+ include Authenticatable
include Internationalizationable
include Pageable
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
- before_action :authenticate!
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
- helper_method :current_user, :current_session, :feature_available?
-
- protected
-
- def current_session(session_id = session[:user_id])
- @current_session ||= UserSession.authenticate(session_id)
- end
-
- def current_user
- @current_user ||= current_session.try(:user)
- end
+ helper_method :feature_available?
def feature_available?(feature)
return true if Rails.env.test?
$flipper[feature.to_sym].enabled?(current_user)
end
- def translate(key)
- I18n.translate("#{params[:controller]}.#{params[:action]}#{key}")
- end
-
- def authenticate!
- return if current_user.present?
- redirect_to new_session_path
- rescue
- redirect_to new_session_path
- end
-
def record_not_found
render text: "404 Not Found", status: 404
end