mirror of
https://github.com/Dadechin/Dashboard-XRoom.git
synced 2025-07-05 17:54:33 +00:00
fix api with new login and getinfo api
This commit is contained in:
parent
c9331d490a
commit
371ac428ea
|
@ -187,10 +187,52 @@ def sendCodeAndNewPassword(request):
|
|||
|
||||
|
||||
|
||||
# @api_view(['POST'])
|
||||
# def login(request):
|
||||
# try:
|
||||
# customer = Customer.objects.get(mobile_number=request.data['mobile_number'])
|
||||
# except Customer.DoesNotExist:
|
||||
# return Response({
|
||||
# "status": 401,
|
||||
# "data": {},
|
||||
# "message": "موبایل یا پسورد غلط است"
|
||||
# }, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
# if not customer.user.check_password(request.data['password']):
|
||||
# return Response({
|
||||
# "status": 401,
|
||||
# "data": {},
|
||||
# "message": "موبایل یا پسورد غلط است"
|
||||
# }, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
# token, created = Token.objects.get_or_create(user=customer.user)
|
||||
# serializer = UserSerializer(customer.user)
|
||||
|
||||
# return Response({
|
||||
# "status": 200,
|
||||
# "data": {
|
||||
# "token": token.key,
|
||||
# "user": serializer.data
|
||||
# },
|
||||
# "message": "ورود با موفقیت انجام شد"
|
||||
# }, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
def login(request):
|
||||
mobile_number = request.data.get('mobile_number')
|
||||
password = request.data.get('password')
|
||||
|
||||
if not mobile_number or not password:
|
||||
return Response({
|
||||
"status": 403,
|
||||
"data": {},
|
||||
"message": "برای ورود نیاز به شماره موبایل و پسورد است"
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
try:
|
||||
customer = Customer.objects.get(mobile_number=request.data['mobile_number'])
|
||||
customer = Customer.objects.get(mobile_number=mobile_number)
|
||||
except Customer.DoesNotExist:
|
||||
return Response({
|
||||
"status": 401,
|
||||
|
@ -198,7 +240,7 @@ def login(request):
|
|||
"message": "موبایل یا پسورد غلط است"
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
if not customer.user.check_password(request.data['password']):
|
||||
if not customer.user.check_password(password):
|
||||
return Response({
|
||||
"status": 401,
|
||||
"data": {},
|
||||
|
@ -218,7 +260,6 @@ def login(request):
|
|||
}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@authentication_classes([SessionAuthentication, TokenAuthentication])
|
||||
@permission_classes([IsAuthenticated])
|
||||
|
|
|
@ -10,7 +10,14 @@ Content-Type: application/json
|
|||
POST http://127.0.0.1:8000/login
|
||||
Content-Type: application/json
|
||||
|
||||
{ "mobile_number":"09140086509", "password": "12345678" }
|
||||
{ "mobile_number":"09140086509", "password": "123456728" }
|
||||
|
||||
###
|
||||
|
||||
POST http://127.0.0.1:8000/login
|
||||
Content-Type: application/json
|
||||
|
||||
{ "password": "12345678" }
|
||||
|
||||
###
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user