feat: implement password reset for shop customers
Add complete password reset functionality: Database: - Add password_reset_tokens migration with token hash, expiry, used_at - Create PasswordResetToken model with secure token hashing (SHA256) - One active token per customer (old tokens invalidated on new request) - 1-hour token expiry for security API: - Implement forgot_password endpoint with email lookup - Implement reset_password endpoint with token validation - No email enumeration (same response for all requests) - Password minimum 8 characters validation Frontend: - Add reset-password.html template with Alpine.js - Support for invalid/expired token states - Success state with login redirect - Dark mode support Email: - Add password_reset email templates (en, fr, de, lb) - Uses existing EmailService with template rendering Testing: - Add comprehensive pytest tests (19 tests) - Test token creation, validation, expiry, reuse prevention - Test endpoint success and error cases Removes critical launch blocker for password reset functionality. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
53
alembic/versions/t8b9c0d1e2f3_add_password_reset_tokens.py
Normal file
53
alembic/versions/t8b9c0d1e2f3_add_password_reset_tokens.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""add password_reset_tokens table
|
||||
|
||||
Revision ID: t8b9c0d1e2f3
|
||||
Revises: s7a8b9c0d1e2
|
||||
Create Date: 2026-01-03
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "t8b9c0d1e2f3"
|
||||
down_revision = "s7a8b9c0d1e2"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"password_reset_tokens",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("customer_id", sa.Integer(), nullable=False),
|
||||
sa.Column("token_hash", sa.String(64), nullable=False),
|
||||
sa.Column("expires_at", sa.DateTime(), nullable=False),
|
||||
sa.Column("used_at", sa.DateTime(), nullable=True),
|
||||
sa.Column(
|
||||
"created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["customer_id"],
|
||||
["customers.id"],
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_password_reset_tokens_customer_id",
|
||||
"password_reset_tokens",
|
||||
["customer_id"],
|
||||
)
|
||||
op.create_index(
|
||||
"ix_password_reset_tokens_token_hash",
|
||||
"password_reset_tokens",
|
||||
["token_hash"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_password_reset_tokens_token_hash", table_name="password_reset_tokens")
|
||||
op.drop_index("ix_password_reset_tokens_customer_id", table_name="password_reset_tokens")
|
||||
op.drop_table("password_reset_tokens")
|
||||
Reference in New Issue
Block a user