Sha256: 37ccac27a8a2c84e621dbc3892deaa70e6c75b69f7358deddf99abcea46ea040

Contents?: true

Size: 1.28 KB

Versions: 13

Compression:

Stored size: 1.28 KB

Contents

module Fe::ApplicationControllerConcern
  extend ActiveSupport::Concern

  begin
    included do
      helper_method :fe_user
      before_action :set_locale
    end
  rescue ActiveSupport::Concern::MultipleIncludedBlocks
  end

  def fe_user
    return nil unless current_user
    @fe_user ||= Fe::User.where(user_id: current_user.id).first
    if @fe_user
      @fe_user.update_attribute(:last_login, Time.now)
      session[:login_stamped] = true
    end
    @fe_user
  end

  def extract_locale_from_accept_language_header
    request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first if request.env['HTTP_ACCEPT_LANGUAGE'].present?
  end

  def set_locale
    session[:locale] = params[:locale] if params[:locale]
    session[:locale] ||= extract_locale_from_accept_language_header || I18n.default_locale
    if @answer_sheet
      session[:locale] = I18n.default_locale unless @answer_sheet.languages.include?(session[:locale])
    end
  end

  def current_person
    #raise "no user" unless current_user
    return nil unless current_user
    current_user.fe_person || Fe::Person.create(user_id: current_user.id)
  end

  def check_valid_user
    unless fe_user
      # TODO redirect to somewhere better
      redirect_to "/", flash: { error: "Access denied" }
      return false
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
fe-2.1.5 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.1.4 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.1.3 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.1.2 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.1.1 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.8 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.6 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.5 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.4 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.3 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.2 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.1 app/controllers/concerns/fe/application_controller_concern.rb
fe-2.0.0 app/controllers/concerns/fe/application_controller_concern.rb