# -*- encoding : utf-8 -*- class Public::PCustomerAuthsController < ApplicationController layout "public" before_action :auth_p_customer, :only => [:index, :edit_password] def valid_account @p_customer = PCustomer.find_by_mlm_token(params[:token]) if !@p_customer.enabled @p_customer.enabled = true @p_customer.save mail_hist = MailHist.auto_generate_mail(:fr, "confirmation-inscription", @p_customer.email, {:arguments => {:nbr_inscrits => PCustomer.count}, :p_customer => @p_customer}) end redirect_to public_my_account_path(), :notice => "Votre email a été validé, merci !" end def index #current_p_customer.consolide_operations #current_p_customer.get_particular @title = "Mon intranet" end def new @p_customer = PCustomer.new end def create @p_customer = true @p_customer = PCustomer.find_by_email(params[:email]) if @p_customer && @p_customer.authenticate(params[:password]) #session[:p_customer_user_id] = user.id if params[:remember_me] cookies.permanent[:p_customer_auth_token] = @p_customer.auth_token else cookies[:p_customer_auth_token] = @p_customer.auth_token end if params[:for_order].to_s != "" redirect_to particulars_public_p_orders_path() elsif 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(:p_customer_auth_token) cookies.delete(:p_customer_auth_token) redirect_to public_my_account_path end def edit_password @edit_p_customer = current_p_customer @edit_p_customer.particular.skip_validation = false end def update_password @edit_p_customer = current_p_customer @edit_p_customer.actual_password = params[:p_customer][:actual_password] @edit_p_customer.valid_pswd_confirmation = true @edit_p_customer.password = params[:p_customer][:password] @edit_p_customer.password_confirmation = params[:p_customer][:password_confirmation] @edit_p_customer.valid_last_password = true if @edit_p_customer.save if params[:for_order].to_s != "" redirect_to particulars_public_p_orders_path(), :notice => "Votre mot de passe est à jour." elsif redirect_to public_my_account_path, :notice => "Votre mot de passe est à jour." end else @edit_p_customer.verify_actual_password render :action => :edit_password end end def password_reset end def save_password_reset @edit_p_customer = PCustomer.where(:email => params[:email]).first if @edit_p_customer @edit_p_customer.generate_token(:reset_password_token) @edit_p_customer.reset_password_sent_at = Time.now @edit_p_customer.save #GeneralMailer.send_qi_mail("fr", "espace-donateur-mot-de-passe-perdu", @edit_p_customer.email, {"email" => @edit_p_customer.email, "token" => @edit_p_customer.reset_password_token,"lien_mot_de_passe" => edit_password_reset_public_p_customer_auths_url(:token => @edit_p_customer.reset_password_token)}).deliver #GeneralMailer.send_qi_mail("fr", "reset_mdp", @edit_p_customer.email, {:token => @edit_p_customer.reset_password_token, :lien_mot_de_passe: => "#{edit_password_reset_public_p_customer_auths_url(:token => @edit_p_customer.reset_password_token)}"}).deliver if params[:for_order].to_s != "" lien = edit_password_reset_public_p_customer_auths_url(:token => @edit_p_customer.reset_password_token, :for_order => true) else lien = edit_password_reset_public_p_customer_auths_url(:token => @edit_p_customer.reset_password_token) end mail_hist = MailHist.generate_mail(:fr, MailType.find_or_create("reset_mdp"), @edit_p_customer.email, {:arguments => {:token => @edit_p_customer.reset_password_token, :lien_mot_de_passe => "#{lien}", :civilite => @edit_p_customer.particular.civilite, :nom => @edit_p_customer.particular.name, :prenom => @edit_p_customer.particular.firstname }, :p_customer => @edit_p_customer, :element => @edit_p_customer}) if params[:for_order].to_s != "" redirect_to new_public_p_customer_auth_path(:for_order => true), :notice => "Un email vous a été envoyé" else redirect_to new_public_p_customer_auth_path, :notice => "Un email vous a été envoyé" end else redirect_to :back, :notice => "Cet email ne possède pas de compte" end end def edit_password_reset @edit_p_customer = PCustomer.where(:reset_password_token => params[:token]).first if @edit_p_customer else redirect_to public_p_customer_auths_path, :notice => "Le compte n'a pas été retrouvé" end end def save_edit_password_reset puts "AAAA" puts params[:token] puts PCustomer.where(:reset_password_token => params[:token]).count @edit_p_customer = PCustomer.where(:reset_password_token => params[:token]).first #sdffsdfds = fsdsfd if @edit_p_customer @edit_p_customer.password = params[:p_customer][:password] @edit_p_customer.password_confirmation = params[:p_customer][:password_confirmation] @edit_p_customer.valid_pswd_confirmation = params[:p_customer][:valid_pswd_confirmation] if @edit_p_customer.save cookies[:p_customer_auth_token] = @edit_p_customer.auth_token if params[:for_order].to_s != "" redirect_to particulars_public_p_orders_path(), :notice => "Votre mot de passe a été mis à jour" elsif redirect_to public_my_account_path, :notice => "Votre mot de passe a été mis à jour" end else render :action => :edit_password_reset end else redirect_to public_p_customers_path, :notice => "Le compte n'a pas été retrouvé" end end end