mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-30 05:27:01 -05:00
feat: Implement MFA authentication, add ride statistics model, and update various services, APIs, and tests across the application.
This commit is contained in:
@@ -27,14 +27,14 @@ def safe_add_avatar_field(apps, schema_editor):
|
||||
# Check if the column already exists
|
||||
with schema_editor.connection.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name='accounts_userprofile'
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name='accounts_userprofile'
|
||||
AND column_name='avatar_id'
|
||||
""")
|
||||
|
||||
|
||||
column_exists = cursor.fetchone() is not None
|
||||
|
||||
|
||||
if not column_exists:
|
||||
# Column doesn't exist, add it
|
||||
UserProfile = apps.get_model('accounts', 'UserProfile')
|
||||
@@ -55,14 +55,14 @@ def reverse_safe_add_avatar_field(apps, schema_editor):
|
||||
# Check if the column exists and remove it
|
||||
with schema_editor.connection.cursor() as cursor:
|
||||
cursor.execute("""
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name='accounts_userprofile'
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name='accounts_userprofile'
|
||||
AND column_name='avatar_id'
|
||||
""")
|
||||
|
||||
|
||||
column_exists = cursor.fetchone() is not None
|
||||
|
||||
|
||||
if column_exists:
|
||||
UserProfile = apps.get_model('accounts', 'UserProfile')
|
||||
field = models.ForeignKey(
|
||||
|
||||
@@ -23,9 +23,9 @@ class Migration(migrations.Migration):
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name='accounts_userprofileevent'
|
||||
SELECT column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name='accounts_userprofileevent'
|
||||
AND column_name='avatar_id'
|
||||
) THEN
|
||||
ALTER TABLE accounts_userprofileevent ADD COLUMN avatar_id uuid;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Generated by Django 5.2.5 on 2025-09-15 17:35
|
||||
|
||||
import apps.core.choices.fields
|
||||
from django.db import migrations
|
||||
|
||||
import apps.core.choices.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# Generated by Django 5.1.6 on 2025-12-26 14:10
|
||||
|
||||
import apps.core.choices.fields
|
||||
import django.db.models.deletion
|
||||
import pgtrigger.compiler
|
||||
import pgtrigger.migrations
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
import apps.core.choices.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
# Generated by Django 5.2.9 on 2025-12-27 20:58
|
||||
|
||||
import django.db.models.deletion
|
||||
import pgtrigger.compiler
|
||||
import pgtrigger.migrations
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("accounts", "0014_remove_toplist_user_remove_toplistitem_top_list_and_more"),
|
||||
("pghistory", "0007_auto_20250421_0444"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="LoginHistory",
|
||||
fields=[
|
||||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
||||
(
|
||||
"ip_address",
|
||||
models.GenericIPAddressField(
|
||||
blank=True, help_text="IP address from which the login occurred", null=True
|
||||
),
|
||||
),
|
||||
(
|
||||
"user_agent",
|
||||
models.CharField(blank=True, help_text="Browser/client user agent string", max_length=500),
|
||||
),
|
||||
(
|
||||
"login_method",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("PASSWORD", "Password"),
|
||||
("GOOGLE", "Google OAuth"),
|
||||
("DISCORD", "Discord OAuth"),
|
||||
("MAGIC_LINK", "Magic Link"),
|
||||
("SESSION", "Session Refresh"),
|
||||
],
|
||||
default="PASSWORD",
|
||||
help_text="Method used for authentication",
|
||||
max_length=20,
|
||||
),
|
||||
),
|
||||
(
|
||||
"login_timestamp",
|
||||
models.DateTimeField(auto_now_add=True, db_index=True, help_text="When the login occurred"),
|
||||
),
|
||||
("success", models.BooleanField(default=True, help_text="Whether the login was successful")),
|
||||
(
|
||||
"country",
|
||||
models.CharField(blank=True, help_text="Country derived from IP (optional)", max_length=100),
|
||||
),
|
||||
("city", models.CharField(blank=True, help_text="City derived from IP (optional)", max_length=100)),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
help_text="User who logged in",
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="login_history",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name": "Login History",
|
||||
"verbose_name_plural": "Login History",
|
||||
"ordering": ["-login_timestamp"],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="LoginHistoryEvent",
|
||||
fields=[
|
||||
("pgh_id", models.AutoField(primary_key=True, serialize=False)),
|
||||
("pgh_created_at", models.DateTimeField(auto_now_add=True)),
|
||||
("pgh_label", models.TextField(help_text="The event label.")),
|
||||
("id", models.BigIntegerField()),
|
||||
(
|
||||
"ip_address",
|
||||
models.GenericIPAddressField(
|
||||
blank=True, help_text="IP address from which the login occurred", null=True
|
||||
),
|
||||
),
|
||||
(
|
||||
"user_agent",
|
||||
models.CharField(blank=True, help_text="Browser/client user agent string", max_length=500),
|
||||
),
|
||||
(
|
||||
"login_method",
|
||||
models.CharField(
|
||||
choices=[
|
||||
("PASSWORD", "Password"),
|
||||
("GOOGLE", "Google OAuth"),
|
||||
("DISCORD", "Discord OAuth"),
|
||||
("MAGIC_LINK", "Magic Link"),
|
||||
("SESSION", "Session Refresh"),
|
||||
],
|
||||
default="PASSWORD",
|
||||
help_text="Method used for authentication",
|
||||
max_length=20,
|
||||
),
|
||||
),
|
||||
("login_timestamp", models.DateTimeField(auto_now_add=True, help_text="When the login occurred")),
|
||||
("success", models.BooleanField(default=True, help_text="Whether the login was successful")),
|
||||
(
|
||||
"country",
|
||||
models.CharField(blank=True, help_text="Country derived from IP (optional)", max_length=100),
|
||||
),
|
||||
("city", models.CharField(blank=True, help_text="City derived from IP (optional)", max_length=100)),
|
||||
(
|
||||
"pgh_context",
|
||||
models.ForeignKey(
|
||||
db_constraint=False,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||
related_name="+",
|
||||
to="pghistory.context",
|
||||
),
|
||||
),
|
||||
(
|
||||
"pgh_obj",
|
||||
models.ForeignKey(
|
||||
db_constraint=False,
|
||||
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||
related_name="events",
|
||||
to="accounts.loginhistory",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
db_constraint=False,
|
||||
help_text="User who logged in",
|
||||
on_delete=django.db.models.deletion.DO_NOTHING,
|
||||
related_name="+",
|
||||
related_query_name="+",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="loginhistory",
|
||||
index=models.Index(fields=["user", "-login_timestamp"], name="accounts_lo_user_id_156da7_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="loginhistory",
|
||||
index=models.Index(fields=["ip_address"], name="accounts_lo_ip_addr_142937_idx"),
|
||||
),
|
||||
pgtrigger.migrations.AddTrigger(
|
||||
model_name="loginhistory",
|
||||
trigger=pgtrigger.compiler.Trigger(
|
||||
name="insert_insert",
|
||||
sql=pgtrigger.compiler.UpsertTriggerSql(
|
||||
func='INSERT INTO "accounts_loginhistoryevent" ("city", "country", "id", "ip_address", "login_method", "login_timestamp", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "success", "user_agent", "user_id") VALUES (NEW."city", NEW."country", NEW."id", NEW."ip_address", NEW."login_method", NEW."login_timestamp", _pgh_attach_context(), NOW(), \'insert\', NEW."id", NEW."success", NEW."user_agent", NEW."user_id"); RETURN NULL;',
|
||||
hash="9ccc4d52099a09097d02128eb427d58ae955a377",
|
||||
operation="INSERT",
|
||||
pgid="pgtrigger_insert_insert_dc41d",
|
||||
table="accounts_loginhistory",
|
||||
when="AFTER",
|
||||
),
|
||||
),
|
||||
),
|
||||
pgtrigger.migrations.AddTrigger(
|
||||
model_name="loginhistory",
|
||||
trigger=pgtrigger.compiler.Trigger(
|
||||
name="update_update",
|
||||
sql=pgtrigger.compiler.UpsertTriggerSql(
|
||||
condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
|
||||
func='INSERT INTO "accounts_loginhistoryevent" ("city", "country", "id", "ip_address", "login_method", "login_timestamp", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "success", "user_agent", "user_id") VALUES (NEW."city", NEW."country", NEW."id", NEW."ip_address", NEW."login_method", NEW."login_timestamp", _pgh_attach_context(), NOW(), \'update\', NEW."id", NEW."success", NEW."user_agent", NEW."user_id"); RETURN NULL;',
|
||||
hash="d5d998a5af1a55f181ebe8500a70022e8e4db724",
|
||||
operation="UPDATE",
|
||||
pgid="pgtrigger_update_update_110f5",
|
||||
table="accounts_loginhistory",
|
||||
when="AFTER",
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user