POST parameters updated
This commit is contained in:
parent
e609b58ac9
commit
4c6a6cc73f
@ -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:
|
||||
|
@ -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"])
|
||||
|
Loading…
Reference in New Issue
Block a user