From 30d1c4bca1a539fb43c44d569dc12deaeae9e134 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Wed, 5 Oct 2022 11:41:05 -0500 Subject: [PATCH 01/11] Add site to add users --- compose/web.yml | 12 ++ images/web_users/Dockerfile | 11 ++ images/web_users/app/dashboard/__init__.py | 0 images/web_users/app/dashboard/asgi.py | 16 +++ images/web_users/app/dashboard/settings.py | 133 ++++++++++++++++++ images/web_users/app/dashboard/urls.py | 21 +++ images/web_users/app/dashboard/wsgi.py | 16 +++ images/web_users/app/manage.py | 22 +++ images/web_users/app/requirements.txt | 2 + images/web_users/app/start.sh | 25 ++++ images/web_users/app/user/__init__.py | 0 images/web_users/app/user/admin.py | 8 ++ images/web_users/app/user/apps.py | 6 + .../app/user/migrations/0001_initial.py | 52 +++++++ .../web_users/app/user/migrations/__init__.py | 0 images/web_users/app/user/models.py | 29 ++++ images/web_users/app/user/tests.py | 3 + images/web_users/app/user/views.py | 3 + 18 files changed, 359 insertions(+) create mode 100644 images/web_users/Dockerfile create mode 100644 images/web_users/app/dashboard/__init__.py create mode 100644 images/web_users/app/dashboard/asgi.py create mode 100644 images/web_users/app/dashboard/settings.py create mode 100644 images/web_users/app/dashboard/urls.py create mode 100644 images/web_users/app/dashboard/wsgi.py create mode 100755 images/web_users/app/manage.py create mode 100644 images/web_users/app/requirements.txt create mode 100755 images/web_users/app/start.sh create mode 100644 images/web_users/app/user/__init__.py create mode 100644 images/web_users/app/user/admin.py create mode 100644 images/web_users/app/user/apps.py create mode 100644 images/web_users/app/user/migrations/0001_initial.py create mode 100644 images/web_users/app/user/migrations/__init__.py create mode 100644 images/web_users/app/user/models.py create mode 100644 images/web_users/app/user/tests.py create mode 100644 images/web_users/app/user/views.py diff --git a/compose/web.yml b/compose/web.yml index 1b90b4b1..42fc8060 100644 --- a/compose/web.yml +++ b/compose/web.yml @@ -27,3 +27,15 @@ services: - ../envs/.env.db depends_on: - db + web_users: + build: ../images/web_users + volumes: + - ../images/web_users/app/:/app + ports: + - '8000:8000' + env_file: + - ../envs/.env.web + - ../envs/.env.db + depends_on: + - db + working_dir: /app diff --git a/images/web_users/Dockerfile b/images/web_users/Dockerfile new file mode 100644 index 00000000..c208e6b7 --- /dev/null +++ b/images/web_users/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +RUN apt-get update \ + && apt-get install -y postgresql-client + +WORKDIR /app +COPY app/requirements.txt /app/ +RUN pip install -r requirements.txt +COPY app/ /app/ +CMD ./start.sh diff --git a/images/web_users/app/dashboard/__init__.py b/images/web_users/app/dashboard/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/images/web_users/app/dashboard/asgi.py b/images/web_users/app/dashboard/asgi.py new file mode 100644 index 00000000..33d63628 --- /dev/null +++ b/images/web_users/app/dashboard/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for dashboard project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dashboard.settings') + +application = get_asgi_application() diff --git a/images/web_users/app/dashboard/settings.py b/images/web_users/app/dashboard/settings.py new file mode 100644 index 00000000..28aaff7e --- /dev/null +++ b/images/web_users/app/dashboard/settings.py @@ -0,0 +1,133 @@ +""" +Django settings for dashboard project. + +Generated by 'django-admin startproject' using Django 3.2.16. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path +import os +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-acnap5f@i4v7^m2$ed0%i10ta%)1xza%k!zp-42%k*$tb6rt$%' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'user' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'dashboard.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'dashboard.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': BASE_DIR / 'db.sqlite3', + # } + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': os.environ.get('POSTGRES_DB'), + 'USER': os.environ.get('POSTGRES_USER'), + 'PASSWORD': os.environ.get('POSTGRES_PASSWORD'), + 'HOST': os.environ.get('POSTGRES_HOST'), + 'PORT': '5432', + } +} + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/images/web_users/app/dashboard/urls.py b/images/web_users/app/dashboard/urls.py new file mode 100644 index 00000000..00198055 --- /dev/null +++ b/images/web_users/app/dashboard/urls.py @@ -0,0 +1,21 @@ +"""dashboard URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/images/web_users/app/dashboard/wsgi.py b/images/web_users/app/dashboard/wsgi.py new file mode 100644 index 00000000..ebe6c676 --- /dev/null +++ b/images/web_users/app/dashboard/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for dashboard project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dashboard.settings') + +application = get_wsgi_application() diff --git a/images/web_users/app/manage.py b/images/web_users/app/manage.py new file mode 100755 index 00000000..73d4f5b5 --- /dev/null +++ b/images/web_users/app/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dashboard.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/images/web_users/app/requirements.txt b/images/web_users/app/requirements.txt new file mode 100644 index 00000000..978f1b78 --- /dev/null +++ b/images/web_users/app/requirements.txt @@ -0,0 +1,2 @@ +Django>=3.0,<4.0 +psycopg2>=2.8 \ No newline at end of file diff --git a/images/web_users/app/start.sh b/images/web_users/app/start.sh new file mode 100755 index 00000000..1508b891 --- /dev/null +++ b/images/web_users/app/start.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e +export DEBUG=1 +export SECRET_KEY=foo +export DJANGO_ALLOWED_HOSTS="localhost 127.0.0.1 [::1]" +export DJANGO_SUPERUSER_USERNAME=admin3 +export DJANGO_SUPERUSER_PASSWORD=1234 +export DJANGO_SUPERUSER_EMAIL="admi3n@admin.com" + +function startApp () { + # python manage.py inspectdb > models.py + python manage.py migrate + python manage.py createsuperuser --noinputs + python manage.py runserver 0.0.0.0:8000 +} + +flag=true +while "$flag" = true; do + pg_isready -h $POSTGRES_HOST -p 5432 >/dev/null 2>&2 || continue + flag=false + until $(curl -sf -o /dev/null $SERVER_URL); do + echo "Waiting to start rails ports server..." + sleep 2 + done & startApp +done diff --git a/images/web_users/app/user/__init__.py b/images/web_users/app/user/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/images/web_users/app/user/admin.py b/images/web_users/app/user/admin.py new file mode 100644 index 00000000..e7a3c944 --- /dev/null +++ b/images/web_users/app/user/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin +from .models import Users + +# Register your models here. +class UserAdmin(admin.ModelAdmin): + list_display = ('email', 'id', 'display_name', 'status') + +admin.site.register(Users, UserAdmin) \ No newline at end of file diff --git a/images/web_users/app/user/apps.py b/images/web_users/app/user/apps.py new file mode 100644 index 00000000..36cce4c8 --- /dev/null +++ b/images/web_users/app/user/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UserConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'user' diff --git a/images/web_users/app/user/migrations/0001_initial.py b/images/web_users/app/user/migrations/0001_initial.py new file mode 100644 index 00000000..5da2d2e9 --- /dev/null +++ b/images/web_users/app/user/migrations/0001_initial.py @@ -0,0 +1,52 @@ +# Generated by Django 3.2.16 on 2022-10-04 23:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Users', + fields=[ + ('email', models.CharField(max_length=100, unique=True)), + ('id', models.BigAutoField(primary_key=True, serialize=False)), + ('pass_crypt', models.CharField(max_length=100)), + ('creation_time', models.DateTimeField()), + ('display_name', models.CharField(max_length=100, unique=True)), + ('data_public', models.BooleanField()), + ('description', models.TextField()), + ('home_lat', models.FloatField(blank=True, null=True)), + ('home_lon', models.FloatField(blank=True, null=True)), + ('home_zoom', models.SmallIntegerField(blank=True, null=True)), + ('pass_salt', models.CharField(blank=True, max_length=100, null=True)), + ('email_valid', models.BooleanField()), + ('new_email', models.CharField(blank=True, max_length=100, null=True)), + ('creation_ip', models.CharField(blank=True, max_length=100, null=True)), + ('languages', models.CharField(blank=True, max_length=100, null=True)), + ('status', models.TextField()), + ('terms_agreed', models.DateTimeField(blank=True, null=True)), + ('consider_pd', models.BooleanField()), + ('auth_uid', models.CharField(blank=True, max_length=100, null=True)), + ('preferred_editor', models.CharField(blank=True, max_length=100, null=True)), + ('terms_seen', models.BooleanField()), + ('description_format', models.TextField()), + ('changesets_count', models.IntegerField()), + ('traces_count', models.IntegerField()), + ('diary_entries_count', models.IntegerField()), + ('image_use_gravatar', models.BooleanField()), + ('auth_provider', models.CharField(blank=True, max_length=100, null=True)), + ('home_tile', models.BigIntegerField(blank=True, null=True)), + ('tou_agreed', models.DateTimeField(blank=True, null=True)), + ], + options={ + 'db_table': 'users', + 'managed': False, + }, + ), + ] diff --git a/images/web_users/app/user/migrations/__init__.py b/images/web_users/app/user/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/images/web_users/app/user/models.py b/images/web_users/app/user/models.py new file mode 100644 index 00000000..334a04e3 --- /dev/null +++ b/images/web_users/app/user/models.py @@ -0,0 +1,29 @@ +from django.db import models +from datetime import datetime + +# Create your models here. +class Users(models.Model): + email = models.CharField(unique=True, max_length=100) + id = models.BigAutoField(primary_key=True) + pass_crypt = models.CharField(max_length=100) + creation_time = models.DateTimeField(default=datetime.now, blank=True) + display_name = models.CharField(unique=True, max_length=100) + data_public = models.BooleanField(default=True) + # description = models.TextField(default="active") + email_valid = models.BooleanField(default=True) + status = models.TextField(default="active") # This field type is a guess. + consider_pd = models.BooleanField(default=True) + terms_seen = models.BooleanField(default=True) + # description_format = models.TextField(default="active") # This field type is a guess. + changesets_count = models.IntegerField(default=0) + traces_count = models.IntegerField(default=0) + diary_entries_count = models.IntegerField(default=0) + image_use_gravatar = models.BooleanField(default=True) + auth_uid = models.CharField(max_length=100, default="xyc") + auth_provider = models.CharField(max_length=100, default="xyc") + + class Meta: + managed = False + db_table = 'users' + unique_together = (('auth_provider', 'auth_uid'),) + diff --git a/images/web_users/app/user/tests.py b/images/web_users/app/user/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/images/web_users/app/user/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/images/web_users/app/user/views.py b/images/web_users/app/user/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/images/web_users/app/user/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From eb2173b8cce5cce9614d91d23a0b717a9e53802d Mon Sep 17 00:00:00 2001 From: Rub21 Date: Wed, 5 Oct 2022 13:25:22 -0500 Subject: [PATCH 02/11] Encode password method --- images/web_users/Dockerfile | 2 ++ images/web_users/app/dashboard/settings.py | 8 +++++++ images/web_users/app/user/models.py | 28 +++++++++++++++------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/images/web_users/Dockerfile b/images/web_users/Dockerfile index c208e6b7..62c7a85e 100644 --- a/images/web_users/Dockerfile +++ b/images/web_users/Dockerfile @@ -7,5 +7,7 @@ RUN apt-get update \ WORKDIR /app COPY app/requirements.txt /app/ RUN pip install -r requirements.txt +RUN python -m pip install django[argon2] COPY app/ /app/ +EXPOSE 8000/tcp CMD ./start.sh diff --git a/images/web_users/app/dashboard/settings.py b/images/web_users/app/dashboard/settings.py index 28aaff7e..bc67e0d2 100644 --- a/images/web_users/app/dashboard/settings.py +++ b/images/web_users/app/dashboard/settings.py @@ -131,3 +131,11 @@ # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +PASSWORD_HASHERS = [ + 'django.contrib.auth.hashers.Argon2PasswordHasher', + 'django.contrib.auth.hashers.PBKDF2PasswordHasher', + 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', + 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', + 'django.contrib.auth.hashers.ScryptPasswordHasher', +] \ No newline at end of file diff --git a/images/web_users/app/user/models.py b/images/web_users/app/user/models.py index 334a04e3..ef46b59e 100644 --- a/images/web_users/app/user/models.py +++ b/images/web_users/app/user/models.py @@ -1,29 +1,39 @@ from django.db import models from datetime import datetime +# from django.contrib.auth.hashers import Argon2PasswordHasher +import django.contrib.auth.hashers as hasher +import argon2, binascii # Create your models here. class Users(models.Model): - email = models.CharField(unique=True, max_length=100) id = models.BigAutoField(primary_key=True) - pass_crypt = models.CharField(max_length=100) - creation_time = models.DateTimeField(default=datetime.now, blank=True) + email = models.CharField(unique=True, max_length=100) display_name = models.CharField(unique=True, max_length=100) + pass_crypt = models.CharField(max_length=100) data_public = models.BooleanField(default=True) - # description = models.TextField(default="active") email_valid = models.BooleanField(default=True) - status = models.TextField(default="active") # This field type is a guess. + status = models.TextField(default="active") consider_pd = models.BooleanField(default=True) terms_seen = models.BooleanField(default=True) - # description_format = models.TextField(default="active") # This field type is a guess. changesets_count = models.IntegerField(default=0) traces_count = models.IntegerField(default=0) diary_entries_count = models.IntegerField(default=0) image_use_gravatar = models.BooleanField(default=True) - auth_uid = models.CharField(max_length=100, default="xyc") - auth_provider = models.CharField(max_length=100, default="xyc") + terms_agreed = models.DateTimeField(default=datetime.now, null=True) + tou_agreed = models.DateTimeField(default=datetime.now, null=True) + creation_time = models.DateTimeField(default=datetime.now, blank=True) class Meta: managed = False db_table = 'users' - unique_together = (('auth_provider', 'auth_uid'),) + # unique_together = (('auth_provider', 'auth_uid'),) + + def save(self, *args, **kwargs): + # self.pass_crypt = Argon2PasswordHasher(self.pass_crypt) + # self.pass_crypt = hasher.Argon2PasswordHasher.encode(self, self.pass_crypt, None) + argon2Hasher = argon2.PasswordHasher(time_cost=16, memory_cost=2**16, parallelism=2, hash_len=32, salt_len=16) + self.pass_crypt = argon2Hasher.hash(self.pass_crypt) + print(self.pass_crypt) + super(Users, self).save(*args, **kwargs) + From 00469abefd0e7f5ffda7740303740e2f87acb3e7 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Thu, 6 Oct 2022 09:28:35 -0500 Subject: [PATCH 03/11] Forms for user creation --- images/web_users/app/dashboard/settings.py | 11 +++++++++-- images/web_users/app/requirements.txt | 4 +++- images/web_users/app/start.sh | 2 +- images/web_users/app/user/admin.py | 5 ++++- images/web_users/app/user/forms.py | 21 ++++++++++++++++++++ images/web_users/app/user/models.py | 23 ++++++---------------- 6 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 images/web_users/app/user/forms.py diff --git a/images/web_users/app/dashboard/settings.py b/images/web_users/app/dashboard/settings.py index bc67e0d2..a27a6ff6 100644 --- a/images/web_users/app/dashboard/settings.py +++ b/images/web_users/app/dashboard/settings.py @@ -137,5 +137,12 @@ 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', - 'django.contrib.auth.hashers.ScryptPasswordHasher', -] \ No newline at end of file + # 'django.contrib.auth.hashers.ScryptPasswordHasher', +] + +# PASSWORD_HASHERS = [ +# 'django.contrib.auth.hashers.PBKDF2PasswordHasher', +# 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', +# 'django.contrib.auth.hashers.Argon2PasswordHasher', +# 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', +# ] \ No newline at end of file diff --git a/images/web_users/app/requirements.txt b/images/web_users/app/requirements.txt index 978f1b78..62466907 100644 --- a/images/web_users/app/requirements.txt +++ b/images/web_users/app/requirements.txt @@ -1,2 +1,4 @@ Django>=3.0,<4.0 -psycopg2>=2.8 \ No newline at end of file +psycopg2>=2.8 +argon2-cffi==21.3.0 +django-scrypt==0.2.3 \ No newline at end of file diff --git a/images/web_users/app/start.sh b/images/web_users/app/start.sh index 1508b891..9e25dd06 100755 --- a/images/web_users/app/start.sh +++ b/images/web_users/app/start.sh @@ -10,7 +10,7 @@ export DJANGO_SUPERUSER_EMAIL="admi3n@admin.com" function startApp () { # python manage.py inspectdb > models.py python manage.py migrate - python manage.py createsuperuser --noinputs + python manage.py createsuperuser --no-input python manage.py runserver 0.0.0.0:8000 } diff --git a/images/web_users/app/user/admin.py b/images/web_users/app/user/admin.py index e7a3c944..8237c827 100644 --- a/images/web_users/app/user/admin.py +++ b/images/web_users/app/user/admin.py @@ -1,8 +1,11 @@ from django.contrib import admin from .models import Users +from .forms import UsersForm # Register your models here. class UserAdmin(admin.ModelAdmin): - list_display = ('email', 'id', 'display_name', 'status') + list_display = ("email", "id", "display_name", "status") + form = UsersForm + admin.site.register(Users, UserAdmin) \ No newline at end of file diff --git a/images/web_users/app/user/forms.py b/images/web_users/app/user/forms.py new file mode 100644 index 00000000..4ec8b3b6 --- /dev/null +++ b/images/web_users/app/user/forms.py @@ -0,0 +1,21 @@ +from .models import Users +from django import forms + +FRUIT_CHOICES = [ + ("active", "Active"), + ("pending", "Pendig"), + ("confirmed", "Confirmed"), + ("suspended", "Suspended"), + ("deleted", "Deleted"), +] + + +class UsersForm(forms.ModelForm): + email = forms.EmailField(help_text="Enter a valid email address.") + pass_crypt = forms.CharField(label="Password", required=True) + display_name = forms.CharField(label="User name", required=True) + status = forms.CharField(label="Status", widget=forms.Select(choices=FRUIT_CHOICES)) + + class Meta: + model = Users + fields = ["email", "display_name", "pass_crypt", "status"] diff --git a/images/web_users/app/user/models.py b/images/web_users/app/user/models.py index ef46b59e..31a65dc2 100644 --- a/images/web_users/app/user/models.py +++ b/images/web_users/app/user/models.py @@ -1,8 +1,6 @@ from django.db import models from datetime import datetime -# from django.contrib.auth.hashers import Argon2PasswordHasher -import django.contrib.auth.hashers as hasher -import argon2, binascii +import argon2 # Create your models here. class Users(models.Model): @@ -12,28 +10,19 @@ class Users(models.Model): pass_crypt = models.CharField(max_length=100) data_public = models.BooleanField(default=True) email_valid = models.BooleanField(default=True) - status = models.TextField(default="active") - consider_pd = models.BooleanField(default=True) + status = models.CharField(default="active", max_length=20) terms_seen = models.BooleanField(default=True) - changesets_count = models.IntegerField(default=0) - traces_count = models.IntegerField(default=0) - diary_entries_count = models.IntegerField(default=0) - image_use_gravatar = models.BooleanField(default=True) terms_agreed = models.DateTimeField(default=datetime.now, null=True) tou_agreed = models.DateTimeField(default=datetime.now, null=True) creation_time = models.DateTimeField(default=datetime.now, blank=True) class Meta: managed = False - db_table = 'users' - # unique_together = (('auth_provider', 'auth_uid'),) + db_table = "users" def save(self, *args, **kwargs): - # self.pass_crypt = Argon2PasswordHasher(self.pass_crypt) - # self.pass_crypt = hasher.Argon2PasswordHasher.encode(self, self.pass_crypt, None) - argon2Hasher = argon2.PasswordHasher(time_cost=16, memory_cost=2**16, parallelism=2, hash_len=32, salt_len=16) + argon2Hasher = argon2.PasswordHasher( + time_cost=16, memory_cost=2 ** 16, parallelism=2, hash_len=32, salt_len=16 + ) self.pass_crypt = argon2Hasher.hash(self.pass_crypt) - print(self.pass_crypt) super(Users, self).save(*args, **kwargs) - - From 3a9ca5a80f284644340eb71ca487eed5e4ecd8cc Mon Sep 17 00:00:00 2001 From: Rub21 Date: Thu, 6 Oct 2022 09:54:44 -0500 Subject: [PATCH 04/11] Update var name --- images/web_users/app/user/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/web_users/app/user/forms.py b/images/web_users/app/user/forms.py index 4ec8b3b6..f979a3d4 100644 --- a/images/web_users/app/user/forms.py +++ b/images/web_users/app/user/forms.py @@ -1,7 +1,7 @@ from .models import Users from django import forms -FRUIT_CHOICES = [ +USER_STATUS = [ ("active", "Active"), ("pending", "Pendig"), ("confirmed", "Confirmed"), @@ -14,7 +14,7 @@ class UsersForm(forms.ModelForm): email = forms.EmailField(help_text="Enter a valid email address.") pass_crypt = forms.CharField(label="Password", required=True) display_name = forms.CharField(label="User name", required=True) - status = forms.CharField(label="Status", widget=forms.Select(choices=FRUIT_CHOICES)) + status = forms.CharField(label="Status", widget=forms.Select(choices=USER_STATUS)) class Meta: model = Users From af214bc7886c1828be9ceed7374dce0abf7d0852 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Fri, 21 Oct 2022 13:27:49 -0500 Subject: [PATCH 05/11] Update dashboard --- compose/web.yml | 13 +- images/web_dashboard/Dockerfile | 26 +++ images/web_dashboard/Dockerfile copy | 17 ++ images/web_dashboard/Dockerfile copy 2 | 19 +++ .../app/dashboard/__init__.py | 0 .../app/dashboard/asgi.py | 0 .../web_dashboard/app/dashboard/settings.py | 157 ++++++++++++++++++ .../app/dashboard/urls.py | 0 .../app/dashboard/wsgi.py | 0 .../app/manage.py | 0 .../app/requirements.txt | 3 +- images/web_dashboard/app/start.sh | 17 ++ .../app/user/__init__.py | 0 .../app/user/admin.py | 0 .../app/user/apps.py | 0 .../app/user/forms.py | 0 .../app/user/migrations/0001_initial.py | 0 .../app/user/migrations/__init__.py | 0 .../app/user/models.py | 2 + .../app/user/tests.py | 0 .../app/user/views.py | 0 images/web_users/Dockerfile | 13 -- images/web_users/app/dashboard/settings.py | 148 ----------------- images/web_users/app/start.sh | 25 --- 24 files changed, 247 insertions(+), 193 deletions(-) create mode 100644 images/web_dashboard/Dockerfile create mode 100644 images/web_dashboard/Dockerfile copy create mode 100644 images/web_dashboard/Dockerfile copy 2 rename images/{web_users => web_dashboard}/app/dashboard/__init__.py (100%) rename images/{web_users => web_dashboard}/app/dashboard/asgi.py (100%) create mode 100644 images/web_dashboard/app/dashboard/settings.py rename images/{web_users => web_dashboard}/app/dashboard/urls.py (100%) rename images/{web_users => web_dashboard}/app/dashboard/wsgi.py (100%) rename images/{web_users => web_dashboard}/app/manage.py (100%) rename images/{web_users => web_dashboard}/app/requirements.txt (59%) create mode 100755 images/web_dashboard/app/start.sh rename images/{web_users => web_dashboard}/app/user/__init__.py (100%) rename images/{web_users => web_dashboard}/app/user/admin.py (100%) rename images/{web_users => web_dashboard}/app/user/apps.py (100%) rename images/{web_users => web_dashboard}/app/user/forms.py (100%) rename images/{web_users => web_dashboard}/app/user/migrations/0001_initial.py (100%) rename images/{web_users => web_dashboard}/app/user/migrations/__init__.py (100%) rename images/{web_users => web_dashboard}/app/user/models.py (96%) rename images/{web_users => web_dashboard}/app/user/tests.py (100%) rename images/{web_users => web_dashboard}/app/user/views.py (100%) delete mode 100644 images/web_users/Dockerfile delete mode 100644 images/web_users/app/dashboard/settings.py delete mode 100755 images/web_users/app/start.sh diff --git a/compose/web.yml b/compose/web.yml index 42fc8060..c811b799 100644 --- a/compose/web.yml +++ b/compose/web.yml @@ -27,15 +27,16 @@ services: - ../envs/.env.db depends_on: - db - web_users: - build: ../images/web_users + web_dashboard: + build: ../images/web_dashboard volumes: - - ../images/web_users/app/:/app + - ../data/web_bashboard-data:/var/lib/postgresql/data + - ../images/web_dashboard/app/:/app ports: - - '8000:8000' + - 8000:8000 + - 5433:5432 env_file: - - ../envs/.env.web - - ../envs/.env.db + - ../envs/.env.web_dashboard depends_on: - db working_dir: /app diff --git a/images/web_dashboard/Dockerfile b/images/web_dashboard/Dockerfile new file mode 100644 index 00000000..00bf5afc --- /dev/null +++ b/images/web_dashboard/Dockerfile @@ -0,0 +1,26 @@ +FROM postgres:12 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +RUN apt-get update -qq +RUN apt-get -y install \ + build-essential libpq-dev \ + python3-dev python3-pip curl sudo + +WORKDIR /app +COPY app/requirements.txt /app/ +RUN pip install -r requirements.txt +COPY app/ /app/ +# COPY start.sh /app/ + +# sed -n "x p" dump.sql + +# RUN echo "echo \"==========Start App==========\"" >> /usr/local/bin/docker-entrypoint.sh +# RUN echo "./app/start.sh" >> /usr/local/bin/docker-entrypoint.sh + +# COPY start.sh /usr/local/bin/ +EXPOSE 5433 +EXPOSE 8000 + +ENTRYPOINT ["sh","/app/start.sh"] +# CMD /app/start.sh diff --git a/images/web_dashboard/Dockerfile copy b/images/web_dashboard/Dockerfile copy new file mode 100644 index 00000000..54355187 --- /dev/null +++ b/images/web_dashboard/Dockerfile copy @@ -0,0 +1,17 @@ +# FROM postgres:12 +# ENV PYTHONDONTWRITEBYTECODE=1 +# ENV PYTHONUNBUFFERED=1 + +# RUN apt-get update -qq +# RUN apt-get -y install \ +# build-essential libpq-dev \ +# python3-dev python3-pip curl sudo + +# WORKDIR /app +# COPY app/requirements.txt /app/ +# RUN pip install -r requirements.txt +# COPY app/ /app/ +# # COPY start.sh /app/ +# EXPOSE 5433 +# EXPOSE 8000 +# CMD ./start.sh diff --git a/images/web_dashboard/Dockerfile copy 2 b/images/web_dashboard/Dockerfile copy 2 new file mode 100644 index 00000000..6b9f37a7 --- /dev/null +++ b/images/web_dashboard/Dockerfile copy 2 @@ -0,0 +1,19 @@ +FROM python:3 +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + + +RUN apt-get update && apt-get -y install wget ca-certificates lsb-release +RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - +RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + +RUN apt-get update +RUN apt-get -y install postgresql-14 postgresql-contrib + +WORKDIR /app +COPY app/requirements.txt /app/ +RUN pip install -r requirements.txt +RUN python -m pip install django[argon2] +COPY app/ /app/ +EXPOSE 8000/tcp +CMD ./start.sh \ No newline at end of file diff --git a/images/web_users/app/dashboard/__init__.py b/images/web_dashboard/app/dashboard/__init__.py similarity index 100% rename from images/web_users/app/dashboard/__init__.py rename to images/web_dashboard/app/dashboard/__init__.py diff --git a/images/web_users/app/dashboard/asgi.py b/images/web_dashboard/app/dashboard/asgi.py similarity index 100% rename from images/web_users/app/dashboard/asgi.py rename to images/web_dashboard/app/dashboard/asgi.py diff --git a/images/web_dashboard/app/dashboard/settings.py b/images/web_dashboard/app/dashboard/settings.py new file mode 100644 index 00000000..86c8efea --- /dev/null +++ b/images/web_dashboard/app/dashboard/settings.py @@ -0,0 +1,157 @@ +""" +Django settings for dashboard project. + +Generated by 'django-admin startproject' using Django 3.2.16. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-acnap5f@i4v7^m2$ed0%i10ta%)1xza%k!zp-42%k*$tb6rt$%" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "user", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "dashboard.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "dashboard.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': BASE_DIR / 'db.sqlite3', + # } + "default": { + "ENGINE": "django.db.backends.postgresql", + "NAME": os.environ.get("POSTGRES_DB"), + "USER": os.environ.get("POSTGRES_USER"), + "PASSWORD": os.environ.get("POSTGRES_PASSWORD"), + "HOST": os.environ.get("POSTGRES_HOST"), + "PORT": os.environ.get("POSTGRES_PORT"), + }, + "osm_api": { + "ENGINE": "django.db.backends.postgresql", + "NAME": os.environ.get("API_DB_POSTGRES_DB"), + "USER": os.environ.get("API_DB_POSTGRES_USER"), + "PASSWORD": os.environ.get("API_DB_POSTGRES_PASSWORD"), + "HOST": os.environ.get("API_DB_POSTGRES_HOST"), + "PORT": os.environ.get("API_DB_POSTGRES_PORT"), + }, +} + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = "/static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +PASSWORD_HASHERS = [ + "django.contrib.auth.hashers.Argon2PasswordHasher", + "django.contrib.auth.hashers.PBKDF2PasswordHasher", + "django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher", + "django.contrib.auth.hashers.BCryptSHA256PasswordHasher", + # 'django.contrib.auth.hashers.ScryptPasswordHasher', +] + +# PASSWORD_HASHERS = [ +# 'django.contrib.auth.hashers.PBKDF2PasswordHasher', +# 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', +# 'django.contrib.auth.hashers.Argon2PasswordHasher', +# 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', +# ] \ No newline at end of file diff --git a/images/web_users/app/dashboard/urls.py b/images/web_dashboard/app/dashboard/urls.py similarity index 100% rename from images/web_users/app/dashboard/urls.py rename to images/web_dashboard/app/dashboard/urls.py diff --git a/images/web_users/app/dashboard/wsgi.py b/images/web_dashboard/app/dashboard/wsgi.py similarity index 100% rename from images/web_users/app/dashboard/wsgi.py rename to images/web_dashboard/app/dashboard/wsgi.py diff --git a/images/web_users/app/manage.py b/images/web_dashboard/app/manage.py similarity index 100% rename from images/web_users/app/manage.py rename to images/web_dashboard/app/manage.py diff --git a/images/web_users/app/requirements.txt b/images/web_dashboard/app/requirements.txt similarity index 59% rename from images/web_users/app/requirements.txt rename to images/web_dashboard/app/requirements.txt index 62466907..5232acc3 100644 --- a/images/web_users/app/requirements.txt +++ b/images/web_dashboard/app/requirements.txt @@ -1,4 +1,5 @@ Django>=3.0,<4.0 psycopg2>=2.8 argon2-cffi==21.3.0 -django-scrypt==0.2.3 \ No newline at end of file +django-scrypt==0.2.3 +django[argon2] \ No newline at end of file diff --git a/images/web_dashboard/app/start.sh b/images/web_dashboard/app/start.sh new file mode 100755 index 00000000..967380f8 --- /dev/null +++ b/images/web_dashboard/app/start.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -e +export POSTGRES_HOST=localhost +export POSTGRES_DB=dashboard +export POSTGRES_USER=postgres +export POSTGRES_PORT=5432 +# POSTGRES_PASSWORD, comes from env var +flag=true +/usr/local/bin/docker-entrypoint.sh "postgres" & +while "$flag" = true; do + pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT >/dev/null 2>&2 || continue + flag=false + echo "===================Start app=======================" + python3 manage.py migrate + python3 manage.py createsuperuser --no-input + python3 manage.py runserver 0.0.0.0:8000 +done diff --git a/images/web_users/app/user/__init__.py b/images/web_dashboard/app/user/__init__.py similarity index 100% rename from images/web_users/app/user/__init__.py rename to images/web_dashboard/app/user/__init__.py diff --git a/images/web_users/app/user/admin.py b/images/web_dashboard/app/user/admin.py similarity index 100% rename from images/web_users/app/user/admin.py rename to images/web_dashboard/app/user/admin.py diff --git a/images/web_users/app/user/apps.py b/images/web_dashboard/app/user/apps.py similarity index 100% rename from images/web_users/app/user/apps.py rename to images/web_dashboard/app/user/apps.py diff --git a/images/web_users/app/user/forms.py b/images/web_dashboard/app/user/forms.py similarity index 100% rename from images/web_users/app/user/forms.py rename to images/web_dashboard/app/user/forms.py diff --git a/images/web_users/app/user/migrations/0001_initial.py b/images/web_dashboard/app/user/migrations/0001_initial.py similarity index 100% rename from images/web_users/app/user/migrations/0001_initial.py rename to images/web_dashboard/app/user/migrations/0001_initial.py diff --git a/images/web_users/app/user/migrations/__init__.py b/images/web_dashboard/app/user/migrations/__init__.py similarity index 100% rename from images/web_users/app/user/migrations/__init__.py rename to images/web_dashboard/app/user/migrations/__init__.py diff --git a/images/web_users/app/user/models.py b/images/web_dashboard/app/user/models.py similarity index 96% rename from images/web_users/app/user/models.py rename to images/web_dashboard/app/user/models.py index 31a65dc2..a1ba1271 100644 --- a/images/web_users/app/user/models.py +++ b/images/web_dashboard/app/user/models.py @@ -26,3 +26,5 @@ def save(self, *args, **kwargs): ) self.pass_crypt = argon2Hasher.hash(self.pass_crypt) super(Users, self).save(*args, **kwargs) + +Users.objects = Users.objects.using('osm_api') \ No newline at end of file diff --git a/images/web_users/app/user/tests.py b/images/web_dashboard/app/user/tests.py similarity index 100% rename from images/web_users/app/user/tests.py rename to images/web_dashboard/app/user/tests.py diff --git a/images/web_users/app/user/views.py b/images/web_dashboard/app/user/views.py similarity index 100% rename from images/web_users/app/user/views.py rename to images/web_dashboard/app/user/views.py diff --git a/images/web_users/Dockerfile b/images/web_users/Dockerfile deleted file mode 100644 index 62c7a85e..00000000 --- a/images/web_users/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM python:3 -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 -RUN apt-get update \ - && apt-get install -y postgresql-client - -WORKDIR /app -COPY app/requirements.txt /app/ -RUN pip install -r requirements.txt -RUN python -m pip install django[argon2] -COPY app/ /app/ -EXPOSE 8000/tcp -CMD ./start.sh diff --git a/images/web_users/app/dashboard/settings.py b/images/web_users/app/dashboard/settings.py deleted file mode 100644 index a27a6ff6..00000000 --- a/images/web_users/app/dashboard/settings.py +++ /dev/null @@ -1,148 +0,0 @@ -""" -Django settings for dashboard project. - -Generated by 'django-admin startproject' using Django 3.2.16. - -For more information on this file, see -https://docs.djangoproject.com/en/3.2/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/3.2/ref/settings/ -""" - -from pathlib import Path -import os -# Build paths inside the project like this: BASE_DIR / 'subdir'. -BASE_DIR = Path(__file__).resolve().parent.parent - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-acnap5f@i4v7^m2$ed0%i10ta%)1xza%k!zp-42%k*$tb6rt$%' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'user' -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'dashboard.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = 'dashboard.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/3.2/ref/settings/#databases - -DATABASES = { - # 'default': { - # 'ENGINE': 'django.db.backends.sqlite3', - # 'NAME': BASE_DIR / 'db.sqlite3', - # } - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': os.environ.get('POSTGRES_DB'), - 'USER': os.environ.get('POSTGRES_USER'), - 'PASSWORD': os.environ.get('POSTGRES_PASSWORD'), - 'HOST': os.environ.get('POSTGRES_HOST'), - 'PORT': '5432', - } -} - -# Password validation -# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/3.2/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.2/howto/static-files/ - -STATIC_URL = '/static/' - -# Default primary key field type -# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field - -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' - -PASSWORD_HASHERS = [ - 'django.contrib.auth.hashers.Argon2PasswordHasher', - 'django.contrib.auth.hashers.PBKDF2PasswordHasher', - 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', - 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', - # 'django.contrib.auth.hashers.ScryptPasswordHasher', -] - -# PASSWORD_HASHERS = [ -# 'django.contrib.auth.hashers.PBKDF2PasswordHasher', -# 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', -# 'django.contrib.auth.hashers.Argon2PasswordHasher', -# 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', -# ] \ No newline at end of file diff --git a/images/web_users/app/start.sh b/images/web_users/app/start.sh deleted file mode 100755 index 9e25dd06..00000000 --- a/images/web_users/app/start.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -e -export DEBUG=1 -export SECRET_KEY=foo -export DJANGO_ALLOWED_HOSTS="localhost 127.0.0.1 [::1]" -export DJANGO_SUPERUSER_USERNAME=admin3 -export DJANGO_SUPERUSER_PASSWORD=1234 -export DJANGO_SUPERUSER_EMAIL="admi3n@admin.com" - -function startApp () { - # python manage.py inspectdb > models.py - python manage.py migrate - python manage.py createsuperuser --no-input - python manage.py runserver 0.0.0.0:8000 -} - -flag=true -while "$flag" = true; do - pg_isready -h $POSTGRES_HOST -p 5432 >/dev/null 2>&2 || continue - flag=false - until $(curl -sf -o /dev/null $SERVER_URL); do - echo "Waiting to start rails ports server..." - sleep 2 - done & startApp -done From 8dfe6f9bad97229f25e446ba3f2130cff59bf36f Mon Sep 17 00:00:00 2001 From: Rub21 Date: Tue, 8 Nov 2022 15:37:19 -0500 Subject: [PATCH 06/11] Update container --- envs/.env.web_dashboard.example | 10 ++++++++++ images/web_dashboard/Dockerfile | 13 +++---------- images/web_dashboard/Dockerfile copy | 17 ----------------- images/web_dashboard/Dockerfile copy 2 | 19 ------------------- images/web_dashboard/README.md | 0 images/web_dashboard/app/start.sh | 1 + 6 files changed, 14 insertions(+), 46 deletions(-) create mode 100644 envs/.env.web_dashboard.example delete mode 100644 images/web_dashboard/Dockerfile copy delete mode 100644 images/web_dashboard/Dockerfile copy 2 create mode 100644 images/web_dashboard/README.md diff --git a/envs/.env.web_dashboard.example b/envs/.env.web_dashboard.example new file mode 100644 index 00000000..51975506 --- /dev/null +++ b/envs/.env.web_dashboard.example @@ -0,0 +1,10 @@ +# Local DB setup +POSTGRES_DB=db_osm +POSTGRES_USER=postgres +POSTGRES_PASSWORD=1234 + +SECRET_KEY=foo +DJANGO_ALLOWED_HOSTS="localhost 127.0.0.1 [::1]" +DJANGO_SUPERUSER_USERNAME=admin +DJANGO_SUPERUSER_PASSWORD=1234 +DJANGO_SUPERUSER_EMAIL="admin@admin.com" \ No newline at end of file diff --git a/images/web_dashboard/Dockerfile b/images/web_dashboard/Dockerfile index 00bf5afc..e79a2c54 100644 --- a/images/web_dashboard/Dockerfile +++ b/images/web_dashboard/Dockerfile @@ -12,15 +12,8 @@ COPY app/requirements.txt /app/ RUN pip install -r requirements.txt COPY app/ /app/ # COPY start.sh /app/ - -# sed -n "x p" dump.sql - -# RUN echo "echo \"==========Start App==========\"" >> /usr/local/bin/docker-entrypoint.sh -# RUN echo "./app/start.sh" >> /usr/local/bin/docker-entrypoint.sh - -# COPY start.sh /usr/local/bin/ EXPOSE 5433 EXPOSE 8000 - -ENTRYPOINT ["sh","/app/start.sh"] -# CMD /app/start.sh +# ENTRYPOINT ["sh","/app/start.sh"] +ENTRYPOINT ["sh"] +CMD /app/start.sh diff --git a/images/web_dashboard/Dockerfile copy b/images/web_dashboard/Dockerfile copy deleted file mode 100644 index 54355187..00000000 --- a/images/web_dashboard/Dockerfile copy +++ /dev/null @@ -1,17 +0,0 @@ -# FROM postgres:12 -# ENV PYTHONDONTWRITEBYTECODE=1 -# ENV PYTHONUNBUFFERED=1 - -# RUN apt-get update -qq -# RUN apt-get -y install \ -# build-essential libpq-dev \ -# python3-dev python3-pip curl sudo - -# WORKDIR /app -# COPY app/requirements.txt /app/ -# RUN pip install -r requirements.txt -# COPY app/ /app/ -# # COPY start.sh /app/ -# EXPOSE 5433 -# EXPOSE 8000 -# CMD ./start.sh diff --git a/images/web_dashboard/Dockerfile copy 2 b/images/web_dashboard/Dockerfile copy 2 deleted file mode 100644 index 6b9f37a7..00000000 --- a/images/web_dashboard/Dockerfile copy 2 +++ /dev/null @@ -1,19 +0,0 @@ -FROM python:3 -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 - - -RUN apt-get update && apt-get -y install wget ca-certificates lsb-release -RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - -RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' - -RUN apt-get update -RUN apt-get -y install postgresql-14 postgresql-contrib - -WORKDIR /app -COPY app/requirements.txt /app/ -RUN pip install -r requirements.txt -RUN python -m pip install django[argon2] -COPY app/ /app/ -EXPOSE 8000/tcp -CMD ./start.sh \ No newline at end of file diff --git a/images/web_dashboard/README.md b/images/web_dashboard/README.md new file mode 100644 index 00000000..e69de29b diff --git a/images/web_dashboard/app/start.sh b/images/web_dashboard/app/start.sh index 967380f8..40efd7d6 100755 --- a/images/web_dashboard/app/start.sh +++ b/images/web_dashboard/app/start.sh @@ -13,5 +13,6 @@ while "$flag" = true; do echo "===================Start app=======================" python3 manage.py migrate python3 manage.py createsuperuser --no-input + python3 manage.py migrate --database=osm_api python3 manage.py runserver 0.0.0.0:8000 done From 21cdb3ee21e757521975cfce5b6ebd7dbed051b6 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Wed, 23 Nov 2022 15:44:17 -0500 Subject: [PATCH 07/11] Add extra DB --- images/web_dashboard/Dockerfile | 1 - images/web_dashboard/README.md | 10 ++++++++++ images/web_dashboard/app/dashboard/settings.py | 2 ++ images/web_dashboard/app/start.sh | 7 +++++++ images/web_dashboard/app/user/dbrouters.py | 13 +++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 images/web_dashboard/app/user/dbrouters.py diff --git a/images/web_dashboard/Dockerfile b/images/web_dashboard/Dockerfile index e79a2c54..aa76a981 100644 --- a/images/web_dashboard/Dockerfile +++ b/images/web_dashboard/Dockerfile @@ -11,7 +11,6 @@ WORKDIR /app COPY app/requirements.txt /app/ RUN pip install -r requirements.txt COPY app/ /app/ -# COPY start.sh /app/ EXPOSE 5433 EXPOSE 8000 # ENTRYPOINT ["sh","/app/start.sh"] diff --git a/images/web_dashboard/README.md b/images/web_dashboard/README.md index e69de29b..6c0cb55c 100644 --- a/images/web_dashboard/README.md +++ b/images/web_dashboard/README.md @@ -0,0 +1,10 @@ +# Web dashbord +This container is for user management in the Web APi database. + +- Development mode + +``` +docker-compose -f compose/web.yml up db +docker-compose -f compose/web.yml up web +docker-compose -f compose/web.yml run --service-ports web_dashboard bash +`` \ No newline at end of file diff --git a/images/web_dashboard/app/dashboard/settings.py b/images/web_dashboard/app/dashboard/settings.py index 86c8efea..34a4514e 100644 --- a/images/web_dashboard/app/dashboard/settings.py +++ b/images/web_dashboard/app/dashboard/settings.py @@ -117,6 +117,8 @@ ] +DATABASE_ROUTERS = ("user.dbrouters.AccountsDBRouter",) + # Internationalization # https://docs.djangoproject.com/en/3.2/topics/i18n/ diff --git a/images/web_dashboard/app/start.sh b/images/web_dashboard/app/start.sh index 40efd7d6..8656bb98 100755 --- a/images/web_dashboard/app/start.sh +++ b/images/web_dashboard/app/start.sh @@ -5,6 +5,13 @@ export POSTGRES_DB=dashboard export POSTGRES_USER=postgres export POSTGRES_PORT=5432 # POSTGRES_PASSWORD, comes from env var + + export API_DB_POSTGRES_HOST=host.docker.internal + export API_DB_POSTGRES_DB=openstreetmap + export API_DB_POSTGRES_USER=postgres + export API_DB_POSTGRES_PASSWORD=1234 + export API_DB_POSTGRES_PORT=5432 + flag=true /usr/local/bin/docker-entrypoint.sh "postgres" & while "$flag" = true; do diff --git a/images/web_dashboard/app/user/dbrouters.py b/images/web_dashboard/app/user/dbrouters.py new file mode 100644 index 00000000..824ae707 --- /dev/null +++ b/images/web_dashboard/app/user/dbrouters.py @@ -0,0 +1,13 @@ +from .models import Users + + +class AccountsDBRouter: + def db_for_read(self, model, **hints): + if model == Users: + return "osm_api" + return None + + def db_for_write(self, model, **hints): + if model == Users: + return "osm_api" + return None From 37134621e42a97214a9636cfa814d8bcad66d935 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Fri, 25 Nov 2022 13:41:34 -0500 Subject: [PATCH 08/11] Avoid to update password --- images/web_dashboard/app/dashboard/urls.py | 4 +++- images/web_dashboard/app/user/admin.py | 3 +-- images/web_dashboard/app/user/forms.py | 8 +++++++- images/web_dashboard/app/user/models.py | 14 ++++++++++++-- images/web_dashboard/app/user/views.py | 2 -- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/images/web_dashboard/app/dashboard/urls.py b/images/web_dashboard/app/dashboard/urls.py index 00198055..84a2b2ac 100644 --- a/images/web_dashboard/app/dashboard/urls.py +++ b/images/web_dashboard/app/dashboard/urls.py @@ -14,8 +14,10 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include +admin.site.site_header = 'OSM-Seed Administration' urlpatterns = [ path('admin/', admin.site.urls), + path("", admin.site.login), ] diff --git a/images/web_dashboard/app/user/admin.py b/images/web_dashboard/app/user/admin.py index 8237c827..84505a32 100644 --- a/images/web_dashboard/app/user/admin.py +++ b/images/web_dashboard/app/user/admin.py @@ -7,5 +7,4 @@ class UserAdmin(admin.ModelAdmin): list_display = ("email", "id", "display_name", "status") form = UsersForm - -admin.site.register(Users, UserAdmin) \ No newline at end of file +admin.site.register(Users, UserAdmin) diff --git a/images/web_dashboard/app/user/forms.py b/images/web_dashboard/app/user/forms.py index f979a3d4..ad2ea906 100644 --- a/images/web_dashboard/app/user/forms.py +++ b/images/web_dashboard/app/user/forms.py @@ -12,10 +12,16 @@ class UsersForm(forms.ModelForm): email = forms.EmailField(help_text="Enter a valid email address.") - pass_crypt = forms.CharField(label="Password", required=True) + pass_crypt = forms.CharField( + widget=forms.PasswordInput( + attrs={"class": "form-control", "placeholder": "please enter password"} + ) + ) display_name = forms.CharField(label="User name", required=True) status = forms.CharField(label="Status", widget=forms.Select(choices=USER_STATUS)) class Meta: model = Users fields = ["email", "display_name", "pass_crypt", "status"] + + \ No newline at end of file diff --git a/images/web_dashboard/app/user/models.py b/images/web_dashboard/app/user/models.py index a1ba1271..c95b0775 100644 --- a/images/web_dashboard/app/user/models.py +++ b/images/web_dashboard/app/user/models.py @@ -19,12 +19,22 @@ class Users(models.Model): class Meta: managed = False db_table = "users" + verbose_name_plural = "OSM Users" def save(self, *args, **kwargs): argon2Hasher = argon2.PasswordHasher( time_cost=16, memory_cost=2 ** 16, parallelism=2, hash_len=32, salt_len=16 ) self.pass_crypt = argon2Hasher.hash(self.pass_crypt) - super(Users, self).save(*args, **kwargs) + if self._state.adding: + super(Users, self).save( + *args, + **kwargs, + ) + else: + super(Users, self).save( + *args, **kwargs, update_fields=["email", "display_name", "status"] + ) -Users.objects = Users.objects.using('osm_api') \ No newline at end of file + +Users.objects = Users.objects.using("osm_api") diff --git a/images/web_dashboard/app/user/views.py b/images/web_dashboard/app/user/views.py index 91ea44a2..2536b376 100644 --- a/images/web_dashboard/app/user/views.py +++ b/images/web_dashboard/app/user/views.py @@ -1,3 +1 @@ from django.shortcuts import render - -# Create your views here. From 8569d317729e304ba1df1a27a6a97c09a5f577f6 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Fri, 25 Nov 2022 13:49:37 -0500 Subject: [PATCH 09/11] Add changeset count column --- images/web_dashboard/app/user/admin.py | 2 +- images/web_dashboard/app/user/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/web_dashboard/app/user/admin.py b/images/web_dashboard/app/user/admin.py index 84505a32..7f441bc8 100644 --- a/images/web_dashboard/app/user/admin.py +++ b/images/web_dashboard/app/user/admin.py @@ -4,7 +4,7 @@ # Register your models here. class UserAdmin(admin.ModelAdmin): - list_display = ("email", "id", "display_name", "status") + list_display = ("email", "id", "display_name", "status", "changesets_count") form = UsersForm admin.site.register(Users, UserAdmin) diff --git a/images/web_dashboard/app/user/models.py b/images/web_dashboard/app/user/models.py index c95b0775..5024e5c7 100644 --- a/images/web_dashboard/app/user/models.py +++ b/images/web_dashboard/app/user/models.py @@ -15,7 +15,7 @@ class Users(models.Model): terms_agreed = models.DateTimeField(default=datetime.now, null=True) tou_agreed = models.DateTimeField(default=datetime.now, null=True) creation_time = models.DateTimeField(default=datetime.now, blank=True) - + changesets_count = models.IntegerField(default=0) class Meta: managed = False db_table = "users" From fb6cf2ec0c76977f1ee2d2b879664c76e0c5f42c Mon Sep 17 00:00:00 2001 From: Rub21 Date: Mon, 28 Nov 2022 09:48:01 -0500 Subject: [PATCH 10/11] Update django app - container --- compose/web.yml | 2 +- envs/.env.web_dashboard.example | 18 +++-- images/web_dashboard/Dockerfile | 6 +- images/web_dashboard/app/dashboard/asgi.py | 2 +- .../web_dashboard/app/dashboard/settings.py | 13 +--- images/web_dashboard/app/dashboard/urls.py | 4 +- images/web_dashboard/app/dashboard/wsgi.py | 2 +- images/web_dashboard/app/start.sh | 14 +--- images/web_dashboard/app/user/admin.py | 1 + images/web_dashboard/app/user/apps.py | 4 +- images/web_dashboard/app/user/forms.py | 2 - .../app/user/migrations/0001_initial.py | 76 ++++++++++--------- images/web_dashboard/app/user/models.py | 4 + 13 files changed, 72 insertions(+), 76 deletions(-) diff --git a/compose/web.yml b/compose/web.yml index c811b799..40a301f7 100644 --- a/compose/web.yml +++ b/compose/web.yml @@ -31,7 +31,7 @@ services: build: ../images/web_dashboard volumes: - ../data/web_bashboard-data:/var/lib/postgresql/data - - ../images/web_dashboard/app/:/app + # - ../images/web_dashboard/app/:/app ports: - 8000:8000 - 5433:5432 diff --git a/envs/.env.web_dashboard.example b/envs/.env.web_dashboard.example index 51975506..ff631814 100644 --- a/envs/.env.web_dashboard.example +++ b/envs/.env.web_dashboard.example @@ -1,10 +1,18 @@ # Local DB setup -POSTGRES_DB=db_osm -POSTGRES_USER=postgres -POSTGRES_PASSWORD=1234 - SECRET_KEY=foo DJANGO_ALLOWED_HOSTS="localhost 127.0.0.1 [::1]" DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=1234 -DJANGO_SUPERUSER_EMAIL="admin@admin.com" \ No newline at end of file +DJANGO_SUPERUSER_EMAIL="admin@admin.com" +## local Database +POSTGRES_HOST=localhost +POSTGRES_DB=dashboard +POSTGRES_USER=postgres +POSTGRES_PORT=5432 +POSTGRES_PASSWORD=1234 +## osm-api database +API_DB_POSTGRES_HOST=host.docker.internal +API_DB_POSTGRES_DB=openstreetmap +API_DB_POSTGRES_USER=postgres +API_DB_POSTGRES_PASSWORD=1234 +API_DB_POSTGRES_PORT=5432 diff --git a/images/web_dashboard/Dockerfile b/images/web_dashboard/Dockerfile index aa76a981..1358639f 100644 --- a/images/web_dashboard/Dockerfile +++ b/images/web_dashboard/Dockerfile @@ -13,6 +13,6 @@ RUN pip install -r requirements.txt COPY app/ /app/ EXPOSE 5433 EXPOSE 8000 -# ENTRYPOINT ["sh","/app/start.sh"] -ENTRYPOINT ["sh"] -CMD /app/start.sh +ENTRYPOINT ["sh","/app/start.sh"] +# ENTRYPOINT ["sh"] +# CMD /app/start.sh diff --git a/images/web_dashboard/app/dashboard/asgi.py b/images/web_dashboard/app/dashboard/asgi.py index 33d63628..d40eccc8 100644 --- a/images/web_dashboard/app/dashboard/asgi.py +++ b/images/web_dashboard/app/dashboard/asgi.py @@ -11,6 +11,6 @@ from django.core.asgi import get_asgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dashboard.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dashboard.settings") application = get_asgi_application() diff --git a/images/web_dashboard/app/dashboard/settings.py b/images/web_dashboard/app/dashboard/settings.py index 34a4514e..3ec39665 100644 --- a/images/web_dashboard/app/dashboard/settings.py +++ b/images/web_dashboard/app/dashboard/settings.py @@ -21,7 +21,7 @@ # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-acnap5f@i4v7^m2$ed0%i10ta%)1xza%k!zp-42%k*$tb6rt$%" +SECRET_KEY = os.environ.get("SECRET_KEY", "foo") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -76,10 +76,6 @@ # https://docs.djangoproject.com/en/3.2/ref/settings/#databases DATABASES = { - # 'default': { - # 'ENGINE': 'django.db.backends.sqlite3', - # 'NAME': BASE_DIR / 'db.sqlite3', - # } "default": { "ENGINE": "django.db.backends.postgresql", "NAME": os.environ.get("POSTGRES_DB"), @@ -150,10 +146,3 @@ "django.contrib.auth.hashers.BCryptSHA256PasswordHasher", # 'django.contrib.auth.hashers.ScryptPasswordHasher', ] - -# PASSWORD_HASHERS = [ -# 'django.contrib.auth.hashers.PBKDF2PasswordHasher', -# 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', -# 'django.contrib.auth.hashers.Argon2PasswordHasher', -# 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher', -# ] \ No newline at end of file diff --git a/images/web_dashboard/app/dashboard/urls.py b/images/web_dashboard/app/dashboard/urls.py index 84a2b2ac..75a82c6f 100644 --- a/images/web_dashboard/app/dashboard/urls.py +++ b/images/web_dashboard/app/dashboard/urls.py @@ -16,8 +16,8 @@ from django.contrib import admin from django.urls import path, include -admin.site.site_header = 'OSM-Seed Administration' +admin.site.site_header = "OSM-Seed Administration" urlpatterns = [ - path('admin/', admin.site.urls), + path("admin/", admin.site.urls), path("", admin.site.login), ] diff --git a/images/web_dashboard/app/dashboard/wsgi.py b/images/web_dashboard/app/dashboard/wsgi.py index ebe6c676..98b1abb5 100644 --- a/images/web_dashboard/app/dashboard/wsgi.py +++ b/images/web_dashboard/app/dashboard/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dashboard.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dashboard.settings") application = get_wsgi_application() diff --git a/images/web_dashboard/app/start.sh b/images/web_dashboard/app/start.sh index 8656bb98..5b8672b2 100755 --- a/images/web_dashboard/app/start.sh +++ b/images/web_dashboard/app/start.sh @@ -1,17 +1,5 @@ #!/usr/bin/env bash set -e -export POSTGRES_HOST=localhost -export POSTGRES_DB=dashboard -export POSTGRES_USER=postgres -export POSTGRES_PORT=5432 -# POSTGRES_PASSWORD, comes from env var - - export API_DB_POSTGRES_HOST=host.docker.internal - export API_DB_POSTGRES_DB=openstreetmap - export API_DB_POSTGRES_USER=postgres - export API_DB_POSTGRES_PASSWORD=1234 - export API_DB_POSTGRES_PORT=5432 - flag=true /usr/local/bin/docker-entrypoint.sh "postgres" & while "$flag" = true; do @@ -20,6 +8,6 @@ while "$flag" = true; do echo "===================Start app=======================" python3 manage.py migrate python3 manage.py createsuperuser --no-input - python3 manage.py migrate --database=osm_api + # python3 manage.py migrate --database=osm_api python3 manage.py runserver 0.0.0.0:8000 done diff --git a/images/web_dashboard/app/user/admin.py b/images/web_dashboard/app/user/admin.py index 7f441bc8..0830698f 100644 --- a/images/web_dashboard/app/user/admin.py +++ b/images/web_dashboard/app/user/admin.py @@ -7,4 +7,5 @@ class UserAdmin(admin.ModelAdmin): list_display = ("email", "id", "display_name", "status", "changesets_count") form = UsersForm + admin.site.register(Users, UserAdmin) diff --git a/images/web_dashboard/app/user/apps.py b/images/web_dashboard/app/user/apps.py index 36cce4c8..578292c2 100644 --- a/images/web_dashboard/app/user/apps.py +++ b/images/web_dashboard/app/user/apps.py @@ -2,5 +2,5 @@ class UserConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'user' + default_auto_field = "django.db.models.BigAutoField" + name = "user" diff --git a/images/web_dashboard/app/user/forms.py b/images/web_dashboard/app/user/forms.py index ad2ea906..63f31247 100644 --- a/images/web_dashboard/app/user/forms.py +++ b/images/web_dashboard/app/user/forms.py @@ -23,5 +23,3 @@ class UsersForm(forms.ModelForm): class Meta: model = Users fields = ["email", "display_name", "pass_crypt", "status"] - - \ No newline at end of file diff --git a/images/web_dashboard/app/user/migrations/0001_initial.py b/images/web_dashboard/app/user/migrations/0001_initial.py index 5da2d2e9..924cfd80 100644 --- a/images/web_dashboard/app/user/migrations/0001_initial.py +++ b/images/web_dashboard/app/user/migrations/0001_initial.py @@ -7,46 +7,54 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Users', + name="Users", fields=[ - ('email', models.CharField(max_length=100, unique=True)), - ('id', models.BigAutoField(primary_key=True, serialize=False)), - ('pass_crypt', models.CharField(max_length=100)), - ('creation_time', models.DateTimeField()), - ('display_name', models.CharField(max_length=100, unique=True)), - ('data_public', models.BooleanField()), - ('description', models.TextField()), - ('home_lat', models.FloatField(blank=True, null=True)), - ('home_lon', models.FloatField(blank=True, null=True)), - ('home_zoom', models.SmallIntegerField(blank=True, null=True)), - ('pass_salt', models.CharField(blank=True, max_length=100, null=True)), - ('email_valid', models.BooleanField()), - ('new_email', models.CharField(blank=True, max_length=100, null=True)), - ('creation_ip', models.CharField(blank=True, max_length=100, null=True)), - ('languages', models.CharField(blank=True, max_length=100, null=True)), - ('status', models.TextField()), - ('terms_agreed', models.DateTimeField(blank=True, null=True)), - ('consider_pd', models.BooleanField()), - ('auth_uid', models.CharField(blank=True, max_length=100, null=True)), - ('preferred_editor', models.CharField(blank=True, max_length=100, null=True)), - ('terms_seen', models.BooleanField()), - ('description_format', models.TextField()), - ('changesets_count', models.IntegerField()), - ('traces_count', models.IntegerField()), - ('diary_entries_count', models.IntegerField()), - ('image_use_gravatar', models.BooleanField()), - ('auth_provider', models.CharField(blank=True, max_length=100, null=True)), - ('home_tile', models.BigIntegerField(blank=True, null=True)), - ('tou_agreed', models.DateTimeField(blank=True, null=True)), + ("email", models.CharField(max_length=100, unique=True)), + ("id", models.BigAutoField(primary_key=True, serialize=False)), + ("pass_crypt", models.CharField(max_length=100)), + ("creation_time", models.DateTimeField()), + ("display_name", models.CharField(max_length=100, unique=True)), + ("data_public", models.BooleanField()), + ("description", models.TextField()), + ("home_lat", models.FloatField(blank=True, null=True)), + ("home_lon", models.FloatField(blank=True, null=True)), + ("home_zoom", models.SmallIntegerField(blank=True, null=True)), + ("pass_salt", models.CharField(blank=True, max_length=100, null=True)), + ("email_valid", models.BooleanField()), + ("new_email", models.CharField(blank=True, max_length=100, null=True)), + ( + "creation_ip", + models.CharField(blank=True, max_length=100, null=True), + ), + ("languages", models.CharField(blank=True, max_length=100, null=True)), + ("status", models.TextField()), + ("terms_agreed", models.DateTimeField(blank=True, null=True)), + ("consider_pd", models.BooleanField()), + ("auth_uid", models.CharField(blank=True, max_length=100, null=True)), + ( + "preferred_editor", + models.CharField(blank=True, max_length=100, null=True), + ), + ("terms_seen", models.BooleanField()), + ("description_format", models.TextField()), + ("changesets_count", models.IntegerField()), + ("traces_count", models.IntegerField()), + ("diary_entries_count", models.IntegerField()), + ("image_use_gravatar", models.BooleanField()), + ( + "auth_provider", + models.CharField(blank=True, max_length=100, null=True), + ), + ("home_tile", models.BigIntegerField(blank=True, null=True)), + ("tou_agreed", models.DateTimeField(blank=True, null=True)), ], options={ - 'db_table': 'users', - 'managed': False, + "db_table": "users", + "managed": False, }, ), ] diff --git a/images/web_dashboard/app/user/models.py b/images/web_dashboard/app/user/models.py index 5024e5c7..a3befa91 100644 --- a/images/web_dashboard/app/user/models.py +++ b/images/web_dashboard/app/user/models.py @@ -16,6 +16,7 @@ class Users(models.Model): tou_agreed = models.DateTimeField(default=datetime.now, null=True) creation_time = models.DateTimeField(default=datetime.now, blank=True) changesets_count = models.IntegerField(default=0) + class Meta: managed = False db_table = "users" @@ -36,5 +37,8 @@ def save(self, *args, **kwargs): *args, **kwargs, update_fields=["email", "display_name", "status"] ) + def __str__(self): + return f"{self.display_name}" + Users.objects = Users.objects.using("osm_api") From 06b0179253a9428c4bb164cb7fc90b9d671b32d2 Mon Sep 17 00:00:00 2001 From: Rub21 Date: Mon, 28 Nov 2022 10:18:23 -0500 Subject: [PATCH 11/11] Dockerfile update --- images/web_dashboard/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/images/web_dashboard/Dockerfile b/images/web_dashboard/Dockerfile index 1358639f..62449e43 100644 --- a/images/web_dashboard/Dockerfile +++ b/images/web_dashboard/Dockerfile @@ -14,5 +14,3 @@ COPY app/ /app/ EXPOSE 5433 EXPOSE 8000 ENTRYPOINT ["sh","/app/start.sh"] -# ENTRYPOINT ["sh"] -# CMD /app/start.sh