diff --git a/backend/webapp/prototype/filehandler/userModule.py b/backend/webapp/prototype/filehandler/userModule.py index 8c3af2e..4ebd580 100644 --- a/backend/webapp/prototype/filehandler/userModule.py +++ b/backend/webapp/prototype/filehandler/userModule.py @@ -23,14 +23,17 @@ def loginUser(login, password): try: user = authenticate(username = login, password = password) if isinstance(user, User): + iat = int(time.time()) + exp = iat + 86400 payload = {"iss": "NKADF", - "iat": int(time.time()), + "iat": iat, "sub": user.id, - "exp": int(time.time()) + 86400} + "exp": exp} jwt_token = jwt.encode(payload, settings.SECRET_KEY, algorithm = "HS256").decode("utf-8") result = {"message": "User authenticated successfully", "statusCode": 200, - "token": jwt_token} + "token": jwt_token, + "exp": exp} else: raise UserAuthFailed("Error: User authentication failed") except UserAuthFailed as error: diff --git a/backend/webapp/prototype/filehandler/views.py b/backend/webapp/prototype/filehandler/views.py index 52f01e4..ad161a9 100644 --- a/backend/webapp/prototype/filehandler/views.py +++ b/backend/webapp/prototype/filehandler/views.py @@ -77,15 +77,15 @@ def visualize(request, id): @csrf_exempt def user(request): if request.method == 'POST': - result = registerNewUser(request.POST["login"], request.POST["password"]) + result = registerNewUser(request.POST["email"], request.POST["password"]) return JsonResponse(result, status = result["statusCode"]) else: - return HttpResponse("Error: Method not allowed", status = 405) + return JsonResponse(MethodNotAllowed, status = MethodNotAllowed["statusCode"]) @csrf_exempt def login(request): if request.method == 'POST': - result = loginUser(request.POST["login"], request.POST["password"]) + result = loginUser(request.POST["email"], request.POST["password"]) return JsonResponse(result, status = result["statusCode"]) else: return JsonResponse(MethodNotAllowed, status = MethodNotAllowed["statusCode"])