Files
arthur_chen f69efb67ad Initial commit: abyssVpn project
- Tauri desktop app (apps/desktop)
- Python Django API service (services/api)
- Deployment scripts and docs
2026-05-15 09:06:10 +08:00

74 lines
2.6 KiB
Python

from django.db import models
from django.utils import timezone
class User(models.Model):
STATUS_ACTIVE = "active"
STATUS_DISABLED = "disabled"
STATUS_CHOICES = (
(STATUS_ACTIVE, "Active"),
(STATUS_DISABLED, "Disabled"),
)
feishu_open_id = models.CharField(max_length=128, unique=True)
email = models.EmailField(blank=True)
name = models.CharField(max_length=128, blank=True)
status = models.CharField(max_length=16, choices=STATUS_CHOICES, default=STATUS_ACTIVE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self) -> str:
return self.name or self.email or self.feishu_open_id
class OAuthState(models.Model):
state = models.CharField(max_length=128, unique=True)
used_at = models.DateTimeField(null=True, blank=True)
expires_at = models.DateTimeField()
created_at = models.DateTimeField(auto_now_add=True)
@property
def is_valid(self) -> bool:
return self.used_at is None and self.expires_at > timezone.now()
class LoginCode(models.Model):
code = models.CharField(max_length=128, unique=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="login_codes")
used_at = models.DateTimeField(null=True, blank=True)
expires_at = models.DateTimeField()
created_at = models.DateTimeField(auto_now_add=True)
@property
def is_valid(self) -> bool:
return self.used_at is None and self.expires_at > timezone.now()
class DesktopLoginSession(models.Model):
STATUS_PENDING = "pending"
STATUS_AUTHENTICATED = "authenticated"
STATUS_FAILED = "failed"
STATUS_EXPIRED = "expired"
STATUS_CHOICES = (
(STATUS_PENDING, "Pending"),
(STATUS_AUTHENTICATED, "Authenticated"),
(STATUS_FAILED, "Failed"),
(STATUS_EXPIRED, "Expired"),
)
session_id = models.CharField(max_length=128, unique=True)
state = models.CharField(max_length=128, unique=True)
user = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL, related_name="desktop_login_sessions")
status = models.CharField(max_length=24, choices=STATUS_CHOICES, default=STATUS_PENDING)
error = models.CharField(max_length=255, blank=True)
expires_at = models.DateTimeField()
authenticated_at = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@property
def is_expired(self) -> bool:
return self.expires_at <= timezone.now()