diff --git a/dev/auth_style_design/migrations/0002_default_allauth.py b/dev/auth_style_design/migrations/0002_default_allauth.py new file mode 100644 index 0000000..491d5d6 --- /dev/null +++ b/dev/auth_style_design/migrations/0002_default_allauth.py @@ -0,0 +1,44 @@ +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor +from django.db.migrations.state import StateApps + + +def create_default_allauth(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): + User = apps.get_model('auth', 'User') # noqa: N806 + EmailAddress = apps.get_model('account', 'EmailAddress') # noqa: N806 + + user = User.objects.create_user( + username='user@auth-style-design.test', + email='user@auth-style-design.test', + password='password', + first_name='John', + last_name='Doe', + ) + EmailAddress.objects.create( + user=user, + email=user.email, + verified=True, + primary=True, + ) + + +def delete_default_allauth(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): + User = apps.get_model('auth', 'User') # noqa: N806 + + User.objects.filter(email='user@auth-style-design.test').delete() + # EmailAddress will cascade delete + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth_style_design', '0001_default_site'), + # This is the final auth app migration + ('auth', '0012_alter_user_first_name_max_length'), + # This is the final account (Allauth) app migration + ('account', '0002_email_max_length'), + ] + + operations = [ + migrations.RunPython(create_default_allauth, delete_default_allauth), + ] diff --git a/dev/auth_style_design/migrations/0003_default_oauth_application.py b/dev/auth_style_design/migrations/0003_default_oauth_application.py new file mode 100644 index 0000000..4742973 --- /dev/null +++ b/dev/auth_style_design/migrations/0003_default_oauth_application.py @@ -0,0 +1,39 @@ +from django.db import migrations +from django.db.backends.base.schema import BaseDatabaseSchemaEditor +from django.db.migrations.state import StateApps + + +def create_default_oauth_application(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): + User = apps.get_model('auth', 'User') # noqa: N806 + Application = apps.get_model('oauth2_provider', 'Application') # noqa: N806 + + user = User.objects.get(email='user@auth-style-design.test') + Application.objects.create( + user=user, + redirect_uris='http://127.0.0.1:8000/ urn:ietf:wg:oauth:2.0:oob', + client_type='public', # Application.CLIENT_PUBLIC + authorization_grant_type='authorization-code', # Application.GRANT_AUTHORIZATION_CODE + client_secret='', + name='auth-style-design', + ) + + +def delete_default_oauth_application(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor): + Application = apps.get_model('oauth2_provider', 'Application') # noqa: N806 + + Application.objects.filter(name='auth-style-design').delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth_style_design', '0002_default_allauth'), + # This is the final auth app migration + ('auth', '0012_alter_user_first_name_max_length'), + # This is the final oauth2_provider app migration + ('oauth2_provider', '0005_auto_20211222_2352'), + ] + + operations = [ + migrations.RunPython(create_default_oauth_application, delete_default_oauth_application), + ] diff --git a/dev/auth_style_design/templates/auth_style_design/auth_template_listing.html b/dev/auth_style_design/templates/auth_style_design/auth_template_listing.html index c2b0571..1cb47c4 100644 --- a/dev/auth_style_design/templates/auth_style_design/auth_template_listing.html +++ b/dev/auth_style_design/templates/auth_style_design/auth_template_listing.html @@ -28,4 +28,3 @@