Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Database Configuration
DB_URL=postgres
# Shared Database Configuration
DB_URL=localhost
DB_PORT=5432
DB_NAME=authdb
DB_USER=resellio
DB_PASSWORD=localpassword
DB_NAME=resellio_db
DB_USER=root
DB_PASSWORD=my_password

# Auth Service JWT Configuration
SECRET_KEY=a-very-secret-key-for-local-development-change-me
# JWT & Security Configuration
SECRET_KEY=a-very-secure-secret-key-for-jwt-256-bit
ACCESS_TOKEN_EXPIRE_MINUTES=30
ADMIN_SECRET_KEY=local-admin-secret-key
INITIAL_ADMIN_EMAIL=admin@resellio.com
INITIAL_ADMIN_PASSWORD=AdminPassword123!
ADMIN_SECRET_KEY=change-in-production

# SendGrid Email Configuration
EMAIL_API_KEY="api-key-placeholder"
EMAIL_FROM_EMAIL="sender-email-placeholder"
# Email (SendGrid) Configuration
EMAIL_API_KEY=YOUR_SENDGRID_API_KEY
# The email address that will appear in the "From" field
EMAIL_FROM_EMAIL=noreply@resellio.com
# The base URL of the application, used for constructing verification links
# For local testing, this points to the API Gateway
APP_BASE_URL=http://localhost:8080
5 changes: 0 additions & 5 deletions backend/event_ticketing_service/.env.template

This file was deleted.

30 changes: 11 additions & 19 deletions backend/event_ticketing_service/app/services/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

SENDGRID_API_KEY = os.getenv("EMAIL_API_KEY")
FROM_EMAIL = os.getenv("EMAIL_FROM_EMAIL", "tickets@resellio.com")
APP_BASE_URL = os.getenv("APP_BASE_URL", "http://localhost:8080")

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -52,23 +53,16 @@ def send_ticket_email(
):
"""
Send beautifully designed ticket confirmation email using SendGrid.

Args:
to_email: Recipient's email address
user_name: Recipient's name
event_name: Name of the event
ticket_id: Ticket ID
event_date: Event date (formatted string)
event_time: Event time (formatted string)
venue: Venue name
seat: Seat number/code

Returns:
bool: True if email was sent successfully, False otherwise
"""
if not SENDGRID_API_KEY:
logger.error("SendGrid API key not set - cannot send emails")
return False
if not APP_BASE_URL:
logger.error("APP_BASE_URL not set - cannot construct email links")
# Fallback to a generic domain if not set, but log an error
base_url = "http://resellio.com"
Comment on lines +62 to +63
Copy link

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since APP_BASE_URL has a default non-empty value from os.getenv, this branch will never execute. If you intend to detect a missing environment variable, retrieve the raw environment lookup first, then apply a default only after the check.

Suggested change
# Fallback to a generic domain if not set, but log an error
base_url = "http://resellio.com"
# Apply default or fallback explicitly
base_url = "http://localhost:8080" # Default for development

Copilot uses AI. Check for mistakes.
else:
base_url = APP_BASE_URL.replace('/api', '') # Ensure we have the root URL
Copy link

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using a simple string replace may inadvertently strip valid parts of URLs. Consider using urllib.parse or a similar URL library to reliably construct the root URL.

Copilot uses AI. Check for mistakes.

# Generate QR code containing ticket info
qr_data = f"TICKET:{ticket_id}|EVENT:{event_name}|DATE:{event_date}|TIME:{event_time}|VENUE:{venue}|SEAT:{seat}"
Expand Down Expand Up @@ -208,20 +202,18 @@ def send_ticket_email(

<p>Please save this email and bring it with you to the event. You can also access your tickets anytime from your account.</p>

<p>We hope you enjoy the event!</p>

<div style="text-align: center;">
<a href="https://resellio.com/my-tickets" class="button">View My Tickets</a>
<a href="{base_url}/home/customer" class="button">View My Tickets</a>
</div>
</div>

<div class="footer">
<p>© 2025 Resellio. All rights reserved.</p>
<p>This is an automated message. Please do not reply to this email.</p>
<p>
<a href="https://resellio.com/terms">Terms of Service</a> |
<a href="https://resellio.com/privacy">Privacy Policy</a> |
<a href="https://resellio.com/contact">Contact Us</a>
<a href="{base_url}/terms">Terms of Service</a> |
<a href="{base_url}/privacy">Privacy Policy</a> |
<a href="{base_url}/contact">Contact Us</a>
</p>
</div>
</body>
Expand Down
9 changes: 0 additions & 9 deletions backend/user_auth_service/.env.template

This file was deleted.

2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ services:
- ADMIN_SECRET_KEY=${ADMIN_SECRET_KEY}
- EMAIL_API_KEY=${EMAIL_API_KEY}
- EMAIL_FROM_EMAIL=${EMAIL_FROM_EMAIL}
- APP_BASE_URL=${APP_BASE_URL}
depends_on:
db-init:
condition: service_completed_successfully
Expand All @@ -66,6 +67,7 @@ services:
- SECRET_KEY=${SECRET_KEY}
- EMAIL_API_KEY=${EMAIL_API_KEY}
- EMAIL_FROM_EMAIL=${EMAIL_FROM_EMAIL}
- APP_BASE_URL=${APP_BASE_URL}
depends_on:
db-init:
condition: service_completed_successfully
Expand Down
12 changes: 12 additions & 0 deletions terraform/main/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ resource "aws_secretsmanager_secret_version" "admin_secret_key" {
secret_string = random_string.admin_secret_key.result
}

resource "aws_secretsmanager_secret" "sendgrid_api_key" {
name = "${var.project_name}-sendgrid-api-key"
}

resource "aws_secretsmanager_secret_version" "sendgrid_api_key" {
secret_id = aws_secretsmanager_secret.sendgrid_api_key.id
secret_string = var.sendgrid_api_key
}


# Database
module "db" {
Expand Down Expand Up @@ -76,6 +85,9 @@ module "ecs_cluster" {
db_endpoint = module.db.endpoint
db_password_secret_arn = aws_secretsmanager_secret.db_master_password.arn
admin_secret_key_arn = aws_secretsmanager_secret.admin_secret_key.arn
sendgrid_api_key_arn = aws_secretsmanager_secret.sendgrid_api_key.arn
email_from_address = var.email_from_address
app_base_url = "http://${module.ecs_cluster.alb_dns_name}"
auth_image = "${data.aws_ecr_repository.auth.repository_url}:latest"
ticket_image = "${data.aws_ecr_repository.tickets.repository_url}:latest"
db_init_image = "${data.aws_ecr_repository.db_init.repository_url}:latest"
Expand Down
9 changes: 9 additions & 0 deletions terraform/main/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ variable "force_db_reset" {
description = "If true, forces the db-init task to wipe the public schema before initializing. Use with caution."
default = false
}
variable "sendgrid_api_key" {
type = string
description = "The SendGrid API key for sending emails."
sensitive = true
}
variable "email_from_address" {
type = string
description = "The email address to use as the sender."
}
17 changes: 12 additions & 5 deletions terraform/modules/ecs_cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ data "aws_iam_policy_document" "task_secrets_access" {
]
resources = [
var.db_password_secret_arn,
var.admin_secret_key_arn
var.admin_secret_key_arn,
var.sendgrid_api_key_arn
]
}
}
Expand Down Expand Up @@ -199,11 +200,14 @@ resource "aws_ecs_task_definition" "auth" {
{ name = "DB_USER", value = var.db_user },
{ name = "DB_NAME", value = var.db_name },
{ name = "DB_PORT", value = tostring(var.db_port) },
{ name = "AWS_REGION", value = var.aws_region }
{ name = "AWS_REGION", value = var.aws_region },
{ name = "EMAIL_FROM_EMAIL", value = var.email_from_address },
{ name = "APP_BASE_URL", value = var.app_base_url }
]
secrets = [
{ name = "DB_PASSWORD", valueFrom = var.db_password_secret_arn },
{ name = "ADMIN_SECRET_KEY", valueFrom = var.admin_secret_key_arn }
{ name = "ADMIN_SECRET_KEY", valueFrom = var.admin_secret_key_arn },
{ name = "EMAIL_API_KEY", valueFrom = var.sendgrid_api_key_arn }
]
logConfiguration = {
logDriver = "awslogs"
Expand Down Expand Up @@ -241,10 +245,13 @@ resource "aws_ecs_task_definition" "tickets" {
{ name = "DB_USER", value = var.db_user },
{ name = "DB_NAME", value = var.db_name },
{ name = "DB_PORT", value = tostring(var.db_port) },
{ name = "AWS_REGION", value = var.aws_region }
{ name = "AWS_REGION", value = var.aws_region },
{ name = "EMAIL_FROM_EMAIL", value = var.email_from_address },
{ name = "APP_BASE_URL", value = var.app_base_url }
]
secrets = [
{ name = "DB_PASSWORD", valueFrom = var.db_password_secret_arn }
{ name = "DB_PASSWORD", valueFrom = var.db_password_secret_arn },
{ name = "EMAIL_API_KEY", valueFrom = var.sendgrid_api_key_arn }
]
logConfiguration = {
logDriver = "awslogs"
Expand Down
12 changes: 12 additions & 0 deletions terraform/modules/ecs_cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ variable "admin_secret_key_arn" {
type = string
description = "ARN for the admin secret key"
}
variable "sendgrid_api_key_arn" {
type = string
description = "ARN for the SendGrid API key secret"
}
variable "email_from_address" {
type = string
description = "The email address to use as the sender"
}
variable "app_base_url" {
type = string
description = "The base URL of the application, for constructing links in emails"
}
variable "db_user" { type = string }
variable "db_name" { type = string }
variable "db_port" {
Expand Down