feat: Display ticket based on `qr_code` field
- Previously ticket was displayed using id which is too easy to find - Now the URL takes ``qr_code`` field as parameters
This commit is contained in:
@@ -48,11 +48,10 @@ class TicketsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Display informations about the event with QR code
|
||||||
def show
|
def show
|
||||||
@ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user).find_by(
|
@ticket = Ticket.joins(order: :user).includes(:event, :ticket_type, order: :user)
|
||||||
tickets: { id: params[:ticket_id] },
|
.find_by(tickets: { qr_code: params[:qr_code] })
|
||||||
orders: { user_id: current_user.id }
|
|
||||||
)
|
|
||||||
|
|
||||||
if @ticket.nil?
|
if @ticket.nil?
|
||||||
redirect_to dashboard_path, alert: "Billet non trouvé"
|
redirect_to dashboard_path, alert: "Billet non trouvé"
|
||||||
@@ -63,6 +62,7 @@ class TicketsController < ApplicationController
|
|||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
redirect_to dashboard_path, alert: "Billet non trouvé"
|
redirect_to dashboard_path, alert: "Billet non trouvé"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_event
|
def set_event
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ class Ticket < ApplicationRecord
|
|||||||
self.qr_code = "#{id || 'temp'}-#{Time.current.to_i}-#{SecureRandom.hex(4)}"
|
self.qr_code = "#{id || 'temp'}-#{Time.current.to_i}-#{SecureRandom.hex(4)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def draft?
|
def draft?
|
||||||
status == "draft"
|
status == "draft"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -131,9 +131,7 @@
|
|||||||
<label class="block text-sm font-medium text-gray-500 mb-1">QR Code</label>
|
<label class="block text-sm font-medium text-gray-500 mb-1">QR Code</label>
|
||||||
<div class="bg-gray-50 rounded-lg p-4 text-center">
|
<div class="bg-gray-50 rounded-lg p-4 text-center">
|
||||||
<div class="inline-block bg-white p-4 rounded-lg shadow-sm">
|
<div class="inline-block bg-white p-4 rounded-lg shadow-sm">
|
||||||
<div data-controller="qr-code"
|
<div data-controller="qr-code" data-qr-code-data-value="<%= @ticket.qr_code %>" class="w-32 h-32">
|
||||||
data-qr-code-data-value="<%= @ticket.qr_code %>"
|
|
||||||
class="w-32 h-32">
|
|
||||||
<!-- Loading indicator -->
|
<!-- Loading indicator -->
|
||||||
<div data-qr-code-target="loading" class="w-32 h-32 bg-gray-100 rounded flex items-center justify-center">
|
<div data-qr-code-target="loading" class="w-32 h-32 bg-gray-100 rounded flex items-center justify-center">
|
||||||
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-purple-600"></div>
|
<div class="animate-spin rounded-full h-8 w-8 border-b-2 border-purple-600"></div>
|
||||||
@@ -161,7 +159,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @ticket.status == 'active' %>
|
<% if @ticket.status == 'active' %>
|
||||||
<%= link_to "#",
|
<%= link_to ticket_download_path(@ticket.qr_code),
|
||||||
class: "flex-1 bg-gradient-to-r from-purple-600 to-indigo-600 hover:from-purple-700 hover:to-indigo-700 text-white font-medium py-3 px-6 rounded-xl shadow-sm transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 transform hover:-translate-y-0.5 text-center" do %>
|
class: "flex-1 bg-gradient-to-r from-purple-600 to-indigo-600 hover:from-purple-700 hover:to-indigo-700 text-white font-medium py-3 px-6 rounded-xl shadow-sm transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:ring-offset-2 transform hover:-translate-y-0.5 text-center" do %>
|
||||||
<svg class="w-4 h-4 inline-block mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="w-4 h-4 inline-block mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ Rails.application.routes.draw do
|
|||||||
get "payments/cancel", to: "tickets#payment_cancel", as: "payment_cancel"
|
get "payments/cancel", to: "tickets#payment_cancel", as: "payment_cancel"
|
||||||
|
|
||||||
# === Tickets ===
|
# === Tickets ===
|
||||||
get "tickets/:ticket_id", to: "tickets#show", as: "ticket"
|
get "tickets/:qr_code", to: "tickets#show", as: "ticket"
|
||||||
get "tickets/:ticket_id/download", to: "events#download_ticket", as: "download_ticket"
|
get "tickets/:qr_code/download", to: "events#download_ticket", as: "ticket_download"
|
||||||
|
|
||||||
# === Promoter Routes ===
|
# === Promoter Routes ===
|
||||||
namespace :promoter do
|
namespace :promoter do
|
||||||
|
|||||||
Reference in New Issue
Block a user