Sha256: 13ddb97d5066bd00b2a2f979e184356c8f50054ba6f1d234bcbacc19d5665ca3

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Brightcontent
  class ApplicationController < ActionController::Base
    add_flash_types :success, :info, :warning, :danger
    before_action :authorize
    before_action :set_locale
    helper TranslationHelper
    protect_from_forgery

    def index
      redirect_to polymorphic_url(user_resources.first.klass)
    end

    def default_url_options(options = {})
      { locale: I18n.locale }.merge options
    end

    private

    def set_locale
      I18n.locale = params[:locale] || Brightcontent.locale
    end

    def current_user
      @current_user ||= begin
        Brightcontent.user_model.find(session[:brightcontent_user_id]) if session[:brightcontent_user_id]
      end.tap { |u| logger.info "Current Brightcontent user: #{u&.to_gid}" }
    end
    helper_method :current_user

    def user_resources
      @user_resources ||= @current_user.resources
    end
    helper_method :user_resources

    def authorize
      unless current_user
        session[:return_to] = request.original_url
        redirect_to login_url
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brightcontent-core-2.6.0 app/controllers/brightcontent/application_controller.rb