| Server IP : 65.108.144.40 / Your IP : 216.73.217.165 Web Server : Apache/2.4.52 (Ubuntu) System : Linux ubuntu-8gb-hel1-1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64 User : dev ( 1000) PHP Version : 8.2.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/erp/horilla_api/api_views/auth/ |
Upload File : |
from django.contrib.auth import authenticate
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_simplejwt.tokens import RefreshToken
from ...api_serializers.auth.serializers import GetEmployeeSerializer
class LoginAPIView(APIView):
def post(self, request):
if "username" and "password" in request.data.keys():
username = request.data.get("username")
password = request.data.get("password")
user = authenticate(username=username, password=password)
if user:
refresh = RefreshToken.for_user(user)
employee = user.employee_get
result = {
"employee": GetEmployeeSerializer(employee).data,
"access": str(refresh.access_token),
}
return Response(result, status=200)
else:
return Response({"error": "Invalid credentials"}, status=401)
else:
return Response({"error": "Please provide Username and Password"})