coton_app/app/controllers/public/p_customer_auths_controller.rb
Nicolas Bally 5f5d2b403f suite
2019-03-04 02:34:11 +01:00

57 lines
1.2 KiB
Ruby
Executable File

# -*- encoding : utf-8 -*-
class Public::PCustomerAuthsController < ApplicationController
layout "public"
def new
params[:step] = "login"
@p_customer = PCustomer.new(:valid_public => true)
particular = Particular.new(:pro => true, :skip_validation => true)
particular.p_contacts << PContact.new
@p_customer.particulars << particular
end
def create
@p_customer = PCustomer.new(:valid_public => true)
params[:step] = "login"
user = PCustomer.find_by_email(params[:email])
if user && user.password_digest && user.authenticate(params[:password].to_s)
#session[:forum_user_id] = user.id
if params[:remember_me]
cookies.permanent[:p_customer_auth_token] = user.token
else
cookies[:p_customer_auth_token] = user.token
end
user.last_sign_in_at = Time.now
user.save(:validate => false)
redirect_to public_p_products_path
else
flash.now.alert = "Email ou mot de passe incorect"
render :action => "new"
end
end
def logout
cookies.delete(:p_customer_auth_token)
redirect_to "/", notice: "Déconnecté."
end
end