diff --git a/app/views/orders/index.html.erb b/app/views/orders/index.html.erb
index bc13008..0c92b52 100644
--- a/app/views/orders/index.html.erb
+++ b/app/views/orders/index.html.erb
@@ -1,6 +1,6 @@
@@ -73,14 +73,14 @@
- <%= link_to order_path(order),
+ <%= link_to order_path(order),
class: "inline-flex items-center px-3 py-2 bg-purple-600 hover:bg-purple-700 text-white text-sm font-medium rounded-lg transition-colors duration-200" do %>
Voir détails
<% end %>
-
+
@@ -92,7 +92,7 @@
- <%= ticket.first_name %> <%= ticket.last_name %>
- <%= link_to ticket_download_path(ticket.qr_code),
+ <%= link_to ticket_download_path(ticket.qr_code),
class: "text-purple-600 hover:text-purple-800 dark:text-purple-400 dark:hover:text-purple-200" do %>
<% end %>
@@ -128,4 +128,4 @@
<% end %>
<% end %>
-
\ No newline at end of file
+
diff --git a/docs/ticket-download-security.md b/docs/ticket-download-security.md
new file mode 100644
index 0000000..474dd3e
--- /dev/null
+++ b/docs/ticket-download-security.md
@@ -0,0 +1,275 @@
+# Ticket Download Security Implementation
+
+## Overview
+
+This document describes how to implement secure unique identifiers for ticket PDF downloads to enhance security and prevent unauthorized access to user tickets.
+
+## Problem Statement
+
+Currently, the ticket download functionality uses the QR code directly as an identifier in URLs. This approach presents several security risks:
+
+1. **Predictability**: QR codes may follow predictable patterns
+2. **Information Disclosure**: QR codes might reveal internal system information
+3. **Brute Force Vulnerability**: Attackers can enumerate valid tickets
+4. **Lack of Revocability**: Cannot invalidate download links without affecting the QR code
+
+## Solution
+
+Implement a separate, cryptographically secure unique identifier specifically for PDF downloads.
+
+## Implementation Steps
+
+### 1. Database Migration
+
+Create a migration to add the new column:
+
+```ruby
+# db/migrate/xxx_add_pdf_download_token_to_tickets.rb
+class AddPdfDownloadTokenToTickets < ActiveRecord::Migration[7.0]
+ def change
+ add_column :tickets, :pdf_download_token, :string, limit: 50
+ add_column :tickets, :pdf_download_token_expires_at, :datetime
+ add_index :tickets, :pdf_download_token, unique: true
+ end
+end
+```
+
+### 2. Model Implementation
+
+Update the Ticket model to generate secure tokens:
+
+```ruby
+# app/models/ticket.rb
+class Ticket < ApplicationRecord
+ before_create :generate_pdf_download_token
+
+ # Generate a secure token for PDF downloads
+ def generate_pdf_download_token
+ self.pdf_download_token = SecureRandom.urlsafe_base64(32)
+ self.pdf_download_token_expires_at = 24.hours.from_now
+ end
+
+ # Check if the download token is still valid
+ def pdf_download_token_valid?
+ pdf_download_token.present? &&
+ pdf_download_token_expires_at.present? &&
+ pdf_download_token_expires_at > Time.current
+ end
+
+ # Regenerate token (useful for security or when token expires)
+ def regenerate_pdf_download_token
+ generate_pdf_download_token
+ save!
+ end
+
+ # Ensure tokens are generated for existing records
+ def ensure_pdf_download_token
+ if pdf_download_token.blank?
+ generate_pdf_download_token
+ save!
+ end
+ end
+end
+```
+
+### 3. Controller Updates
+
+Update the TicketsController to use the new token system:
+
+```ruby
+# app/controllers/tickets_controller.rb
+class TicketsController < ApplicationController
+ before_action :authenticate_user!
+
+ def show
+ @ticket = Ticket.joins(order: :user)
+ .includes(:event, :ticket_type, order: :user)
+ .find_by(tickets: { qr_code: params[:qr_code] })
+
+ if @ticket.nil?
+ redirect_to dashboard_path, alert: "Billet non trouvé"
+ return
+ end
+
+ @event = @ticket.event
+ @order = @ticket.order
+ end
+
+ def download
+ # Find ticket by PDF download token instead of QR code
+ @ticket = Ticket.find_by(pdf_download_token: params[:pdf_download_token])
+
+ # Check if ticket exists
+ if @ticket.nil?
+ redirect_to dashboard_path, alert: "Lien de téléchargement invalide ou expiré"
+ return
+ end
+
+ # Verify token validity
+ unless @ticket.pdf_download_token_valid?
+ redirect_to dashboard_path, alert: "Le lien de téléchargement a expiré"
+ return
+ end
+
+ # Verify ownership
+ unless @ticket.order.user == current_user
+ redirect_to dashboard_path, alert: "Vous n'avez pas l'autorisation d'accéder à ce billet"
+ return
+ end
+
+ # Generate and send PDF
+ pdf_content = @ticket.to_pdf
+
+ # Optionally regenerate token to make it single-use
+ # @ticket.regenerate_pdf_download_token
+
+ send_data pdf_content,
+ filename: "ticket_#{@ticket.id}_#{@ticket.event.name.parameterize}.pdf",
+ type: "application/pdf",
+ disposition: "attachment"
+ rescue => e
+ Rails.logger.error "Error generating ticket PDF: #{e.message}"
+ redirect_to dashboard_path, alert: "Erreur lors de la génération du billet"
+ end
+end
+```
+
+### 4. Route Configuration
+
+Update routes to use the new token-based system:
+
+```ruby
+# config/routes.rb
+Rails.application.routes.draw do
+ # Existing routes...
+
+ # Update ticket download route
+ get "tickets/:pdf_download_token/download", to: "tickets#download", as: "ticket_download"
+
+ # Keep existing show route for QR code functionality
+ get "tickets/:qr_code", to: "tickets#show", as: "ticket"
+end
+```
+
+### 5. View Updates
+
+Update views to use the new download URL:
+
+```erb
+
+<%= link_to ticket_download_path(@ticket.pdf_download_token),
+ 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 %>
+