WellService/jwtauth/views.py
2024-08-21 16:38:37 +03:30

43 lines
No EOL
1 KiB
Python

from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework_simplejwt.exceptions import InvalidToken
from rest_framework_simplejwt.tokens import UntypedToken
import json
from .models import OkService
@api_view(['POST'])
def register_service(request):
try:
data = dict(json.loads(request.body.decode('utf-8')))
print(data, type(data))
if "shared_key" in dict(data).keys:
if first_step_check():
...
services = OkService.objects.all()
except Exception as ex:
print(ex)
def first_step_check(shared_key):
service_id = 1
return service_id
def generate_tokens(service_id):
refresh = RefreshToken.for_user(service_id)
return {
'refresh': str(refresh),
'access': str(refresh.access_token),
}
def validate_token(token):
try:
UntypedToken(token)
return True
except InvalidToken:
return False