Skip to content

Commit

Permalink
Add password reset capabilities to the admin interface (code4romania#133
Browse files Browse the repository at this point in the history
)

- Fix code4romania#106
- Add site base URL to the prod required env variables
- Configure DATABASES using the configurations module
- Fix the prod environment variables template.
- Fix black issues
  • Loading branch information
aramboi committed Feb 25, 2020
1 parent b85a9c4 commit fa05805
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
26 changes: 23 additions & 3 deletions api/seismic_site/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@

import os

import dj_database_url
from configurations import Configuration, values

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


class Base(Configuration):
"""
For more info about the `django-configurations` library, see
https://django-configurations.readthedocs.io/en/latest/
"""

DEBUG = False

SECRET_KEY = values.Value()

ALLOWED_HOSTS = []
SITE_URL = values.Value()
SITE_ID = 1

INSTALLED_APPS = [
# django apps
Expand All @@ -32,6 +38,9 @@ class Base(Configuration):
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"django.contrib.sitemaps",
"django.contrib.humanize",
# third-party apps
"rest_framework",
"storages",
Expand Down Expand Up @@ -77,7 +86,7 @@ class Base(Configuration):
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {"default": dj_database_url.config(conn_max_age=600)}
DATABASES = values.DatabaseURLValue()

# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
Expand Down Expand Up @@ -135,15 +144,26 @@ class Base(Configuration):
class Dev(Base):
DEBUG = True
SECRET_KEY = "secret"
SITE_URL = "http://localhost:8000"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"


class Test(Base):
DEBUG = True
SECRET_KEY = "secret"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
SITE_URL = "http://localhost"
EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend"


class Prod(Base):
DEBUG = False
ALLOWED_HOSTS = values.ListValue(default=[".code4.ro"])

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_USE_TLS = True
EMAIL_HOST = values.Value(default="smtp.gmail.com")
EMAIL_PORT = 587
EMAIL_HOST_USER = values.Value()
EMAIL_HOST_PASSWORD = values.Value()

DEFAULT_FROM_EMAIL = values.EmailValue(default="noreply@code4.ro")
25 changes: 25 additions & 0 deletions api/seismic_site/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import path, include

from rest_framework import routers
Expand All @@ -9,6 +10,10 @@
from pages.views import PagesViewSet
from blog.views import PostViewSet

admin.site.site_title = "Seismic Risk Admin"
admin.site.site_header = "Seismic Risk Admin"
admin.site.index_title = "Seismic Risk Admin"
admin.site.site_url = settings.SITE_URL

router = routers.DefaultRouter()
router.register(r"buildings", BuildingViewSet, basename="buildings")
Expand All @@ -17,6 +22,26 @@


urlpatterns = [
path(
"admin/password_reset/",
auth_views.PasswordResetView.as_view(),
name="admin_password_reset",
),
path(
"admin/password_reset/done/",
auth_views.PasswordResetDoneView.as_view(),
name="password_reset_done",
),
path(
"admin/reset/<uidb64>/<token>/",
auth_views.PasswordResetConfirmView.as_view(),
name="password_reset_confirm",
),
path(
"admin/reset/done/",
auth_views.PasswordResetCompleteView.as_view(),
name="password_reset_complete",
),
path("admin/", admin.site.urls),
path("ckeditor/", include("ckeditor_uploader.urls")),
path("api/v1/", include(router.urls)),
Expand Down
5 changes: 5 additions & 0 deletions prod.env.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
DJANGO_CONFIGURATION=Prod
DJANGO_SECRET_KEY=
DJANGO_SITE_URL=
DJANGO_EMAIL_HOST=
DJANGO_EMAIL_HOST_USER=
DJANGO_EMAIL_HOST_PASSWORD=
DJANGO_DEFAULT_FROM_EMAIL=
DATABASE_URL=postgres://USER:PASSWORD@HOST:PORT/NAME
GUNICORN_PORT=5000
GUNICORN_WORKERS=2
Expand Down

0 comments on commit fa05805

Please sign in to comment.