178 lines
4.0 KiB
Ruby
Executable File
178 lines
4.0 KiB
Ruby
Executable File
class Public::CustomersController < ApplicationController
|
|
layout "public"
|
|
|
|
before_filter :auth_customer, :except => [:new, :create, :confirm, :show, :parrainage, :mail, :find_parrain]
|
|
|
|
|
|
def parrainage
|
|
cookies.permanent[:mlm_token] = params[:mlm_token]
|
|
redirect_to "/"
|
|
end
|
|
|
|
def index
|
|
|
|
@customers = Customer.all
|
|
if params[:reseaux_id]
|
|
@reseaux_layout = true
|
|
@reseaux = current_customer.own_reseauxes.find(params[:reseaux_id])
|
|
@customers = @reseaux.customers
|
|
if params[:domain_id] and params[:domain_id].to_s != ""
|
|
|
|
@customers = @customers.joins(:domains).where(:domains => {:id => params[:domain_id]})
|
|
end
|
|
@reseaux_chief_layout = true
|
|
end
|
|
end
|
|
|
|
|
|
def show
|
|
@customer = current_customer.own_customers.find(params[:id])
|
|
if params[:reseaux_id]
|
|
@reseaux_layout = true
|
|
@reseaux = current_customer.own_reseauxes.find(params[:reseaux_id])
|
|
@reseaux_chief_layout = true
|
|
end
|
|
end
|
|
|
|
|
|
def new
|
|
|
|
|
|
@customer = Customer.new()
|
|
if params[:p]
|
|
@customer.reseaux_token = params[:p]
|
|
end
|
|
|
|
|
|
end
|
|
|
|
def show_details
|
|
@no_search = true
|
|
if current_customer.mlm_children_ids.include?(params[:id].to_i)
|
|
|
|
@customer = Customer.find(params[:id])
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def edit
|
|
@customer = Customer.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
params[:step] = "login"
|
|
@no_search = true
|
|
@customer = Customer.new(params.require(:customer).permit!)
|
|
@customer.account_validated = true
|
|
|
|
if @customer.save
|
|
@customer.reseauxes << Reseaux.find(16)
|
|
@customer.reseauxes << Reseaux.find(2)
|
|
@customer.domains << Domain.find(1)
|
|
|
|
CustomerMailer.confirm(@customer).deliver
|
|
CustomerMailer.notify_ins(@customer).deliver
|
|
|
|
|
|
@customer.authenticate(params[:password])
|
|
|
|
cookies[:customer_auth_token] = @customer.token
|
|
|
|
|
|
#if session[:for_annonce]
|
|
# redirect_to new_public_annonce_path(:ins => "ins_finish"), notice: "Vous êtes désormais inscrit."
|
|
#else
|
|
# redirect_to public_my_account_path(:ins => "ins_finish"), notice: "Vous êtes désormais inscrit."
|
|
#end
|
|
redirect_to public_my_reseauxes_path(), notice: "Vous êtes désormais inscrit."
|
|
|
|
|
|
if cookies[:video_read] == "true"
|
|
flash[:read_video] = false
|
|
else
|
|
cookies.permanent[:video_read] = "true"
|
|
flash[:read_video] = true
|
|
end
|
|
|
|
|
|
else
|
|
|
|
render :action => "new"
|
|
end
|
|
end
|
|
|
|
def confirm
|
|
@customer = Customer.find_by_token(params[:id])
|
|
@customer.enabled = true
|
|
@customer.save(:validate => false)
|
|
|
|
CustomerMailer.confirm_ins(@customer).deliver
|
|
|
|
cookies[:customer_auth_token] = @customer.token
|
|
|
|
redirect_to public_my_account_path, notice: "Votre adresse mail a bien été validée, merci beaucoup."
|
|
#redirect_to "/"
|
|
end
|
|
|
|
|
|
def update
|
|
@customer = Customer.find(params[:id])
|
|
|
|
@accepted_offers = @customer.accepted_offers.order(created_at: :desc).page(params[:page_offers]).per(5)
|
|
@wishes = @customer.wishes.includes(:need).page(params[:page_wishes]).per(5)
|
|
|
|
@needs = Kaminari.paginate_array(@customer.owned_needs.order(created_at: :desc))
|
|
.page(params[:page_needs])
|
|
.per(5)
|
|
|
|
if params[:order]
|
|
|
|
@customer.force_address = true
|
|
end
|
|
|
|
if @customer == current_customer
|
|
|
|
|
|
if @customer.update_attributes(params.require(:customer).permit!)
|
|
|
|
flash[:success] = "Vos informations ont bien été enregistrées"
|
|
redirect_to public_my_account_path
|
|
|
|
else
|
|
flash[:error] = "Certains champs sont invalides"
|
|
render :template => "public/my_account/edit_infos"
|
|
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mail
|
|
@no_search = true
|
|
@customer = Customer.find_by_id(params[:id])
|
|
|
|
if @customer
|
|
@customer_message = CustomerMessage.new(:destinataire => @customer)
|
|
|
|
|
|
@customer_message.expediteur = current_customer if current_customer
|
|
if @customer_message.expediteur
|
|
@customer_message.expediteur_mail = current_customer.email
|
|
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
|
|
end
|