Repository: imAsparky/django-cookiecutter

Issue:
[FEAT]: Add django-allauth to Django project
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.



Discussion:

Resolving patch:
diff --git a/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py b/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py
--- a/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py
+++ b/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/settings.py
@@ -39,6 +39,11 @@
     "django.contrib.sessions",
     "django.contrib.messages",
     "django.contrib.staticfiles",
+{% if cookiecutter.use_django_allauth == "y" %}
+    "allauth",
+    "allauth.account",
+    "allauth.socialaccount",
+{% endif %}
 ]
 
 SITE_ID = "{{cookiecutter.SITE_ID}}"
@@ -67,11 +72,25 @@
                 "django.template.context_processors.request",
                 "django.contrib.auth.context_processors.auth",
                 "django.contrib.messages.context_processors.messages",
+                {% if cookiecutter.use_django_allauth == "y" %}
+                "django.template.context_processors.request",
+                {% endif %}
             ],
         },
     },
 ]
 
+{% if cookiecutter.use_django_allauth == "y" %}
+AUTHENTICATION_BACKENDS = [
+
+    # Needed to login by username in Django admin, regardless of `allauth`
+    'django.contrib.auth.backends.ModelBackend',
+
+    # `allauth` specific authentication methods, such as login by e-mail
+    'allauth.account.auth_backends.AuthenticationBackend',
+
+{% endif %}
+
 WSGI_APPLICATION = "{{ cookiecutter.project_slug}}.wsgi.application"
 
 
diff --git a/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/urls.py b/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/urls.py
--- a/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/urls.py
+++ b/{{cookiecutter.git_project_name}}/{{cookiecutter.project_slug}}/urls.py
@@ -18,4 +18,7 @@
 
 urlpatterns = [
     path('admin/', admin.site.urls),
+{% if cookiecutter.use_django_allauth == "y" %}
+    path('accounts/', include('allauth.urls')),
+{% endif %}
 ]


Test patch:
diff --git a/tests/test_bake_django.py b/tests/test_bake_django.py
--- a/tests/test_bake_django.py
+++ b/tests/test_bake_django.py
@@ -15,6 +15,78 @@ def test_django_bakes_ok_with_defaults(cookies):
     assert default_django.project_path.name == "django-boilerplate"
 
 
+def test_baked_django_with_allauth_settings_ok(cookies):
+    """Test Django allauth settings file has been generated correctly."""
+    default_django = cookies.bake()
+
+    settings_path = default_django.project_path / "django_boilerplate/settings.py"
+    settings_file = settings_path.read_text().splitlines()
+
+    assert '    "allauth",' in settings_file
+
+    assert '    "allauth.account",' in settings_file
+    assert '    "allauth.socialaccount",' in settings_file
+    assert (
+        '                "django.template.context_processors.request",' in settings_file
+    )
+
+
+def test_baked_django_without_allauth_settings_ok(cookies):
+    """Test Django allauth settings file has not been generated."""
+    non_default_django = cookies.bake(extra_context={"use_django_allauth": "n"})
+
+    settings_path = non_default_django.project_path / "django_boilerplate/settings.py"
+    settings_file = settings_path.read_text().splitlines()
+
+    assert '    "allauth",' not in settings_file
+
+    assert '    "allauth.account",' not in settings_file
+    assert '    "allauth.socialaccount",' not in settings_file
+    assert (
+        '                "django.template.context_processors.request",' in settings_file
+    )
+
+
+def test_baked_django_with_allauth_requirements_ok(cookies):
+    """Test Django allauth requirements_dev file entry has been generated."""
+    default_django = cookies.bake()
+
+    requirements_path = default_django.project_path / "requirements_dev.txt"
+    requirements_file = requirements_path.read_text().splitlines()
+
+    assert "django-allauth==0.45.0" in requirements_file
+
+
+def test_baked_django_without_allauth_requirements_ok(cookies):
+    """Test Django allauth requirements_dev file entry has not been generated."""
+    non_default_django = cookies.bake(extra_context={"use_django_allauth": "n"})
+
+    requirements_path = non_default_django.project_path / "requirements_dev.txt"
+    requirements_file = requirements_path.read_text().splitlines()
+
+    assert "django-allauth==0.45.0" not in requirements_file
+
+
+def test_baked_django_with_allauth_url_ok(cookies):
+    """Test Django allauth url.py file entry has been generated."""
+    default_django = cookies.bake()
+
+    url_path = default_django.project_path / "django_boilerplate/urls.py"
+    url_file = url_path.read_text().splitlines()
+
+    assert "    path('accounts/', include('allauth.urls'))," in url_file
+
+
+def test_baked_django_without_allauth_url_ok(cookies):
+    """Test Django allauth url.py file entry has not been generated."""
+    non_default_django = cookies.bake(extra_context={"use_django_allauth": "n"})
+
+    url_path = non_default_django.project_path / "django_boilerplate/urls.py"
+    url_file = url_path.read_text().splitlines()
+
+    assert "    path('accounts/', include('allauth.urls'))," not in url_file
+
+
 def test_baked_django_asgi_file_ok(cookies):
     """Test Django asgy.py file has been generated correctly."""
     default_django = cookies.bake()