Login va Register to'girlandi

This commit is contained in:
2025-11-21 16:33:11 +05:00
parent 256e80cc23
commit 3da10c2a7f
9 changed files with 94 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
from datetime import datetime
from core.services import sms
from django.contrib.auth import get_user_model, hashers
from django.contrib.auth import get_user_model
from django.utils.translation import gettext as _
from django_core import exceptions
from rest_framework.exceptions import PermissionDenied
@@ -17,20 +17,19 @@ class UserService(sms.SmsService):
"access": str(refresh.access_token),
}
def create_user(self, phone, first_name, last_name, password):
get_user_model().objects.update_or_create(
def create_user(self, phone):
user, created = get_user_model().objects.update_or_create(
phone=phone,
defaults={
"phone": phone,
"first_name": first_name,
"last_name": last_name,
"password": hashers.make_password(password),
},
)
user.set_unusable_password()
user.save()
def send_confirmation(self, phone) -> bool:
try:
self.send_confirm(phone)
sms.SmsService.send_confirm(phone)
return True
except exceptions.SmsException as e:
raise PermissionDenied(_("Qayta sms yuborish uchun kuting: {}").format(e.kwargs.get("expired")))