class Public::ReseauxesController < ApplicationController
  layout "public"
  before_filter :auth_customer, :except => :find_sub_domain

  def index
    @reseauxes = current_customer.own_reseauxes.order(:name)
    if @reseauxes.count == 1
      redirect_to public_reseaux_path(@reseauxes.first)
    end
  end

  def show
    @reseaux_layout = true
    @reseaux = current_customer.own_reseauxes.find(params[:id])
    @reseaux_chief_layout = true
    #@reseaux = Reseaux.find(params[:id])

  end
  
  def products
    
    
    #@reseaux = Reseaux.find(params[:id])

  end


  def find_sub_domain
    if ["negos.pro", "localhost.qz"].include?(request.domain(1))
      
      sub_domain = request.domain(2).split(".")[0]
      @reseaux = Reseaux.where(:sub_domain => sub_domain.to_s).first
      if @reseaux
        if request.domain(1) == "localhost.qz"
          redirect_to "http://localhost:3000/public/customers_auths/new?p="+@reseaux.token.to_s
        
        else
          redirect_to "http://negos.pro/public/customers_auths/new?p="+@reseaux.token.to_s
        end
      else
        redirect_to "http://negos.pro"
      end
      
      
    end
  end
  
end
