Sha256: 246944e2e10872412ba0e4e01412d38d64f10477cf2a4d0b94c48290380820e9

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module FlyAdmin::Imbs
  class ApplicationController < ActionController::Base
    protect_from_forgery

    before_filter :block_user, :store_link_param
    before_filter :check_user_status, if: Proc.new { user_signed_in? && old_user? }, unless: :devise_controller?
    before_filter :set_locale, :load_footer

    def block_user
      render_blocked if session[:blocked]
    end

    def store_link_param
      session[:link] = params[:link] if params[:link].present?
    end

    def check_user_status
      user_is_valid = FlyAdmin::Imbs::ConnectionApi.check_user(current_user)

      if user_is_valid 
        current_user.update_attributes is_active: true
        cookies[:active_user] = { value: 1, expires: 1.day.from_now }
      else
        current_user.update_attributes is_active: false
        session[:blocked] = true
        render_blocked
      end
    end

    def load_footer
      paysite = session['action_type'] || 'wap'
      country = I18n.locale.to_s
      @footer = SiteCache.read("content_#{paysite}_#{country}")
    end
    
    private

    def old_user?
      !(current_user.admin? || current_user.tester? || cookies[:active_user].present?)
    end

    def set_locale
      locale = params["locale"].try(:downcase).try(:to_sym)
      I18n.locale = locale && I18n.available_locales.include?(params) ? locale : I18n.default_locale
    end

    # Locale for all url_helpers in rails
    def default_url_options(options = {})
      { locale: I18n.locale }.merge options
    end
      
    def after_sign_in_path_for(resource)
      root_url
    end

    def after_sign_out_path_for(resource)
      root_url
    end

    def render_blocked
      render 'errors/blocked', status: :forbidden
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fly_admin-0.0.8 app/controllers/fly_admin/imbs/application_controller.rb