A wrong password or an unknown phone number was answered 900 (HTTP 500), like a server error, so clients could only tell them apart by the cause text. Both are now 304 (HTTP 400) from customer_auth_service with one cause, "invalid phone number or password", so a login does not tell which numbers have an account. A customer who never set a password gets 304 "customer not properly registered". Anything else stays 900. Login is limited per phone number: 5 attempts in 15 minutes, counted in Redis before the password is checked, so attempts sent at once all count, and for numbers without a customer too. The sixth is refused with 429 and data.locked_until, even with the right password, until the window ends. A successful login starts the count again. Since the number is normalized first, 0812… and 62812… count as one. When Redis fails, logins go on unlimited and the error is logged. There is no limit per IP: the client IP comes from X-Forwarded-For, which anyone can set while no trusted proxies are configured. Tested over HTTP with fakes; the Redis commands were checked against miniredis outside the repo, not against a real Redis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
4.2 KiB
Go
95 lines
4.2 KiB
Go
package constants
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
InternalServerErrorCode = "900"
|
|
MissingFieldErrorCode = "303"
|
|
MalformedFieldErrorCode = "310"
|
|
ValidationErrorCode = "304"
|
|
InvalidFieldErrorCode = "305"
|
|
NotFoundErrorCode = "404"
|
|
// PIN outcomes the customer app tells apart (docs/prd-point-coin.md §9).
|
|
PinNotSetErrorCode = "PIN_NOT_SET"
|
|
PinInvalidErrorCode = "PIN_INVALID"
|
|
PinLockedErrorCode = "PIN_LOCKED"
|
|
TransferBlockedErrorCode = "TRANSFER_BLOCKED"
|
|
TooManyRequestsErrorCode = "429"
|
|
)
|
|
|
|
const (
|
|
RequestEntity = "request"
|
|
UserServiceEntity = "user_service"
|
|
OrganizationServiceEntity = "organization_service"
|
|
CategoryServiceEntity = "category_service"
|
|
ProductServiceEntity = "product_service"
|
|
ProductVariantServiceEntity = "product_variant_service"
|
|
InventoryServiceEntity = "inventory_service"
|
|
OrderServiceEntity = "order_service"
|
|
CustomerServiceEntity = "customer_service"
|
|
UserValidatorEntity = "user_validator"
|
|
AuthHandlerEntity = "auth_handler"
|
|
UserHandlerEntity = "user_handler"
|
|
CategoryHandlerEntity = "category_handler"
|
|
ProductHandlerEntity = "product_handler"
|
|
ProductVariantHandlerEntity = "product_variant_handler"
|
|
InventoryHandlerEntity = "inventory_handler"
|
|
OrderValidatorEntity = "order_validator"
|
|
OrderHandlerEntity = "order_handler"
|
|
OrganizationValidatorEntity = "organization_validator"
|
|
OrgHandlerEntity = "organization_handler"
|
|
PaymentMethodValidatorEntity = "payment_method_validator"
|
|
PaymentMethodHandlerEntity = "payment_method_handler"
|
|
OutletServiceEntity = "outlet_service"
|
|
VendorServiceEntity = "vendor_service"
|
|
PurchaseOrderServiceEntity = "purchase_order_service"
|
|
PurchaseCategoryServiceEntity = "purchase_category_service"
|
|
IngredientUnitConverterServiceEntity = "ingredient_unit_converter_service"
|
|
IngredientCompositionServiceEntity = "ingredient_composition_service"
|
|
TableEntity = "table"
|
|
// Gamification entities
|
|
CustomerPointsEntity = "customer_points"
|
|
TierEntity = "tier"
|
|
OmsetTrackerEntity = "omset_tracker"
|
|
CampaignEntity = "campaign"
|
|
CampaignRuleEntity = "campaign_rule"
|
|
CustomerEntity = "customer"
|
|
UserDeviceServiceEntity = "user_device_service"
|
|
NotificationServiceEntity = "notification_service"
|
|
NotificationHandlerEntity = "notification_handler"
|
|
ProductOutletPriceServiceEntity = "product_outlet_price_service"
|
|
ExpenseServiceEntity = "expense_service"
|
|
CashAdvanceServiceEntity = "cash_advance_service"
|
|
WalletServiceEntity = "wallet_service"
|
|
EnakGameServiceEntity = "enakgame_service"
|
|
LoyaltySettingsServiceEntity = "loyalty_settings_service"
|
|
CustomerPinServiceEntity = "customer_pin_service"
|
|
CustomerAuthServiceEntity = "customer_auth_service"
|
|
)
|
|
|
|
var HttpErrorMap = map[string]int{
|
|
InternalServerErrorCode: http.StatusInternalServerError,
|
|
MissingFieldErrorCode: http.StatusBadRequest,
|
|
MalformedFieldErrorCode: http.StatusBadRequest,
|
|
ValidationErrorCode: http.StatusBadRequest,
|
|
InvalidFieldErrorCode: http.StatusBadRequest,
|
|
NotFoundErrorCode: http.StatusNotFound,
|
|
PinNotSetErrorCode: http.StatusForbidden,
|
|
PinInvalidErrorCode: http.StatusBadRequest,
|
|
PinLockedErrorCode: http.StatusLocked,
|
|
TransferBlockedErrorCode: http.StatusForbidden,
|
|
TooManyRequestsErrorCode: http.StatusTooManyRequests,
|
|
}
|
|
|
|
// Error messages
|
|
var (
|
|
ErrPaymentMethodNameRequired = fmt.Errorf("payment method name is required")
|
|
ErrPaymentMethodTypeRequired = fmt.Errorf("payment method type is required")
|
|
ErrInvalidPaymentMethodType = fmt.Errorf("invalid payment method type")
|
|
ErrInvalidPageNumber = fmt.Errorf("page number must be greater than 0")
|
|
ErrInvalidLimit = fmt.Errorf("limit must be between 1 and 100")
|
|
)
|