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: :null_session before_action :set_locale helper_method :current_site, :current_user def default_url_options(options={}) { locale: I18n.locale } end def set_locale in_use_locales = current_site.in_use_locales if params[:locale] session[:locale] = in_use_locales.include?(params[:locale].to_sym) ? params[:locale] : nil end if !params[:locale] and !session[:locale] if current_site.enable_language_detection browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.underscore rescue nil session[:locale] = in_use_locales.include?(browser_locale.to_sym) ? browser_locale : nil elsif current_site.default_locale session[:locale] = current_site.default_locale end end session[:locale] = session[:locale].blank? ? I18n.default_locale : session[:locale] I18n.locale = session[:locale] @site_in_use_locales = [I18n.locale]+(in_use_locales-[I18n.locale]) @site_valid_locales = [I18n.locale]+(current_site.valid_locales-[I18n.locale]) end def get_layout f = File.join("../../templates/", "#{@key}", '/home/page.html.erb') end def get_key @key = current_site.template end def current_site @current_site = Site.first end def frontent_allowed current_user.nil? and !current_site.frontend_open end private def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] rescue nil end protected def authenticate_user if session[:user_id] # set current user object to @current_user object variable @current_user = User.find(session[:user_id]) rescue nil redirect_to new_session_path if @current_user.nil? return true else redirect_to new_session_path return false end end end