forked from github/plane
dev: license check
This commit is contained in:
parent
cc82fae0e1
commit
08a81b0c5e
@ -40,32 +40,34 @@ class InstanceEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
payload = {"email": email, "version": data.get("version", 0.1)}
|
payload = {"email": email, "version": data.get("version", 0.1)}
|
||||||
|
|
||||||
response = requests.post(
|
print(request.get_host())
|
||||||
f"{LICENSE_ENGINE_BASE_URL}/api/instances",
|
|
||||||
headers=headers,
|
|
||||||
data=json.dumps(payload),
|
|
||||||
)
|
|
||||||
|
|
||||||
if response.status_code == 201:
|
# response = requests.post(
|
||||||
data = response.json()
|
# f"{LICENSE_ENGINE_BASE_URL}/api/instances",
|
||||||
license = License.objects.create(
|
# headers=headers,
|
||||||
instance_id=data.get("id"),
|
# data=json.dumps(payload),
|
||||||
license_key=data.get("license_key"),
|
# )
|
||||||
api_key=data.get("api_key"),
|
|
||||||
version=data.get("version"),
|
# if response.status_code == 201:
|
||||||
email=data.get("email"),
|
# data = response.json()
|
||||||
last_checked_at=timezone.now(),
|
# license = License.objects.create(
|
||||||
)
|
# instance_id=data.get("id"),
|
||||||
return Response(
|
# license_key=data.get("license_key"),
|
||||||
{
|
# api_key=data.get("api_key"),
|
||||||
"id": str(license.instance_id),
|
# version=data.get("version"),
|
||||||
"message": "Instance registered succesfully",
|
# email=data.get("email"),
|
||||||
},
|
# last_checked_at=timezone.now(),
|
||||||
status=status.HTTP_200_OK,
|
# )
|
||||||
)
|
# return Response(
|
||||||
|
# {
|
||||||
|
# "id": str(license.instance_id),
|
||||||
|
# "message": "Instance registered succesfully",
|
||||||
|
# },
|
||||||
|
# status=status.HTTP_200_OK,
|
||||||
|
# )
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "Unable to create instance"}, status=response.status_code
|
{"error": "Unable to create instance"}, status=200
|
||||||
)
|
)
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
@ -1,7 +1,19 @@
|
|||||||
|
# Django imports
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
# Third party imports
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from plane.license.models import License
|
||||||
|
|
||||||
|
@shared_task
|
||||||
def license_check_task():
|
def license_check_task():
|
||||||
|
|
||||||
|
license = License.objects.first()
|
||||||
|
now = timezone.now()
|
||||||
|
if license.check_frequency == "daily" and (now - license.last_checked_at).total_seconds() > 86400:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if license.check_frequency == "fortnite" and (now - license.last_checked_at).total_seconds():
|
||||||
|
pass
|
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.3 on 2023-10-27 11:37
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('license', '0004_alter_license_instance_id'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='license',
|
||||||
|
name='last_checked_at',
|
||||||
|
field=models.DateTimeField(null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.3 on 2023-10-27 11:41
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('license', '0005_license_last_checked_at'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='license',
|
||||||
|
name='check_frequency',
|
||||||
|
field=models.CharField(null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -11,7 +11,9 @@ class License(BaseModel):
|
|||||||
api_key = models.CharField(max_length=16)
|
api_key = models.CharField(max_length=16)
|
||||||
version = models.CharField(max_length=10)
|
version = models.CharField(max_length=10)
|
||||||
email = models.CharField(max_length=256)
|
email = models.CharField(max_length=256)
|
||||||
# last_checked_at = models.DateTimeField(null=True)
|
last_checked_at = models.DateTimeField(null=True)
|
||||||
|
check_frequency = models.CharField(null=True)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "License"
|
verbose_name = "License"
|
||||||
|
Loading…
Reference in New Issue
Block a user