Login va Register to'girlandi
This commit is contained in:
@@ -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")))
|
||||
|
||||
Reference in New Issue
Block a user