# -*- encoding : utf-8 -*- class Public::CustomersAuthsController < ApplicationController layout "public" def new @no_search = true params[:step] = "login" if params[:for_annonce] session[:for_annonce] = true else session[:for_annonce] = nil end @customer = Customer.new() if cookies[:mlm_token] and @parent = Customer.find_parrain(cookies[:mlm_token]) @customer.parent_code = @parent.mlm_token.upcase elsif params[:p] and @parent = Customer.find_parrain(params[:p]) @customer.parent_code = @parent.mlm_token.upcase end end def create @customer = Customer.new() if cookies[:mlm_token] and @parent = Customer.find_parrain(cookies[:mlm_token]) @customer.parent_code = @parent.mlm_token.upcase elsif params[:p] and @parent = Customer.find_parrain(params[:p]) @customer.parent_code = @parent.mlm_token.upcase end params[:step] = "login" @no_search = true user = Customer.find_by_email(params[:email]) if user && user.authenticate(params[:password]) #session[:forum_user_id] = user.id if params[:remember_me] cookies.permanent[:customer_auth_token] = user.token else cookies[:customer_auth_token] = user.token end user.last_sign_in_at = Time.now user.save(:validate => false) if session[:for_annonce] redirect_to new_public_annonce_path else redirect_to public_my_account_path end else flash.now.alert = "Email ou mot de passe incorect" render "new" end end def logout cookies.delete(:customer_auth_token) redirect_to "/", notice: "Déconnecté." end end