add test number

This commit is contained in:
Sayyid Hamid Mahdavi 2026-02-23 11:31:38 +03:30
parent ba858baa85
commit b8a57a0ce4
3 changed files with 26 additions and 14 deletions

View file

@ -11,7 +11,7 @@ https://docs.djangoproject.com/en/5.0/ref/settings/
""" """
from pathlib import Path from pathlib import Path
from decouple import config from decouple import config, Csv
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -274,7 +274,12 @@ PAYAM_SMS_USERNAME = config('PAYAM_SMS_USERNAME')
PAYAM_SMS_PASSWORD = config('PAYAM_SMS_PASSWORD') PAYAM_SMS_PASSWORD = config('PAYAM_SMS_PASSWORD')
PAYAM_SMS_CLIENT_ID = config('PAYAM_SMS_CLIENT_ID') PAYAM_SMS_CLIENT_ID = config('PAYAM_SMS_CLIENT_ID')
PAYAM_SMS_CLIENT_SECRET = config('PAYAM_SMS_CLIENT_SECRET') PAYAM_SMS_CLIENT_SECRET = config('PAYAM_SMS_CLIENT_SECRET')
SMS_OTP_SIGNITURE = config('SMS_OTP_SIGNITURE', '') SMS_OTP_SIGNITURE = config('SMS_OTP_SIGNITURE', '')
SMS_SEND=config('SMS_SEND', True, cast=bool)
TEST_PHONENUMBERS=config('TEST_PHONENUMBERS', [], cast=Csv(post_process=list))
CACHES = { CACHES = {
"default": { "default": {
@ -352,7 +357,6 @@ STORAGES = {
], ],
"MINIO_POLICY_HOOKS": [], "MINIO_POLICY_HOOKS": [],
"MINIO_BUCKET_CHECK_ON_SAVE": True # Default: True // Creates bucket if missing, then save "MINIO_BUCKET_CHECK_ON_SAVE": True # Default: True // Creates bucket if missing, then save
}, },
}, },
"staticfiles": { "staticfiles": {

View file

@ -1,3 +1,4 @@
import logging
import random import random
import string import string
from datetime import timedelta from datetime import timedelta
@ -22,6 +23,8 @@ from .provinces_and_cities import state
from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS, GenderChoices, EducationDegreeChoices, \ from apps.users.constans import MAX_OTP_TRY, DEVELOPMENT_PHONE_NUMBERS, GenderChoices, EducationDegreeChoices, \
MAX_OTP_VALID_DURATION MAX_OTP_VALID_DURATION
logger = logging.getLogger(__name__)
class UserManager(BaseUserManager): class UserManager(BaseUserManager):
use_in_migrations = True use_in_migrations = True
@ -161,7 +164,9 @@ class User(AbstractUser):
if self.otp_expire and (self.otp_expire + timedelta(seconds=MAX_OTP_VALID_DURATION)) > timezone.now(): if self.otp_expire and (self.otp_expire + timedelta(seconds=MAX_OTP_VALID_DURATION)) > timezone.now():
raise Exception(_('otp expire time not reached.')) raise Exception(_('otp expire time not reached.'))
if self.phone_number == '+989965419352': if not settings.SMS_SEND:
self._otp = '77501'
elif self.phone_number in settings.TEST_PHONENUMBERS:
self._otp = '88555' self._otp = '88555'
else: else:
self._otp = ''.join(random.choice('0123456789') for _ in range(5)) self._otp = ''.join(random.choice('0123456789') for _ in range(5))
@ -245,7 +250,10 @@ class User(AbstractUser):
# # f"code is: {body}\n" # # f"code is: {body}\n"
# f"{settings.SMS_OTP_SIGNITURE}" # f"{settings.SMS_OTP_SIGNITURE}"
) )
send_sms(self.phone_number.strip('+'), message) if settings.SMS_SEND:
send_sms(self.phone_number.strip('+'), message)
else:
logger.info(f'otp for: {self.phone_number} is {message}')
return return
# TODO: enable celery # TODO: enable celery
send_notification( send_notification(

View file

@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.13 # This file is autogenerated by pip-compile with Python 3.13
# by the following command: # by the following command:
# #
# pip-compile --cert=None --client-cert=None --index-url=None --pip-args=None # pip-compile
# #
amqp==5.3.1 amqp==5.3.1
# via kombu # via kombu
@ -58,7 +58,7 @@ constantly==23.10.4
# via twisted # via twisted
crispy-bootstrap5==2025.6 crispy-bootstrap5==2025.6
# via -r requirements.in # via -r requirements.in
cryptography==46.0.4 cryptography==46.0.5
# via # via
# autobahn # autobahn
# jwcrypto # jwcrypto
@ -80,7 +80,7 @@ django==6.0.2
# django-redis # django-redis
# djangorestframework # djangorestframework
# drf-spectacular # drf-spectacular
django-betterforms==2.0.0 django-betterforms==3.0.0
# via -r requirements.in # via -r requirements.in
django-cors-headers==4.9.0 django-cors-headers==4.9.0
# via -r requirements.in # via -r requirements.in
@ -106,9 +106,9 @@ drf-spectacular==0.29.0
# via -r requirements.in # via -r requirements.in
gevent==25.9.1 gevent==25.9.1
# via -r requirements.in # via -r requirements.in
greenlet==3.3.1 greenlet==3.3.2
# via gevent # via gevent
gunicorn==25.0.2 gunicorn==25.1.0
# via -r requirements.in # via -r requirements.in
h2==4.3.0 h2==4.3.0
# via twisted # via twisted
@ -141,7 +141,7 @@ jwcrypto==1.5.6
# via django-oauth-toolkit # via django-oauth-toolkit
kombu==5.6.2 kombu==5.6.2
# via celery # via celery
markdown==3.10.1 markdown==3.10.2
# via -r requirements.in # via -r requirements.in
minio==7.2.20 minio==7.2.20
# via django-minio-backend # via django-minio-backend
@ -155,7 +155,7 @@ packaging==25.0
# gunicorn # gunicorn
# incremental # incremental
# kombu # kombu
pillow==12.1.0 pillow==12.1.1
# via # via
# -r requirements.in # -r requirements.in
# django-minio-backend # django-minio-backend
@ -163,9 +163,9 @@ priority==1.3.0
# via twisted # via twisted
prompt-toolkit==3.0.52 prompt-toolkit==3.0.52
# via click-repl # via click-repl
psycopg[binary,pool]==3.3.2 psycopg[binary,pool]==3.3.3
# via -r requirements.in # via -r requirements.in
psycopg-binary==3.3.2 psycopg-binary==3.3.3
# via psycopg # via psycopg
psycopg-pool==3.3.0 psycopg-pool==3.3.0
# via psycopg # via psycopg
@ -189,7 +189,7 @@ python-decouple==3.8
# via -r requirements.in # via -r requirements.in
pyyaml==6.0.3 pyyaml==6.0.3
# via drf-spectacular # via drf-spectacular
redis==7.1.0 redis==7.2.0
# via # via
# -r requirements.in # -r requirements.in
# django-redis # django-redis