Skip to content

Commit

Permalink
Merge pull request #25 from anjaniacatus/registration_feat_bis
Browse files Browse the repository at this point in the history
Registration feat bis : this PR will cover the registration and resetting password functionality
  • Loading branch information
sheenarbw authored Dec 23, 2024
2 parents f3bf78f + 15c83ce commit 6a2b414
Show file tree
Hide file tree
Showing 58 changed files with 601 additions and 77 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: CodeCov
on: [push, pull_request]

Expand All @@ -17,11 +16,11 @@ jobs:

services:
postgres:
image: postgres:10.8
image: postgres:12
env:
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: djangocon_africa
POSTGRES_USER: pguser
POSTGRES_PASSWORD: password
POSTGRES_DB: db
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
Expand All @@ -39,12 +38,13 @@ jobs:
- name: Generate Report
run: |
pip install -r requirements.txt
python manage.py collectstatic
coverage run -m pytest
coverage xml
env:
DB_NAME: djangocon_africa
DB_HOST: localhost
DB_PASSWORD: postgres
DB_USER: postgres
POSTGRES_DB: db
POSTGRES_USER: pguser
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: password
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
34 changes: 30 additions & 4 deletions core/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"template_partials",
"crispy_forms",
"crispy_tailwind",
"website",
"custom_auth",
"proposals",
"custom_auth",
"allauth",
"allauth.account",
]

MIDDLEWARE = [
Expand All @@ -41,6 +44,7 @@
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"allauth.account.middleware.AccountMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

Expand Down Expand Up @@ -129,9 +133,6 @@

CRISPY_TEMPLATE_PACK = "tailwind"

# django.contrib.auth settings
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
Expand All @@ -141,3 +142,28 @@
DB_PASSWORD = os.environ.get("DATABASE_PASSWORD")
DB_NAME = os.environ.get("DATABASE_NAME")
DB_PORT = os.environ.get("DATABASE_PORT", 5432)

# django-allauth configurations
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
]

ACCOUNT_FORMS = {
'signup': 'custom_auth.forms.CustomSignupForm',
}

SITE_ID = 1 # new
ACCOUNT_EMAIL_VERIFICATION = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_LOGOUT_REDIRECT_URL ='/accounts/login/'
LOGIN_REDIRECT_URL = "/"
ACCOUNT_LOGIN_ON_PASSWORD_RESET = True #logged automatiquely when success
ACCOUNT_LOGOUT_ON_GET = True
5 changes: 5 additions & 0 deletions core/settings_dev.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .settings_base import * # noqa: F403
from .settings_base import BASE_DIR
import dj_database_url

SECRET_KEY = "not really a secret"
Expand All @@ -11,6 +12,7 @@
INSTALLED_APPS += [ # noqa: F405
"django_browser_reload",
"whitenoise.runserver_nostatic",
"django_extensions",
]


Expand All @@ -32,3 +34,6 @@
default=f"postgres://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
)
}

EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
EMAIL_FILE_PATH = BASE_DIR / "emails"
12 changes: 12 additions & 0 deletions core/settings_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@
default=f"postgres://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}" # noqa: F405
)
}


# email config - to be setted in another feature
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = BASE_DIR / 'emails'

Check failure on line 22 in core/settings_prod.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F405)

core/settings_prod.py:22:19: F405 `BASE_DIR` may be undefined, or defined from star imports

# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_HOST = 'smtp.gmail.com'
# EMAIL_USE_TLS = True
# EMAIL_PORT = 587
# EMAIL_HOST_USER = str(os.getenv('EMAIL_USER'))
# EMAIL_HOST_PASSWORD = str(os.getenv('EMAIL_PASSWORD'))
3 changes: 2 additions & 1 deletion core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
from django.contrib import admin
from django.urls import path, include


urlpatterns = [
path("", include("website.urls")),
path("accounts/", include("allauth.urls")),
path("proposals/", include("proposals.urls")),
path("accounts/", include("django.contrib.auth.urls")),
path("admin/", admin.site.urls),
path("__reload__/", include("django_browser_reload.urls")),
]
15 changes: 15 additions & 0 deletions custom_auth/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django import forms
from allauth.account.forms import SignupForm


class CustomSignupForm(SignupForm):
first_name = forms.CharField(max_length=30, label='First Name')
last_name = forms.CharField(max_length=30, label='Last Name')
email = forms.EmailField()

def signup(self, request, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.email = self.cleaned_data['email']
user.save()
return user
2 changes: 2 additions & 0 deletions custom_auth/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
urlpatterns = [
]
4 changes: 2 additions & 2 deletions custom_auth/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# from django.shortcuts import render

# Create your views here.


6 changes: 3 additions & 3 deletions proposals/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.13 on 2024-12-10 14:29
# Generated by Django 5.1.3 on 2024-12-15 15:22

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down Expand Up @@ -42,9 +42,9 @@ class Migration(migrations.Migration):
('audience_level', models.CharField(choices=[('b', 'Beginner - just starting'), ('i', 'Intermediate'), ('a', 'Advanced'), ('n', 'Non technical talk')])),
('accessibility_requests', models.TextField(blank=True, null=True)),
('status', models.CharField(choices=[('submitted', 'Submitted'), ('rejected', 'Rejected'), ('accepted', 'Accepted'), ('shortlisted', 'Shortlisted'), ('backup', 'Backup')], default='submitted')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('proposal_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='proposals.proposaltype')),
('track', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='proposals.track')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
1 change: 1 addition & 0 deletions requirements.dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
django-extensions>=3.2.3
8 changes: 5 additions & 3 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
django>=4.2,<5
django>=4.2,<=5
coverage==7.5.3
dj-database-url==2.2.0
psycopg2-binary==2.9.9
python-dotenv==1.0.1
pytest==8.2.2
pytest==8.3.3
pytest-django==4.8.0
pytest-dotenv==0.5.2
django-browser-reload==1.16.0
django-template-partials==24.4
whitenoise==6.8.2
django-allauth==65.2.0
django-extensions>=3.2.0
crispy-tailwind==1.0.3
django-template-partials==24.4
django-template-partials==24.4
11 changes: 9 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@
asgiref==3.8.1
# via
# django
# django-allauth
# django-browser-reload
coverage==7.5.3
# via -r requirements.in
crispy-tailwind==1.0.3
# via -r requirements.in
dj-database-url==2.2.0
# via -r requirements.in
django==4.2.13
django==4.2.16
# via
# -r requirements.in
# crispy-tailwind
# dj-database-url
# django-allauth
# django-browser-reload
# django-crispy-forms
# django-extensions
# django-template-partials
django-allauth==65.2.0
# via -r requirements.in
django-browser-reload==1.16.0
# via -r requirements.in
django-crispy-forms==2.3
# via crispy-tailwind
django-extensions==3.2.3
# via -r requirements.in
django-template-partials==24.4
# via -r requirements.in
iniconfig==2.0.0
Expand All @@ -36,7 +43,7 @@ pluggy==1.5.0
# via pytest
psycopg2-binary==2.9.9
# via -r requirements.in
pytest==8.2.2
pytest==8.3.3
# via
# -r requirements.in
# pytest-django
Expand Down
33 changes: 9 additions & 24 deletions templates/_base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load static %}

{% load tailwind_filters %}
{% load partials %}

{% partialdef header-menu-item-large %}
Expand All @@ -22,7 +23,7 @@
style="display: none;">

{% for child in link.children %}
<a href="{{ child.href }}" class="header_button">{{ child.label }}</a>
<a href="{{ child.href }}" class="header_button">{{ child.label }}</a>
{% endfor %}

</div>
Expand All @@ -33,7 +34,6 @@


<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down Expand Up @@ -63,45 +63,30 @@
{% for link in header_menu_items %}
{% partial header-menu-item-large %}
{% endfor %}

<!--
{% if user.is_authenticated %}
{% with link=user_loggedin_link %}
{% partial header-menu-item-large %}
{% endwith %}
{% with link=user_loggedin_link %}
{% partial header-menu-item-large %}
{% endwith %}
{% else %}
{% with link=user_not_loggedin_link %}
{% partial header-menu-item-large %}
{% endwith %}
{% with link=user_not_loggedin_link %}
{% partial header-menu-item-large %}
{% endwith %}
{% endif %}
-->

</div>
</div>

</div>
</nav>
<section class="max-w-7xl mx-auto pt-14">
{% block content %}



{% endblock %}

<section class="bg-darkPrimary text-white text-2xl text-center py-8">

<a target="_blank" href="https://x.com/djcafrica"><i class="fab fa-twitter"></i></a>
<a target="_blank" href="https://github.com/djangocon/2025.djangocon.africa"><i
class="fab fa-github"></i></a>
<a target="_blank" href="https://fosstodon.org/@djangoconafrica"><i class="fab fa-mastodon"></i></a>
<a target="_blank" href="https://www.facebook.com/djcafrica/"><i class="fab fa-facebook"></i></a>

</section>
</section>

</body>

</html>
</html>
14 changes: 14 additions & 0 deletions templates/account/account_inactive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "_base.html" %}
{% load i18n %}
{% load allauth %}
{% block head_title %}
{% translate "Account Inactive" %}
{% endblock head_title %}
{% block content %}
{% element h1 %}
{% translate "Account Inactive" %}
{% endelement %}
{% element p %}
{% translate "This account is inactive." %}
{% endelement %}
{% endblock content %}
13 changes: 13 additions & 0 deletions templates/account/email/account_already_exists_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "account/email/base_message.txt" %}
{% load i18n %}

{% block content %}{% autoescape off %}{% blocktrans %}You are receiving this email because you or someone else tried to signup for an
account using email address:

{{ email }}

However, an account using that email address already exists. In case you have
forgotten about this, please use the password forgotten procedure to recover
your account:

{{ password_reset_url }}{% endblocktrans %}{% endautoescape %}{% endblock content %}
4 changes: 4 additions & 0 deletions templates/account/email/account_already_exists_subject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Account Already Exists{% endblocktrans %}
{% endautoescape %}
7 changes: 7 additions & 0 deletions templates/account/email/base_message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% load i18n %}{% autoescape off %}{% blocktrans with site_name=current_site.name %}Hello from {{ site_name }}!{% endblocktrans %}

{% block content %}{% endblock content %}

{% blocktrans with site_name=current_site.name site_domain=current_site.domain %}Thank you for using {{ site_name }}!
{{ site_domain }}{% endblocktrans %}
{% endautoescape %}
14 changes: 14 additions & 0 deletions templates/account/email/base_notification.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "account/email/base_message.txt" %}
{% load account %}
{% load i18n %}

{% block content %}{% autoescape off %}{% blocktrans %}You are receiving this mail because the following change was made to your account:{% endblocktrans %}

{% block notification_message %}
{% endblock notification_message%}

{% blocktrans %}If you do not recognize this change then please take proper security precautions immediately. The change to your account originates from:

- IP address: {{ip}}
- Browser: {{user_agent}}
- Date: {{timestamp}}{% endblocktrans %}{% endautoescape %}{% endblock %}
Loading

0 comments on commit 6a2b414

Please sign in to comment.