Skip to content

Commit

Permalink
add min length validator on api key
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Oct 29, 2024
1 parent b197675 commit 548469e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions lemarche/users/migrations/0040_alter_user_api_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.15 on 2024-10-29 13:28

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("users", "0039_remove_user_user_email_ci_uniqueness_and_more"),
]

operations = [
migrations.AlterField(
model_name="user",
name="api_key",
field=models.CharField(
blank=True,
max_length=128,
null=True,
unique=True,
validators=[django.core.validators.MinLengthValidator(64)],
verbose_name="Clé API",
),
),
]
5 changes: 4 additions & 1 deletion lemarche/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import AbstractUser
from django.contrib.contenttypes.fields import GenericRelation
from django.core.validators import MinLengthValidator
from django.db import models
from django.db.models import Count
from django.db.models.functions import Greatest, Lower
Expand Down Expand Up @@ -230,7 +231,9 @@ class User(AbstractUser):
max_length=20, choices=user_constants.SOURCE_CHOICES, default=user_constants.SOURCE_SIGNUP_FORM
)

api_key = models.CharField(verbose_name="Clé API", max_length=128, unique=True, blank=True, null=True)
api_key = models.CharField(
verbose_name="Clé API", max_length=128, unique=True, blank=True, null=True, validators=[MinLengthValidator(64)]
)
api_key_last_updated = models.DateTimeField(
verbose_name="Date de dernière mise à jour de la clé API", blank=True, null=True
)
Expand Down

0 comments on commit 548469e

Please sign in to comment.