accounts: me va login apilar togirlandi, create_user command qoshildi
This commit is contained in:
0
core/apps/accounts/management/__init__.py
Normal file
0
core/apps/accounts/management/__init__.py
Normal file
0
core/apps/accounts/management/commands/__init__.py
Normal file
0
core/apps/accounts/management/commands/__init__.py
Normal file
52
core/apps/accounts/management/commands/createuser.py
Normal file
52
core/apps/accounts/management/commands/createuser.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# python
|
||||
from getpass import getpass
|
||||
|
||||
# django
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
# django tenants
|
||||
from django_tenants.utils import schema_context
|
||||
|
||||
|
||||
# accounts
|
||||
from core.apps.accounts.models import User
|
||||
|
||||
# customers
|
||||
from core.apps.customers.models import Client
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
client = None
|
||||
username = None
|
||||
|
||||
while True:
|
||||
schema_name = input("Schema nomini kiriting: ")
|
||||
client = Client.objects.filter(schema_name=schema_name).first()
|
||||
if not client:
|
||||
self.stdout.write("Schema topilmadi")
|
||||
else: break
|
||||
|
||||
with schema_context(schema_name):
|
||||
while True:
|
||||
username = input("username kiriting: ")
|
||||
user = User.objects.filter(username=username).first()
|
||||
if user:
|
||||
self.stdout.write("Foydalanuvchi bu username bilan mavjud")
|
||||
else:
|
||||
break
|
||||
|
||||
first_name = input("Ism kiriting: ")
|
||||
last_name = input("Familiya kiriting: ")
|
||||
phone_number = input("Telefon raqam kiriting: ")
|
||||
password = getpass("Parol kiriting: ")
|
||||
|
||||
User.objects.create_superuser(
|
||||
username=username,
|
||||
first_name=first_name,
|
||||
last_name=last_name,
|
||||
password=password,
|
||||
phone_number=phone_number,
|
||||
)
|
||||
|
||||
self.stdout.write("Foydalanuvchi qo'shildi")
|
||||
@@ -1,5 +1,5 @@
|
||||
# rest framework
|
||||
from rest_framework import viewsets
|
||||
from rest_framework import viewsets, permissions
|
||||
from rest_framework.decorators import action
|
||||
|
||||
# drf yasg
|
||||
@@ -13,12 +13,11 @@ from core.apps.accounts.serializers.user import user as serializers
|
||||
|
||||
# utils
|
||||
from core.utils.response.mixin import ResponseMixin
|
||||
from core.utils.permissions.tenant_user import IsTenantUser
|
||||
|
||||
|
||||
class UserViewSet(viewsets.GenericViewSet, ResponseMixin):
|
||||
queryset = User.objects.all()
|
||||
permission_classes = [IsTenantUser]
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
def get_serializer_class(self):
|
||||
match self.action:
|
||||
@@ -28,7 +27,34 @@ class UserViewSet(viewsets.GenericViewSet, ResponseMixin):
|
||||
return
|
||||
case _:
|
||||
return serializers.UserSerializer
|
||||
|
||||
|
||||
@swagger_auto_schema(
|
||||
tags=['User'],
|
||||
operation_description="User malumotlarini olish uchun api",
|
||||
responses={
|
||||
200: openapi.Response(
|
||||
description="Success",
|
||||
schema=None,
|
||||
examples={
|
||||
"application/json": {
|
||||
"status_code": 200,
|
||||
"status": "success",
|
||||
"message": "User ma'lumotlari",
|
||||
"data": {
|
||||
"id": 0,
|
||||
"first_name": "string",
|
||||
"last_name": "string",
|
||||
"username": "string",
|
||||
"phone_number": "+998951234567",
|
||||
"profile_image": None or "string",
|
||||
"created_at": "string",
|
||||
"updated_at": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
@action(
|
||||
methods=["GET"], url_name="me", url_path="me", detail=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user