Files
ch420/app/controllers/application_controller.rb
T

42 lines
1.2 KiB
Ruby
Raw Normal View History

2015-10-02 21:05:03 +02:00
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
2016-04-21 16:53:30 +02:00
2016-04-21 16:51:35 +02:00
before_action :set_locale
2017-03-31 14:42:37 +02:00
before_action :configure_permitted_parameters, if: :devise_controller?
2015-10-06 09:16:07 +02:00
INPUT_TIMEOUT = 2.seconds # We estimate that a user needs more then x seconds to enter some informations
# calculate how long a user needed for a form input, ussually we just
def input_to_fast?
2017-02-26 18:22:28 +01:00
raise 'session[:form_timestamp] not set' unless session[:form_timestamp]
2015-10-06 09:16:07 +02:00
duration = Time.now - session[:form_timestamp].to_time
duration < INPUT_TIMEOUT
end
# Set the current timestamp that marks entering a form
def set_form_timestamp
session[:form_timestamp] = Time.now
end
2016-04-21 16:53:30 +02:00
2016-04-21 16:51:35 +02:00
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
2016-04-21 16:53:30 +02:00
2016-04-21 16:51:35 +02:00
# I18n set default language in url
def default_url_options(options = {})
options.merge locale: I18n.locale
end
2017-03-31 14:42:37 +02:00
2017-04-14 11:34:01 +02:00
def admin_area
false
end
2017-03-31 14:42:37 +02:00
protected
def configure_permitted_parameters
2017-04-18 14:41:35 +02:00
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :street, :city, :zip, :support, :language, :age_category])
2017-03-31 14:42:37 +02:00
end
2015-10-02 21:05:03 +02:00
end