473 lines
17 KiB
Python
473 lines
17 KiB
Python
# Generated by Django 5.2.7 on 2025-10-06 21:15
|
|
|
|
import django.contrib.auth.models
|
|
import django.contrib.auth.validators
|
|
import django.utils.timezone
|
|
import uuid
|
|
from django.db import migrations, models
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
initial = True
|
|
|
|
dependencies = [
|
|
("auth", "0012_alter_user_first_name_max_length"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name="PasswordHistory",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.BigAutoField(
|
|
auto_created=True,
|
|
primary_key=True,
|
|
serialize=False,
|
|
verbose_name="ID",
|
|
),
|
|
),
|
|
(
|
|
"password_hash",
|
|
models.CharField(help_text="Hashed password", max_length=128),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
],
|
|
options={
|
|
"verbose_name": "Password History",
|
|
"verbose_name_plural": "Password History",
|
|
"db_table": "accounts_password_history",
|
|
"ordering": ["-created_at"],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name="SocialAccount",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.BigAutoField(
|
|
auto_created=True,
|
|
primary_key=True,
|
|
serialize=False,
|
|
verbose_name="ID",
|
|
),
|
|
),
|
|
(
|
|
"provider",
|
|
models.CharField(
|
|
choices=[
|
|
("GOOGLE", "Google"),
|
|
("MICROSOFT", "Microsoft"),
|
|
("APPLE", "Apple"),
|
|
("FACEBOOK", "Facebook"),
|
|
("LINKEDIN", "LinkedIn"),
|
|
("GITHUB", "GitHub"),
|
|
("OKTA", "Okta"),
|
|
("SAML", "SAML"),
|
|
("LDAP", "LDAP"),
|
|
],
|
|
max_length=50,
|
|
),
|
|
),
|
|
(
|
|
"provider_id",
|
|
models.CharField(help_text="Provider user ID", max_length=200),
|
|
),
|
|
(
|
|
"provider_email",
|
|
models.EmailField(
|
|
blank=True,
|
|
help_text="Email from provider",
|
|
max_length=254,
|
|
null=True,
|
|
),
|
|
),
|
|
(
|
|
"display_name",
|
|
models.CharField(
|
|
blank=True,
|
|
help_text="Display name from provider",
|
|
max_length=200,
|
|
null=True,
|
|
),
|
|
),
|
|
(
|
|
"profile_url",
|
|
models.URLField(
|
|
blank=True, help_text="Profile URL from provider", null=True
|
|
),
|
|
),
|
|
(
|
|
"avatar_url",
|
|
models.URLField(
|
|
blank=True, help_text="Avatar URL from provider", null=True
|
|
),
|
|
),
|
|
(
|
|
"access_token",
|
|
models.TextField(
|
|
blank=True, help_text="Access token from provider", null=True
|
|
),
|
|
),
|
|
(
|
|
"refresh_token",
|
|
models.TextField(
|
|
blank=True, help_text="Refresh token from provider", null=True
|
|
),
|
|
),
|
|
(
|
|
"token_expires_at",
|
|
models.DateTimeField(
|
|
blank=True, help_text="Token expiration date", null=True
|
|
),
|
|
),
|
|
(
|
|
"is_active",
|
|
models.BooleanField(
|
|
default=True, help_text="Social account is active"
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
(
|
|
"last_login_at",
|
|
models.DateTimeField(
|
|
blank=True,
|
|
help_text="Last login using this social account",
|
|
null=True,
|
|
),
|
|
),
|
|
],
|
|
options={
|
|
"verbose_name": "Social Account",
|
|
"verbose_name_plural": "Social Accounts",
|
|
"db_table": "accounts_social_account",
|
|
"ordering": ["-created_at"],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name="TwoFactorDevice",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.BigAutoField(
|
|
auto_created=True,
|
|
primary_key=True,
|
|
serialize=False,
|
|
verbose_name="ID",
|
|
),
|
|
),
|
|
(
|
|
"device_id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4,
|
|
editable=False,
|
|
help_text="Unique device identifier",
|
|
unique=True,
|
|
),
|
|
),
|
|
("name", models.CharField(help_text="Device name", max_length=100)),
|
|
(
|
|
"device_type",
|
|
models.CharField(
|
|
choices=[
|
|
("TOTP", "Time-based OTP (Authenticator App)"),
|
|
("SMS", "SMS"),
|
|
("EMAIL", "Email"),
|
|
("HARDWARE", "Hardware Token"),
|
|
("BACKUP", "Backup Codes"),
|
|
],
|
|
max_length=20,
|
|
),
|
|
),
|
|
(
|
|
"secret_key",
|
|
models.CharField(
|
|
blank=True,
|
|
help_text="Secret key for TOTP devices",
|
|
max_length=200,
|
|
null=True,
|
|
),
|
|
),
|
|
(
|
|
"phone_number",
|
|
models.CharField(
|
|
blank=True,
|
|
help_text="Phone number for SMS devices",
|
|
max_length=20,
|
|
null=True,
|
|
),
|
|
),
|
|
(
|
|
"email_address",
|
|
models.EmailField(
|
|
blank=True,
|
|
help_text="Email address for email devices",
|
|
max_length=254,
|
|
null=True,
|
|
),
|
|
),
|
|
(
|
|
"is_active",
|
|
models.BooleanField(default=True, help_text="Device is active"),
|
|
),
|
|
(
|
|
"is_verified",
|
|
models.BooleanField(default=False, help_text="Device is verified"),
|
|
),
|
|
(
|
|
"verified_at",
|
|
models.DateTimeField(
|
|
blank=True, help_text="Device verification date", null=True
|
|
),
|
|
),
|
|
(
|
|
"last_used_at",
|
|
models.DateTimeField(
|
|
blank=True, help_text="Last time device was used", null=True
|
|
),
|
|
),
|
|
(
|
|
"usage_count",
|
|
models.PositiveIntegerField(
|
|
default=0, help_text="Number of times device was used"
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("updated_at", models.DateTimeField(auto_now=True)),
|
|
],
|
|
options={
|
|
"verbose_name": "Two Factor Device",
|
|
"verbose_name_plural": "Two Factor Devices",
|
|
"db_table": "accounts_two_factor_device",
|
|
"ordering": ["-created_at"],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name="UserSession",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.BigAutoField(
|
|
auto_created=True,
|
|
primary_key=True,
|
|
serialize=False,
|
|
verbose_name="ID",
|
|
),
|
|
),
|
|
(
|
|
"session_key",
|
|
models.CharField(
|
|
help_text="Django session key", max_length=40, unique=True
|
|
),
|
|
),
|
|
(
|
|
"session_id",
|
|
models.UUIDField(
|
|
default=uuid.uuid4,
|
|
editable=False,
|
|
help_text="Unique session identifier",
|
|
unique=True,
|
|
),
|
|
),
|
|
("ip_address", models.GenericIPAddressField(help_text="IP address")),
|
|
("user_agent", models.TextField(help_text="User agent string")),
|
|
(
|
|
"device_type",
|
|
models.CharField(
|
|
choices=[
|
|
("DESKTOP", "Desktop"),
|
|
("MOBILE", "Mobile"),
|
|
("TABLET", "Tablet"),
|
|
("UNKNOWN", "Unknown"),
|
|
],
|
|
default="UNKNOWN",
|
|
max_length=20,
|
|
),
|
|
),
|
|
(
|
|
"browser",
|
|
models.CharField(
|
|
blank=True,
|
|
help_text="Browser name and version",
|
|
max_length=100,
|
|
null=True,
|
|
),
|
|
),
|
|
(
|
|
"operating_system",
|
|
models.CharField(
|
|
blank=True,
|
|
help_text="Operating system",
|
|
max_length=100,
|
|
null=True,
|
|
),
|
|
),
|
|
(
|
|
"country",
|
|
models.CharField(
|
|
blank=True, help_text="Country", max_length=100, null=True
|
|
),
|
|
),
|
|
(
|
|
"region",
|
|
models.CharField(
|
|
blank=True, help_text="Region/State", max_length=100, null=True
|
|
),
|
|
),
|
|
(
|
|
"city",
|
|
models.CharField(
|
|
blank=True, help_text="City", max_length=100, null=True
|
|
),
|
|
),
|
|
(
|
|
"is_active",
|
|
models.BooleanField(default=True, help_text="Session is active"),
|
|
),
|
|
(
|
|
"login_method",
|
|
models.CharField(
|
|
choices=[
|
|
("PASSWORD", "Password"),
|
|
("TWO_FACTOR", "Two Factor"),
|
|
("SOCIAL", "Social Login"),
|
|
("SSO", "Single Sign-On"),
|
|
("API_KEY", "API Key"),
|
|
],
|
|
default="PASSWORD",
|
|
max_length=20,
|
|
),
|
|
),
|
|
("created_at", models.DateTimeField(auto_now_add=True)),
|
|
("last_activity_at", models.DateTimeField(auto_now=True)),
|
|
(
|
|
"expires_at",
|
|
models.DateTimeField(help_text="Session expiration time"),
|
|
),
|
|
(
|
|
"ended_at",
|
|
models.DateTimeField(
|
|
blank=True, help_text="Session end time", null=True
|
|
),
|
|
),
|
|
],
|
|
options={
|
|
"verbose_name": "User Session",
|
|
"verbose_name_plural": "User Sessions",
|
|
"db_table": "accounts_user_session",
|
|
"ordering": ["-created_at"],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name="User",
|
|
fields=[
|
|
(
|
|
"id",
|
|
models.BigAutoField(
|
|
auto_created=True,
|
|
primary_key=True,
|
|
serialize=False,
|
|
verbose_name="ID",
|
|
),
|
|
),
|
|
("password", models.CharField(max_length=128, verbose_name="password")),
|
|
(
|
|
"last_login",
|
|
models.DateTimeField(
|
|
blank=True, null=True, verbose_name="last login"
|
|
),
|
|
),
|
|
(
|
|
"is_superuser",
|
|
models.BooleanField(
|
|
default=False,
|
|
help_text="Designates that this user has all permissions without explicitly assigning them.",
|
|
verbose_name="superuser status",
|
|
),
|
|
),
|
|
(
|
|
"username",
|
|
models.CharField(
|
|
error_messages={
|
|
"unique": "A user with that username already exists."
|
|
},
|
|
help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
|
|
max_length=150,
|
|
unique=True,
|
|
validators=[
|
|
django.contrib.auth.validators.UnicodeUsernameValidator()
|
|
],
|
|
verbose_name="username",
|
|
),
|
|
),
|
|
(
|
|
"first_name",
|
|
models.CharField(
|
|
blank=True, max_length=150, verbose_name="first name"
|
|
),
|
|
),
|
|
(
|
|
"last_name",
|
|
models.CharField(
|
|
blank=True, max_length=150, verbose_name="last name"
|
|
),
|
|
),
|
|
(
|
|
"is_staff",
|
|
models.BooleanField(
|
|
default=False,
|
|
help_text="Designates whether the user can log into this admin site.",
|
|
verbose_name="staff status",
|
|
),
|
|
),
|
|
(
|
|
"is_active",
|
|
models.BooleanField(
|
|
default=True,
|
|
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.",
|
|
verbose_name="active",
|
|
),
|
|
),
|
|
(
|
|
"date_joined",
|
|
models.DateTimeField(
|
|
default=django.utils.timezone.now, verbose_name="date joined"
|
|
),
|
|
),
|
|
(
|
|
"user_id",
|
|
models.UUIDField(default=uuid.uuid4, editable=False, unique=True),
|
|
),
|
|
("email", models.EmailField(max_length=254, unique=True)),
|
|
("force_password_change", models.BooleanField(default=False)),
|
|
("password_expires_at", models.DateTimeField(blank=True, null=True)),
|
|
("failed_login_attempts", models.PositiveIntegerField(default=0)),
|
|
("locked_until", models.DateTimeField(blank=True, null=True)),
|
|
("two_factor_enabled", models.BooleanField(default=False)),
|
|
("max_concurrent_sessions", models.PositiveIntegerField(default=3)),
|
|
("session_timeout_minutes", models.PositiveIntegerField(default=30)),
|
|
("last_password_change", models.DateTimeField(blank=True, null=True)),
|
|
(
|
|
"groups",
|
|
models.ManyToManyField(
|
|
blank=True,
|
|
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
|
|
related_name="user_set",
|
|
related_query_name="user",
|
|
to="auth.group",
|
|
verbose_name="groups",
|
|
),
|
|
),
|
|
],
|
|
options={
|
|
"db_table": "accounts_user",
|
|
"ordering": ["last_name", "first_name"],
|
|
},
|
|
managers=[
|
|
("objects", django.contrib.auth.models.UserManager()),
|
|
],
|
|
),
|
|
]
|