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
  
  
  
  def auth_inscrit
    if !current_inscrit
      redirect_to new_inscrits_auth_path
    end
      
    
  end
  
  
  private


  
  def auth_admin
    if !current_admin
      redirect_to new_admin_admin_auth_path
    end
      
    
  end
  
  
  private

    def current_admin
      
      if cookies[:admin_remember_token]
        if @current_admin = Admin.find_by_remember_token(cookies[:admin_remember_token]) 
          @current_admin = Admin.find_by_remember_token(cookies[:admin_remember_token]) 
        else
            cookies[:admin_remember_token] =nil
        end
        
      end
      
      
     
    end
    
    def current_inscrit
      if session[:inscrit_id] and Inscrit.exists?(session[:inscrit_id])
        @current_inscrit = Inscrit.find(session[:inscrit_id])
      else
        nil
      end
     
    end
    


  
    
    
    helper_method :current_admin, :current_inscrit
  
end

