coton_app/app/controllers/public/p_customer_auths_controller.rb
2018-12-15 14:06:53 +01:00

55 lines
1019 B
Ruby
Executable File

# -*- encoding : utf-8 -*-
class Public::PCustomerAuthsController < ApplicationController
layout "public"
def new
params[:step] = "login"
@p_customer = PCustomer.new(:valid_public => true)
end
def create
@p_customer = PCustomer.new(:valid_public => true)
params[:step] = "login"
user = PCustomer.find_by_email(params[:email])
if user && user.authenticate(params[:password])
#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_my_account_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