From bef1e8a9f17a9a79d3c68472c323f31e9feeb8ac Mon Sep 17 00:00:00 2001 From: Dmitry Afanasyev Date: Mon, 25 Oct 2021 22:40:08 +0300 Subject: [PATCH] add command and README.md --- django_accounts_app/README.md | 61 +++++++++++++++++++ .../management/commands/create_superuser.py | 19 ++++++ 2 files changed, 80 insertions(+) create mode 100644 django_accounts_app/README.md create mode 100644 django_accounts_app/management/commands/create_superuser.py diff --git a/django_accounts_app/README.md b/django_accounts_app/README.md new file mode 100644 index 0000000..40106db --- /dev/null +++ b/django_accounts_app/README.md @@ -0,0 +1,61 @@ +# Installation + +##*Add to settings.py* + + LOGIN_REDIRECT_URL = '/admin/' + LOGOUT_REDIRECT_URL = '/accounts/login/' + +To INSTALLED_APPS + + 'server.apps.accounts', + +Email settings + +``` +from server.settings.components import config + +ACCOUNT_ACTIVATION_DAYS = 2 +EMAIL_TIMEOUT = 20 + +EMAIL_HOST = config('EMAIL_HOST') +EMAIL_PORT = config('EMAIL_PORT', cast=int) +EMAIL_USE_SSL = config('EMAIL_USE_SSL', cast=bool) +EMAIL_USE_TLS = config('EMAIL_USE_TLS', cast=bool) + +EMAIL_HOST_USER = config('EMAIL_HOST_USER') +EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD') + +# Is used to set sender name +# https://docs.djangoproject.com/en/1.11/ref/settings/#default-from-email +DEFAULT_FROM_EMAIL = EMAIL_HOST_USER +SERVER_EMAIL = EMAIL_HOST_USER +``` + +## Add to templates + +to base.html + + {% block content %} + {% endblock %} + +## Add to .env + +``` +# ====== Email settings ===== + +EMAIL_HOST= +EMAIL_HOST_USER= +EMAIL_HOST_PASSWORD= +EMAIL_PORT= +EMAIL_USE_SSL= +EMAIL_USE_TLS= +``` + +## To urls.py + + from health_check import urls as health_urls + +url_patterns + + path('accounts/', include(accounts_urls)), + diff --git a/django_accounts_app/management/commands/create_superuser.py b/django_accounts_app/management/commands/create_superuser.py new file mode 100644 index 0000000..9871de2 --- /dev/null +++ b/django_accounts_app/management/commands/create_superuser.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand +from server.apps.accounts.models import CustomUser + + +class Command(BaseCommand): + + def handle(self, *args, **options): + if not CustomUser.objects.filter(username='admin').exists(): + username = 'admin' + email = 'admin@admin.ru' + password = 'admin' + admin = CustomUser.objects.create_superuser(username=username, + password=password, + email=email) + admin.is_active = True + admin.is_admin = True + admin.save() + else: + print('Admin accounts can only be initialized if no Accounts exist')