Module: Fe::ApplicationControllerConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/fe/application_controller_concern.rb

Instance Method Summary collapse

Instance Method Details

#check_valid_userObject



40
41
42
43
44
45
46
# File 'app/controllers/concerns/fe/application_controller_concern.rb', line 40

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

#current_personObject



34
35
36
37
38
# File 'app/controllers/concerns/fe/application_controller_concern.rb', line 34

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

#extract_locale_from_accept_language_headerObject



22
23
24
# File 'app/controllers/concerns/fe/application_controller_concern.rb', line 22

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

#fe_userObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/concerns/fe/application_controller_concern.rb', line 12

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

#set_localeObject



26
27
28
29
30
31
32
# File 'app/controllers/concerns/fe/application_controller_concern.rb', line 26

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