125 lines
3.3 KiB
Ruby
Executable File
125 lines
3.3 KiB
Ruby
Executable File
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
|
|
|
|
before_filter :get_reseaux
|
|
before_filter :set_order
|
|
|
|
|
|
|
|
|
|
def get_reseaux
|
|
if params[:reseaux_id] and current_customer and !params[:no_reseaux]
|
|
@reseaux = current_customer.reseauxes.find(params[:reseaux_id])
|
|
@reseaux_layout = true
|
|
session[:reseaux_id] = @reseaux.id
|
|
elsif session[:reseaux_id] and current_customer and !params[:no_reseaux]
|
|
@reseaux = current_customer.reseauxes.find(session[:reseaux_id])
|
|
@reseaux_layout = true
|
|
elsif !params[:no_reseaux]
|
|
session[:reseaux_id] = nil
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def set_order
|
|
if session[:product_order_id] && @product_order = ProductOrder.where(id: session[:product_order_id]).first
|
|
if @product_order.paid
|
|
@product_order = ProductOrder.new
|
|
@product_order.save
|
|
|
|
session[:product_order_id] = @product_order.id
|
|
end
|
|
else
|
|
@product_order = ProductOrder.new
|
|
|
|
@product_order.save
|
|
|
|
session[:product_order_id] = @product_order.id
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_enabled
|
|
if (!@current_customer and current_admin and params[:admin])
|
|
|
|
|
|
elsif (@current_customer and !@current_customer.account_validated?)
|
|
redirect_to public_my_account_path
|
|
end
|
|
end
|
|
|
|
def auth_customer
|
|
|
|
session[:devise_id] = params[:d] if params[:d]
|
|
if !current_customer and !(current_admin and params[:admin])
|
|
session[:before_auth_url] = request.url
|
|
redirect_to new_public_customers_auth_path(:p => params[:p], :for_annonce => (true if params[:controller] == "public/annonces"))
|
|
else
|
|
if !(current_admin and params[:admin])
|
|
@current_customer.last_activity = DateTime.now
|
|
@current_customer.save
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def current_abo
|
|
if current_customer
|
|
abo = current_customer.abonnements.where(:paid => true, :reseaux_id => session[:reseaux_id]).where("start_at <= ? and end_at >= ?", Time.now, Time.now).first
|
|
end
|
|
end
|
|
|
|
def require_negos_abo
|
|
get_reseaux
|
|
|
|
if !current_abo and (!session[:reseaux_id] or (@reseaux and @reseaux.abo_needed))
|
|
redirect_to new_public_abonnement_path
|
|
end
|
|
end
|
|
|
|
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_customer
|
|
if cookies[:customer_auth_token] and Customer.exists?(:token => cookies[:customer_auth_token])
|
|
a_c = Customer.find_by_token(cookies[:customer_auth_token])
|
|
if !a_c.lock
|
|
@current_customer = a_c
|
|
|
|
else
|
|
cookies[:customer_auth_token] = nil
|
|
nil
|
|
end
|
|
else
|
|
nil
|
|
end
|
|
end
|
|
|
|
def redirect_back_or_default(default = root_path, options = {})
|
|
redirect_to (request.referer.present? ? :back : default), options
|
|
end
|
|
|
|
helper_method :current_admin, :current_customer
|
|
|
|
end
|