2.5 KiB
2.5 KiB
Accounts Context
Overview
Module: Aprsme.Accounts (lib/aprsme/accounts.ex)
Handles user registration, authentication, email confirmation, password reset, and session management.
Schemas
User (lib/aprsme/accounts/user.ex)
| Field | Type | Notes |
|---|---|---|
id |
binary_id | Primary key |
email |
citext | Case-insensitive, unique |
callsign |
string | Optional amateur radio callsign |
hashed_password |
string | Bcrypt-hashed |
confirmed_at |
utc_datetime | Email confirmation timestamp |
password |
virtual | Transient, used for changesets only |
UserToken (lib/aprsme/accounts/user_token.ex)
| Field | Type | Notes |
|---|---|---|
id |
binary_id | Primary key |
token |
binary | Bcrypt-hashed token |
context |
string | "session", "confirm", "reset_password", "change_email" |
sent_to |
string | Email or identifier |
user_id |
binary_id | FK → users.id |
Public API
Registration
register_user/1— Create user from registration paramschange_user_registration/2— Changeset for registration form
Authentication
get_user_by_email_and_password/2— Verify credentialsgenerate_user_session_token/1— Create session tokenget_user_by_session_token/1— Lookup user from tokendelete_user_session_token/1— Logout
Email Confirmation
deliver_user_confirmation_instructions/2— Send confirmation emailconfirm_user/1— Mark user as confirmed
Password Reset
deliver_user_reset_password_instructions/2— Send reset emailget_user_by_reset_password_token/1— Validate reset tokenreset_user_password/2— Update password
Account Settings
change_user_email/2,update_user_email/2— Email change flowchange_user_callsign/2,update_user_callsign/3— Callsign managementchange_user_password/2,update_user_password/3— Password change
Email Delivery
Uses Aprsme.Accounts.UserNotifier which delegates to Aprsme.Mailer (Swoosh with custom Resend adapter).
Web Integration
AprsmeWeb.UserAuthmodule provides plug-based and LiveViewon_mounthooks- Session stored in signed+encrypted cookie (
_aprs_key) - "Remember me" cookie (60-day expiry, signed)
- Token-based session with fixation prevention (renew on login/logout)
Notes
- No FK relationship between
users↔packets - Authentication is optional; most pages are publicly accessible without login
- Authenticated pages:
/users/settings,/dashboard(LiveDashboard),/errors(ErrorTracker)