fix bug sms

This commit is contained in:
javad committed 2026-10-09 10:32:27 +03:30
1 parent 48d0ecba79
commit ae4dbab3cc
5 files changed
+93 -13

No files matched your search

+10 -3
View File
@@ -94,11 +94,18 @@ def login_by_mobile(mobile: int):
from math import ceil
raise SmsRequestThrottled(ceil(remaining))
code = secrets.randbelow(900000) + 100000
if not DefaultSmsProvider().send_sms(str(user.mobile), f'کد ورود شما: {code}'):
delivery = DefaultSmsProvider().send_sms(str(user.mobile), f'کد ورود شما: {code}')
if delivery is False:
raise SmsDeliveryUnavailable()
SmsOpt.objects.filter(mobile=user.mobile).delete()
if delivery is True:
SmsOpt.objects.filter(mobile=user.mobile).delete()
else:
# Keep any previous unexpired code too: either SMS may have arrived.
SmsOpt.objects.filter(mobile=user.mobile, expire__lte=timezone.now()).delete()
SmsOpt.objects.create(mobile=user.mobile, opt=code, expire=timezone.now() + timedelta(minutes=3))
return user.mobile
return {'mobile': user.mobile, 'delivery_status': 'accepted' if delivery is True else 'unconfirmed',
'message': 'opt code send' if delivery is True else 'وضعیت ارسال پیامک تأیید نشد. اگر کد را دریافت کرده‌اید، آن را وارد کنید.',
'retry_after': SMS_RESEND_INTERVAL}
@transaction.atomic