Skip to main content

Command Palette

Search for a command to run...

Lifecycle Events System

Published
2 min read

Over the past week i have been focused on the user experience.

Specifically i implemented a lifecycle approach where various events trigger specific actions that are under our control. Actions are things like “Log The Event” or “Sent Email Template”

HerpesHearts includes a comprehensive lifecycle events system that automatically tracks user milestones, sends notifications, and maintains an audit log of important events.

Overview

The lifecycle events system provides:

  • Automatic UserAction logging for all lifecycle events

  • Configurable email notifications to users and/or staff

  • Extensible event handlers for custom business logic

  • Template-based email rendering with consistent branding

Available Lifecycle Events

Event NameTriggerNotification TargetEmail Template
first_loginUser logs in for first timeStafflifecycle_notification.html
profile_activatedUser makes profile visibleStafflifecycle_notification.html
profile_completedUser fills all required fieldsUserprofile_completed.html
profile_deletedUser deletes accountUser + Staffprofile_deleted_user.html, profile_deleted_staff.html
role_assignedAdmin assigns roleUser + Staffrole_assigned.html
badge_assignedAdmin assigns badgeUserbadge_assigned.html
first_message_sentUser sends first messageNone (disabled)first_message_sent.html
first_message_receivedUser receives first messageNone (disabled)-
first_like_sentUser sends first likeNone (disabled)first_like_sent.html
first_like_receivedUser receives first likeNone (disabled)-
first_profile_photoUser uploads first photoNone (disabled)first_profile_photo.html

Configuration

Lifecycle events are configured in src/profiles/lifecycle_events.py via the DEFAULT_LIFECYCLE_ACTIONS dictionary. You can override this in settings.py:

# In settings.py
LIFECYCLE_ACTIONS = {
    'first_login': [
        {
            'type': 'email_notification',
            'enabled': True,
            'notification_target': 'staff',  # 'staff', 'user', or 'both'
            'staff_email': 'support@herpeshearts.com',
            'subject': '[HerpesHearts] New User: {display_name}',
            'template_name': 'emails/lifecycle_notification.html',  # Optional
        }
    ],
    # ... more events
}

Notification Targets

Each event can notify:

  • staff - Sends to configured staff email (default: support@herpeshearts.com)

  • user - Sends to the user's email address

  • both - Sends to both staff and user

Template Variables

All email templates receive these standard variables:

  • display_name - User's profile display name

  • email - User's email address

  • user_id - User's database ID

  • timestamp - Event timestamp (formatted)

  • event_name - Name of the lifecycle event

  • SITE_NAME - Site name from settings

  • SITE_PURPOSE - Site purpose from settings

Event-specific variables (e.g., role_name, badge_name, badge_description) are passed based on the event context.