feat: implement API security measures phase 1

This commit is contained in:
Marko (Hermes Implementer)
2026-05-27 00:24:09 +00:00
parent a0b3ae7e34
commit c2fc7bc15f
21 changed files with 1050 additions and 44 deletions
+31 -1
View File
@@ -26,4 +26,34 @@ class User(AbstractUser):
verbose_name_plural = "Users"
def __str__(self) -> str:
return self.email
return self.email
@property
def is_admin(self) -> bool:
"""Check if user belongs to the admin group."""
return self.groups.filter(name="admin").exists() or self.is_superuser
class BlacklistedToken(models.Model):
"""Stores blacklisted JWT tokens for revocation."""
jti = models.UUIDField(unique=True, help_text="JWT ID from the token payload")
user = models.ForeignKey(
User,
on_delete=models.CASCADE,
related_name="blacklisted_tokens",
)
created_at = models.DateTimeField(auto_now_add=True)
expires_at = models.DateTimeField(help_text="When the token would have naturally expired")
class Meta:
db_table = "accounts_blacklisted_token"
verbose_name = "Blacklisted Token"
verbose_name_plural = "Blacklisted Tokens"
indexes = [
models.Index(fields=["jti"]),
models.Index(fields=["expires_at"]),
]
def __str__(self) -> str:
return f"Blacklisted {self.jti} (user {self.user_id})"