generate auth key
This commit is contained in:
parent
3defb09002
commit
8bf138d8c9
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.1 on 2022-08-24 01:37
|
||||
|
||||
from django.db import migrations, models
|
||||
import frog_api.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("frog_api", "0005_remove_entry_decompiled_bytes_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="project",
|
||||
name="auth_key",
|
||||
field=models.CharField(default=frog_api.models.gen_auth_key, max_length=10),
|
||||
),
|
||||
]
|
|
@ -1,4 +1,17 @@
|
|||
from django.db import models
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
AUTH_KEY_LEN = 10
|
||||
|
||||
|
||||
def gen_auth_key() -> str:
|
||||
ret = get_random_string(length=AUTH_KEY_LEN)
|
||||
|
||||
if Project.objects.filter(auth_key=ret).exists():
|
||||
return gen_auth_key()
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
# Example: OOT
|
||||
class Project(models.Model):
|
||||
|
@ -8,7 +21,7 @@ class Project(models.Model):
|
|||
|
||||
slug = models.SlugField(max_length=255, unique=True)
|
||||
name = models.CharField(max_length=255)
|
||||
auth_key = models.CharField(max_length=255)
|
||||
auth_key = models.CharField(max_length=AUTH_KEY_LEN, default=gen_auth_key)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.slug
|
||||
|
|
Loading…
Reference in New Issue