Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Api users creation #274

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compose/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions images/web_users/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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
Empty file.
16 changes: 16 additions & 0 deletions images/web_users/app/dashboard/asgi.py
Original file line number Diff line number Diff line change
@@ -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()
148 changes: 148 additions & 0 deletions images/web_users/app/dashboard/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""
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',
# ]
21 changes: 21 additions & 0 deletions images/web_users/app/dashboard/urls.py
Original file line number Diff line number Diff line change
@@ -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),
]
16 changes: 16 additions & 0 deletions images/web_users/app/dashboard/wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 22 additions & 0 deletions images/web_users/app/manage.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 4 additions & 0 deletions images/web_users/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Django>=3.0,<4.0
psycopg2>=2.8
argon2-cffi==21.3.0
django-scrypt==0.2.3
25 changes: 25 additions & 0 deletions images/web_users/app/start.sh
Original file line number Diff line number Diff line change
@@ -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="[email protected]"

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
Empty file.
11 changes: 11 additions & 0 deletions images/web_users/app/user/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +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")
form = UsersForm


admin.site.register(Users, UserAdmin)
6 changes: 6 additions & 0 deletions images/web_users/app/user/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'user'
21 changes: 21 additions & 0 deletions images/web_users/app/user/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from .models import Users
from django import forms

FRUIT_CHOICES = [
Rub21 marked this conversation as resolved.
Show resolved Hide resolved
("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"]
52 changes: 52 additions & 0 deletions images/web_users/app/user/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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,
},
),
]
Empty file.
Loading