Skip to content

Customer accounts: register, profile, update, deactivate (#51, #53) - #70

Merged
CookieLynx merged 9 commits into
mainfrom
feature/51-customer-accounts
Nov 18, 2026
Merged

CookieLynx merged 9 commits into
mainfrom
feature/51-customer-accounts

Conversation

@sonoftirit

@sonoftirit sonoftirit commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Customer accounts for M2. Closes #49, closes #51 (except Token), part of #53 (login is in the auth PR).

  • POST /customers registers a customer, 409 if the email is taken
  • GET /customers/me gets my info
  • PATCH /customers/me updates name, email, phone or address
  • DELETE /customers/me deactivates the account (sets isActive to false, doesn't delete it)
  • passwords are hashed with argon2 (pwdlib) and the hash is never returned
  • emails are saved in lowercase
  • @CookieLynx get_current_customer in core/dependencies.py just returns 401 for now so /me is locked until login is in, you can use get_active_customer() and verify_password() for it
  • roles are customer/owner/admin for now, we still need to decide this
  • added a lock so two sign-ups at the same time don't overwrite each other
  • tests for the models, service and endpoints plus a regression test for parallel sign-ups, all 168 pass

Customer is what gets stored (with the password hash), CustomerResponse is
what the API returns (no hash). CustomerCreate/CustomerUpdate validate input,
lowercase emails and keep passwords exactly as typed.
Register (hashes the password with argon2 via pwdlib, rejects a used email),
get, update info/address and deactivate (soft delete, isActive=false).
get_active_customer is for the auth dependency and cart/checkout to use.
POST /customers, and GET/PATCH/DELETE /customers/me. The /me routes use
get_current_customer, which rejects everything with 401 until the JWT login
is merged. Tests fake a signed-in customer with dependency_overrides.

Added customers.json to test-data, sample-data and the conftest file list.
Two registrations at the same time could both pass the email check and the
second save would drop the first customer. Register/update/deactivate now
hold the file lock around load -> change -> save, and the password is hashed
before taking it. Also rejects passwords that are only spaces.
@sonoftirit

Copy link
Copy Markdown
Collaborator Author

separate the json file for customer tests!

@CookieLynx CookieLynx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looking good!

All tests pass, and using the endpoints you can do all of the current customer actions (creating account, deleting account, modifiying).

Passwords and emails are validated to be in the correct format (I know I mentioned this during out meeting that it was not but I was mistaken)

Hashing looks like a good start for the auth I'm working on!

All requirements from M2 are covered for accounts!

One thing I would consider adding is a test for a passwords beyond 128 characters, the current testing for spaces and too-short passwords works great but is missing this edgecase! Otherwise the data is correctly copied from our production data files to temp copied ones during testing for customers.json as well!

Overall looking great! I approve, I'll keep open for now in case anyone else has other changes they want!

From Nathan's review: 128 characters is accepted, 129 is rejected.
@sonoftirit

Copy link
Copy Markdown
Collaborator Author

thanks! added the test for passwords over 128 chars (and one for exactly 128 so the limit is checked both ways). also merged main in since #69 is merged now

@sonoftirit sonoftirit mentioned this pull request Nov 18, 2026
- get_customer and get_active_customer did the same lookup, kept one
- shorter comments, removed a duplicate import and a duplicate test
Added an ErrorResponse model so 401/409 show their body in /docs, and a
description for GET /customers/me.
- role and password tests now send a valid field too, so the 422 really
  comes from the forbidden field
- added repository tests for lookups by id/email and stable ids
- removed a lower() in the service that never did anything (emails are
  already lowercased by the request model)
@CookieLynx

Copy link
Copy Markdown
Collaborator

New changes to error handling on routes looks good for purposefully thrown errors! New tests all look good! Merging!

@CookieLynx
CookieLynx merged commit 0d442f5 into main Nov 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TASK] Define Pydantic models for Customers [USER STORY] Customer Registration & Profile Management

2 participants