Skip to content

Commit 801fe45

Browse files
Merge pull request #62 from RandomProgramm3r/develop
refactor(user, validators): extract PromoActivationService & simplify password validators This commit consolidates and improves core user-related logic by: - Extracting promo code activation functionality from `PromoActivateView` into a new `PromoActivationService` in `user/services.py`, which now handles: - User targeting (age, country) checks - Promo active status verification - Anti‑fraud validation - Atomic issuance for common and unique promo codes - Granular exceptions (`PromoActivationError`, `TargetingError`, etc.) for clearer API error responses - Simplifying password validation by: - Removing the `BaseCountPasswordValidator` abstract class in favor of standalone validators - Renaming classes for brevity (e.g. `AsciiValidator`, `UppercaseValidator`) - Leveraging built‑in methods like `isascii()` and `isupper()` for clarity and performance - Using `ngettext` to enhance internationalized, pluralized error messages - Updating `settings.py` to reference new validator names and options Both the view and validator integrations have been streamlined for maintainability and adherence to Django conventions.
2 parents 0f1ac9d + 2b936fa commit 801fe45

File tree

4 files changed

+315
-311
lines changed

4 files changed

+315
-311
lines changed

promo_code/promo_code/settings.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,23 @@ def load_bool(name, default):
178178
'.NumericPasswordValidator',
179179
},
180180
{
181-
'NAME': 'promo_code.validators.ASCIIOnlyPasswordValidator',
181+
'NAME': 'promo_code.validators.AsciiValidator',
182182
},
183183
{
184-
'NAME': 'promo_code.validators.SpecialCharacterPasswordValidator',
185-
'OPTIONS': {'min_count': 1},
184+
'NAME': 'promo_code.validators.SpecialCharacterValidator',
185+
'OPTIONS': {'special_chars': '[@$!%*?&]'},
186186
},
187187
{
188-
'NAME': 'promo_code.validators.NumericPasswordValidator',
189-
'OPTIONS': {'min_count': 1},
188+
'NAME': 'promo_code.validators.NumericValidator',
190189
},
191190
{
192-
'NAME': 'promo_code.validators.LowercaseLatinLetterPasswordValidator',
193-
'OPTIONS': {'min_count': 1},
191+
'NAME': 'promo_code.validators.LowercaseValidator',
194192
},
195193
{
196-
'NAME': 'promo_code.validators.UppercaseLatinLetterPasswordValidator',
197-
'OPTIONS': {'min_count': 1},
194+
'NAME': 'promo_code.validators.UppercaseValidator',
198195
},
199196
]
200197

201-
202198
PASSWORD_HASHERS = [
203199
'django.contrib.auth.hashers.Argon2PasswordHasher',
204200
'django.contrib.auth.hashers.PBKDF2PasswordHasher',

0 commit comments

Comments
 (0)