diff --git a/Imagens para correção /Imagem colada (14).png b/Imagens para correção /Imagem colada (14).png new file mode 100644 index 0000000..2d1d36b Binary files /dev/null and b/Imagens para correção /Imagem colada (14).png differ diff --git a/app/controllers/motorista/sessoes_controller.rb b/app/controllers/motorista/sessoes_controller.rb index 912b9d8..5268a94 100644 --- a/app/controllers/motorista/sessoes_controller.rb +++ b/app/controllers/motorista/sessoes_controller.rb @@ -9,36 +9,53 @@ module Motorista layout 'application' # GET /motorista/login — tela com teclado de PIN - def new; end + # Se veio de um QR Code, o motorista já está pré-identificado (só falta o PIN). + def new + @motorista_pre = User.motorista.ativos.find_by(id: session[:motorista_qr_id]) + end # POST /motorista/login — valida PIN def create pin = params[:pin].to_s.strip user = User.motorista.ativos.find_by(pin_code: pin) - if pin.length == 4 && user - sign_in(user) - session[:mostrar_splash] = true - AuditoriaLog.registrar(user: user, acao: :login, entidade: 'User', - entidade_id: user.id, request: request) - redirect_to motorista_dashboard_path, notice: "Bem-vindo, #{user.nome.split.first}!" - else + unless pin.length == 4 && user + @motorista_pre = User.motorista.ativos.find_by(id: session[:motorista_qr_id]) flash.now[:alert] = 'PIN não encontrado. Confira os 4 números e tente de novo.' - render :new, status: :unprocessable_entity + return render :new, status: :unprocessable_entity end + + # Segurança: se o login partiu de um QR Code, o PIN precisa ser do MESMO + # motorista do QR — impede usar o QR Code de outra pessoa. + qr_id = session[:motorista_qr_id] + if qr_id.present? && qr_id != user.id + @motorista_pre = User.motorista.ativos.find_by(id: qr_id) + flash.now[:alert] = 'Este PIN não corresponde ao QR Code lido. Use o seu PIN.' + return render :new, status: :unprocessable_entity + end + + session.delete(:motorista_qr_id) + sign_in(user) + session[:mostrar_splash] = true + AuditoriaLog.registrar(user: user, acao: :login, entidade: 'User', + entidade_id: user.id, + dados_novos: (qr_id.present? ? { via: 'qr_code+pin' } : nil), + request: request) + redirect_to motorista_dashboard_path, notice: "Bem-vindo, #{user.nome.split.first}!" end - # GET /motorista/acesso/:token — login via QR Code do holerite + # GET /motorista/acesso/:token — abre o login a partir do QR Code do holerite. + # SEGURANÇA: o QR apenas identifica o motorista; ele ainda precisa digitar o + # PIN de 4 dígitos para entrar (antes o QR logava direto, sem PIN). def acesso_qr user = User.motorista.ativos.find_by(login_token: params[:token]) if user - sign_in(user) - session[:mostrar_splash] = true - AuditoriaLog.registrar(user: user, acao: :login, entidade: 'User', - entidade_id: user.id, dados_novos: { via: 'qr_code' }, request: request) - redirect_to motorista_dashboard_path, notice: "Bem-vindo, #{user.nome.split.first}!" + session[:motorista_qr_id] = user.id + redirect_to motorista_login_path, + notice: "Olá, #{user.nome.split.first}! Digite seu PIN de 4 dígitos para entrar." else + session.delete(:motorista_qr_id) redirect_to motorista_login_path, alert: 'QR Code inválido ou expirado. Entre com seu PIN.' end end diff --git a/app/views/motorista/dashboard/index.html.erb b/app/views/motorista/dashboard/index.html.erb index 094ac9c..8773c02 100644 --- a/app/views/motorista/dashboard/index.html.erb +++ b/app/views/motorista/dashboard/index.html.erb @@ -33,7 +33,7 @@ <%# Card 1 — Valor Estimado (LARANJA) %>

💰 Valor estimado deste mês

-

<%= moeda(@valor_estimado) %>

+

<%= moeda(@valor_estimado) %>

<%= @entregas_mes %> entregas feitas e confirmadas

@@ -45,7 +45,7 @@ <%# Card 2 — Valor Consolidado (BRANCO) %>

✅ Valor fechado para pagamento

-

<%= moeda(@valor_consolidado) %>

+

<%= moeda(@valor_consolidado) %>

Soma dos pagamentos já confirmados pela empresa

@@ -72,7 +72,7 @@

📅 <%= l c.data_inicio, format: :short %> a <%= l c.data_fim, format: :short %>

-

<%= moeda(cm&.valor_total || 0) %>

+

<%= moeda(cm&.valor_total || 0) %>

<% if cm&.pago? %>

💰 Pago em <%= l cm.pago_em.to_date, format: :short %> diff --git a/app/views/motorista/sessoes/new.html.erb b/app/views/motorista/sessoes/new.html.erb index d7be7bc..68f8c2b 100644 --- a/app/views/motorista/sessoes/new.html.erb +++ b/app/views/motorista/sessoes/new.html.erb @@ -8,7 +8,12 @@

G

Reem Logística

-

Digite seu PIN de 4 números

+ <% if @motorista_pre %> +

Olá, <%= @motorista_pre.nome.split.first %>!

+

Confirme com seu PIN de 4 números

+ <% else %> +

Digite seu PIN de 4 números

+ <% end %>
<%= form_with url: motorista_login_path, method: :post, id: 'form-pin' do |f| %>