AUTH_CMD to USER_CMD, updated workflows, Makefile, and docker-compose for user service
This commit is contained in:
28
user/.cruft.json
Normal file
28
user/.cruft.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"template": "https://github.com/JscorpTech/django",
|
||||
"commit": "d8682a7685597c2cf088da2f240b78a7a71e91ec",
|
||||
"checkout": null,
|
||||
"context": {
|
||||
"cookiecutter": {
|
||||
"cacheops": true,
|
||||
"silk": true,
|
||||
"storage": true,
|
||||
"rosetta": false,
|
||||
"channels": false,
|
||||
"ckeditor": false,
|
||||
"modeltranslation": false,
|
||||
"parler": false,
|
||||
"project_name": "auth",
|
||||
"settings_module": "config.settings.local",
|
||||
"runner": "wsgi",
|
||||
"script": "entrypoint.sh",
|
||||
"key": "key",
|
||||
"port": "8081",
|
||||
"phone": "998888112309",
|
||||
"password": "2309",
|
||||
"max_line_length": "120",
|
||||
"project_slug": "auth"
|
||||
}
|
||||
},
|
||||
"directory": null
|
||||
}
|
||||
2
user/.dockerignore
Normal file
2
user/.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
||||
venv/
|
||||
resources/staticfiles/
|
||||
63
user/.env.example
Normal file
63
user/.env.example
Normal file
@@ -0,0 +1,63 @@
|
||||
# Django configs
|
||||
DJANGO_SECRET_KEY=key
|
||||
DEBUG=True
|
||||
DJANGO_SETTINGS_MODULE=config.settings.local
|
||||
COMMAND=sh ./resources/scripts/entrypoint.sh
|
||||
PORT=8081
|
||||
#! debug | prod
|
||||
PROJECT_ENV=debug
|
||||
PROTOCOL_HTTPS=False
|
||||
|
||||
# Databse configs
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
DB_ENGINE=django.db.backends.postgresql_psycopg2
|
||||
DB_NAME=django
|
||||
DB_USER=postgres
|
||||
DB_PASSWORD=2309
|
||||
DB_HOST=db
|
||||
DB_PORT=5432
|
||||
|
||||
# Cache
|
||||
CACHE_BACKEND=django.core.cache.backends.redis.RedisCache
|
||||
REDIS_URL=redis://redis:6379
|
||||
|
||||
|
||||
CACHE_ENABLED=False
|
||||
|
||||
CACHE_TIMEOUT=120
|
||||
|
||||
# Vite settings
|
||||
VITE_LIVE=False
|
||||
VITE_PORT=5173
|
||||
VITE_HOST=127.0.0.1
|
||||
|
||||
# Sms service
|
||||
SMS_API_URL=https://notify.eskiz.uz/api
|
||||
SMS_LOGIN=admin@gmail.com
|
||||
SMS_PASSWORD=key
|
||||
|
||||
# Addition
|
||||
|
||||
ALLOWED_HOSTS=127.0.0.1,web
|
||||
CSRF_TRUSTED_ORIGINS=http://127.0.0.1:8081
|
||||
|
||||
|
||||
OTP_MODULE=core.services.otp
|
||||
OTP_SERVICE=EskizService
|
||||
|
||||
|
||||
# Storage
|
||||
STORAGE_ID=id
|
||||
STORAGE_KEY=key
|
||||
STORAGE_URL=example.com
|
||||
|
||||
#! MINIO | AWS | FILE
|
||||
STORAGE_DEFAULT=FILE
|
||||
|
||||
#! MINIO | AWS | STATIC
|
||||
STORAGE_STATIC=STATIC
|
||||
|
||||
STORAGE_BUCKET_MEDIA=name
|
||||
STORAGE_BUCKET_STATIC=name
|
||||
STORAGE_PATH=127.0.0.1:8081/bucket/
|
||||
STORAGE_PROTOCOL=http:
|
||||
3
user/.flake8
Normal file
3
user/.flake8
Normal file
@@ -0,0 +1,3 @@
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
ignore = E701, E704, W503
|
||||
158
user/.gitignore
vendored
Normal file
158
user/.gitignore
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
node_modules
|
||||
|
||||
# OS ignores
|
||||
*.DS_Store
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
poetry.lock
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
.idea/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
2
user/README.MD
Normal file
2
user/README.MD
Normal file
@@ -0,0 +1,2 @@
|
||||
# JST-DJANGO
|
||||
[Docs](https://docs.jscorp.uz)
|
||||
3
user/config/__init__.py
Normal file
3
user/config/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .celery import app
|
||||
|
||||
__all__ = ["app"]
|
||||
12
user/config/asgi.py
Normal file
12
user/config/asgi.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
asgi_application = get_asgi_application()
|
||||
from config.env import env # noqa
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", env("DJANGO_SETTINGS_MODULE"))
|
||||
|
||||
|
||||
application = asgi_application
|
||||
|
||||
16
user/config/celery.py
Normal file
16
user/config/celery.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
Celery configurations
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import celery
|
||||
from config.env import env
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", env("DJANGO_SETTINGS_MODULE"))
|
||||
|
||||
app = celery.Celery("config")
|
||||
|
||||
app.config_from_object("django.conf:settings", namespace="CELERY")
|
||||
|
||||
app.autodiscover_tasks()
|
||||
11
user/config/conf/__init__.py
Normal file
11
user/config/conf/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from .cache import * # noqa
|
||||
from .celery import * # noqa
|
||||
from .cron import * # noqa
|
||||
from .jwt import * # noqa
|
||||
from .logs import * # noqa
|
||||
from .rest_framework import * # noqa
|
||||
from .unfold import * # noqa
|
||||
from .spectacular import * # noqa
|
||||
|
||||
|
||||
from .storage import * # noqa
|
||||
18
user/config/conf/apps.py
Normal file
18
user/config/conf/apps.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from config.env import env
|
||||
|
||||
APPS = [
|
||||
"cacheops",
|
||||
"drf_spectacular",
|
||||
"rest_framework",
|
||||
"corsheaders",
|
||||
"django_filters",
|
||||
"django_redis",
|
||||
"rest_framework_simplejwt",
|
||||
"django_core",
|
||||
"core.apps.accounts.apps.AccountsConfig",
|
||||
]
|
||||
|
||||
if env.str("PROJECT_ENV") == "debug":
|
||||
APPS += [
|
||||
"silk",
|
||||
]
|
||||
26
user/config/conf/cache.py
Normal file
26
user/config/conf/cache.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from config.env import env
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": env.str("CACHE_BACKEND"),
|
||||
"LOCATION": env.str("REDIS_URL"),
|
||||
"TIMEOUT": env.str("CACHE_TIMEOUT"),
|
||||
},
|
||||
}
|
||||
|
||||
CACHE_MIDDLEWARE_SECONDS = env("CACHE_TIMEOUT")
|
||||
|
||||
|
||||
CACHEOPS_REDIS = env.str("REDIS_URL")
|
||||
CACHEOPS_DEFAULTS = {
|
||||
"timeout": env.str("CACHE_TIMEOUT"),
|
||||
}
|
||||
CACHEOPS = {
|
||||
# !NOTE: api => "you app name"
|
||||
# "api.*": {
|
||||
# "ops": "all", # Barcha turdagi so'rovlarni keshga olish
|
||||
# "timeout": 60 * 5, # 5 daqiqa davomida saqlash
|
||||
# },
|
||||
}
|
||||
CACHEOPS_DEGRADE_ON_FAILURE = True
|
||||
CACHEOPS_ENABLED = env.bool("CACHE_ENABLED", False)
|
||||
7
user/config/conf/celery.py
Normal file
7
user/config/conf/celery.py
Normal file
@@ -0,0 +1,7 @@
|
||||
CELERY_BEAT_SCHEDULE = {
|
||||
# "test": {
|
||||
# "task": "core.apps.home.tasks.demo.add",
|
||||
# "schedule": 5.0,
|
||||
# "args": (1, 2)
|
||||
# },
|
||||
}
|
||||
8
user/config/conf/channels.py
Normal file
8
user/config/conf/channels.py
Normal file
@@ -0,0 +1,8 @@
|
||||
CHANNEL_LAYERS = {
|
||||
"default": {
|
||||
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||||
"CONFIG": {
|
||||
"hosts": [("redis", 6379)],
|
||||
},
|
||||
},
|
||||
}
|
||||
147
user/config/conf/ckeditor.py
Normal file
147
user/config/conf/ckeditor.py
Normal file
@@ -0,0 +1,147 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
STATIC_URL = "/resources/static/"
|
||||
MEDIA_URL = "/resources/media/"
|
||||
MEDIA_ROOT = os.path.join(Path().parent.parent, "media")
|
||||
|
||||
customColorPalette = [
|
||||
{"color": "hsl(4, 90%, 58%)", "label": "Red"},
|
||||
{"color": "hsl(340, 82%, 52%)", "label": "Pink"},
|
||||
{"color": "hsl(291, 64%, 42%)", "label": "Purple"},
|
||||
{"color": "hsl(262, 52%, 47%)", "label": "Deep Purple"},
|
||||
{"color": "hsl(231, 48%, 48%)", "label": "Indigo"},
|
||||
{"color": "hsl(207, 90%, 54%)", "label": "Blue"},
|
||||
]
|
||||
|
||||
CKEDITOR_5_CONFIGS = {
|
||||
"default": {
|
||||
"toolbar": [
|
||||
"heading",
|
||||
"|",
|
||||
"bold",
|
||||
"italic",
|
||||
"link",
|
||||
"bulletedList",
|
||||
"numberedList",
|
||||
"blockQuote",
|
||||
"imageUpload",
|
||||
],
|
||||
},
|
||||
"extends": {
|
||||
"blockToolbar": [
|
||||
"paragraph",
|
||||
"heading1",
|
||||
"heading2",
|
||||
"heading3",
|
||||
"|",
|
||||
"bulletedList",
|
||||
"numberedList",
|
||||
"|",
|
||||
"blockQuote",
|
||||
],
|
||||
"toolbar": [
|
||||
"heading",
|
||||
"|",
|
||||
"outdent",
|
||||
"indent",
|
||||
"|",
|
||||
"bold",
|
||||
"italic",
|
||||
"link",
|
||||
"underline",
|
||||
"strikethrough",
|
||||
"code",
|
||||
"subscript",
|
||||
"superscript",
|
||||
"highlight",
|
||||
"|",
|
||||
"codeBlock",
|
||||
"sourceEditing",
|
||||
"insertImage",
|
||||
"bulletedList",
|
||||
"numberedList",
|
||||
"todoList",
|
||||
"|",
|
||||
"blockQuote",
|
||||
"imageUpload",
|
||||
"|",
|
||||
"fontSize",
|
||||
"fontFamily",
|
||||
"fontColor",
|
||||
"fontBackgroundColor",
|
||||
"mediaEmbed",
|
||||
"removeFormat",
|
||||
"insertTable",
|
||||
],
|
||||
"image": {
|
||||
"toolbar": [
|
||||
"imageTextAlternative",
|
||||
"|",
|
||||
"imageStyle:alignLeft",
|
||||
"imageStyle:alignRight",
|
||||
"imageStyle:alignCenter",
|
||||
"imageStyle:side",
|
||||
"|",
|
||||
],
|
||||
"styles": [
|
||||
"full",
|
||||
"side",
|
||||
"alignLeft",
|
||||
"alignRight",
|
||||
"alignCenter",
|
||||
],
|
||||
},
|
||||
"table": {
|
||||
"contentToolbar": [
|
||||
"tableColumn",
|
||||
"tableRow",
|
||||
"mergeTableCells",
|
||||
"tableProperties",
|
||||
"tableCellProperties",
|
||||
],
|
||||
"tableProperties": {
|
||||
"borderColors": customColorPalette,
|
||||
"backgroundColors": customColorPalette,
|
||||
},
|
||||
"tableCellProperties": {
|
||||
"borderColors": customColorPalette,
|
||||
"backgroundColors": customColorPalette,
|
||||
},
|
||||
},
|
||||
"heading": {
|
||||
"options": [
|
||||
{
|
||||
"model": "paragraph",
|
||||
"title": "Paragraph",
|
||||
"class": "ck-heading_paragraph",
|
||||
},
|
||||
{
|
||||
"model": "heading1",
|
||||
"view": "h1",
|
||||
"title": "Heading 1",
|
||||
"class": "ck-heading_heading1",
|
||||
},
|
||||
{
|
||||
"model": "heading2",
|
||||
"view": "h2",
|
||||
"title": "Heading 2",
|
||||
"class": "ck-heading_heading2",
|
||||
},
|
||||
{
|
||||
"model": "heading3",
|
||||
"view": "h3",
|
||||
"title": "Heading 3",
|
||||
"class": "ck-heading_heading3",
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
"list": {
|
||||
"properties": {
|
||||
"styles": "true",
|
||||
"startIndex": "true",
|
||||
"reversed": "true",
|
||||
}
|
||||
},
|
||||
}
|
||||
0
user/config/conf/cron.py
Normal file
0
user/config/conf/cron.py
Normal file
36
user/config/conf/jwt.py
Normal file
36
user/config/conf/jwt.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from config.env import env
|
||||
|
||||
SIMPLE_JWT = {
|
||||
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=60),
|
||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=30),
|
||||
"ROTATE_REFRESH_TOKENS": False,
|
||||
"BLACKLIST_AFTER_ROTATION": False,
|
||||
"UPDATE_LAST_LOGIN": False,
|
||||
"ALGORITHM": "HS256",
|
||||
"SIGNING_KEY": env("JWT_KEY"),
|
||||
"VERIFYING_KEY": "",
|
||||
"AUDIENCE": None,
|
||||
"ISSUER": None,
|
||||
"JSON_ENCODER": None,
|
||||
"JWK_URL": None,
|
||||
"LEEWAY": 0,
|
||||
"AUTH_HEADER_TYPES": ("Bearer",),
|
||||
"AUTH_HEADER_NAME": "HTTP_AUTHORIZATION",
|
||||
"USER_ID_FIELD": "id",
|
||||
"USER_ID_CLAIM": "user_id",
|
||||
"AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
|
||||
"TOKEN_TYPE_CLAIM": "token_type",
|
||||
"TOKEN_USER_CLASS": "rest_framework_simplejwt.models.TokenUser",
|
||||
"JTI_CLAIM": "jti",
|
||||
"SLIDING_TOKEN_REFRESH_EXP_CLAIM": "refresh_exp",
|
||||
"SLIDING_TOKEN_LIFETIME": timedelta(minutes=60),
|
||||
"SLIDING_TOKEN_REFRESH_LIFETIME": timedelta(days=30),
|
||||
"TOKEN_OBTAIN_SERIALIZER": "rest_framework_simplejwt.serializers.TokenObtainPairSerializer",
|
||||
"TOKEN_REFRESH_SERIALIZER": "rest_framework_simplejwt.serializers.TokenRefreshSerializer",
|
||||
"TOKEN_VERIFY_SERIALIZER": "rest_framework_simplejwt.serializers.TokenVerifySerializer",
|
||||
"TOKEN_BLACKLIST_SERIALIZER": "rest_framework_simplejwt.serializers.TokenBlacklistSerializer",
|
||||
"SLIDING_TOKEN_OBTAIN_SERIALIZER": "rest_framework_simplejwt.serializers.TokenObtainSlidingSerializer",
|
||||
"SLIDING_TOKEN_REFRESH_SERIALIZER": "rest_framework_simplejwt.serializers.TokenRefreshSlidingSerializer",
|
||||
}
|
||||
29
user/config/conf/logs.py
Normal file
29
user/config/conf/logs.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# settings.py faylida
|
||||
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"verbose": {
|
||||
"format": "{levelname} {asctime} {module} {message}",
|
||||
"style": "{",
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"daily_rotating_file": {
|
||||
"level": "INFO",
|
||||
"class": "logging.handlers.TimedRotatingFileHandler",
|
||||
"filename": "resources/logs/django.log", # Fayl nomi (kunlik fayllar uchun avtomatik yoziladi)
|
||||
"when": "midnight", # Har kecha log fayli yangilanadi
|
||||
"backupCount": 30, # 30 kunlik loglar saqlanadi, 1 oydan keyin eski fayllar o'chiriladi
|
||||
"formatter": "verbose",
|
||||
},
|
||||
},
|
||||
"loggers": {
|
||||
"django": {
|
||||
"handlers": ["daily_rotating_file"],
|
||||
"level": "INFO",
|
||||
"propagate": True,
|
||||
},
|
||||
},
|
||||
}
|
||||
1
user/config/conf/modules.py
Normal file
1
user/config/conf/modules.py
Normal file
@@ -0,0 +1 @@
|
||||
MODULES = []
|
||||
31
user/config/conf/navigation.py
Normal file
31
user/config/conf/navigation.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
PAGES = [
|
||||
{
|
||||
"seperator": False,
|
||||
"items": [
|
||||
{
|
||||
"title": _("Home page"),
|
||||
"icon": "home",
|
||||
"link": reverse_lazy("admin:index"),
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"title": _("Auth"),
|
||||
"separator": True, # Top border
|
||||
"items": [
|
||||
{
|
||||
"title": _("Users"),
|
||||
"icon": "group",
|
||||
"link": reverse_lazy("admin:http_user_changelist"),
|
||||
},
|
||||
{
|
||||
"title": _("Group"),
|
||||
"icon": "group",
|
||||
"link": reverse_lazy("admin:auth_group_changelist"),
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
9
user/config/conf/rest_framework.py
Normal file
9
user/config/conf/rest_framework.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from typing import Any, Union
|
||||
|
||||
REST_FRAMEWORK: Union[Any] = {
|
||||
"DEFAULT_AUTHENTICATION_CLASSES": ("rest_framework_simplejwt.authentication.JWTAuthentication",),
|
||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||
"DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated"],
|
||||
"DEFAULT_PAGINATION_CLASS": "django_core.paginations.CustomPagination",
|
||||
"PAGE_SIZE": 10,
|
||||
}
|
||||
31
user/config/conf/spectacular.py
Normal file
31
user/config/conf/spectacular.py
Normal file
@@ -0,0 +1,31 @@
|
||||
SPECTACULAR_SETTINGS = {
|
||||
"TITLE": "Your Project API",
|
||||
"DESCRIPTION": "Your project description",
|
||||
"VERSION": "1.0.0",
|
||||
"SERVE_INCLUDE_SCHEMA": False,
|
||||
"CAMELIZE_NAMES": True,
|
||||
"POSTPROCESSING_HOOKS": ["config.conf.spectacular.custom_postprocessing_hook"],
|
||||
}
|
||||
|
||||
|
||||
def custom_postprocessing_hook(result, generator, request, public):
|
||||
"""
|
||||
Customizes the API schema to wrap all responses in a standard format.
|
||||
"""
|
||||
for path, methods in result.get("paths", {}).items():
|
||||
for method, operation in methods.items():
|
||||
if "responses" in operation:
|
||||
for status_code, response in operation["responses"].items():
|
||||
if "content" in response:
|
||||
for content_type, content in response["content"].items():
|
||||
# Wrap original schema
|
||||
original_schema = content.get("schema", {})
|
||||
response["content"][content_type]["schema"] = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"status": {"type": "boolean", "example": True},
|
||||
"data": original_schema,
|
||||
},
|
||||
"required": ["status", "data"],
|
||||
}
|
||||
return result
|
||||
23
user/config/conf/storage.py
Normal file
23
user/config/conf/storage.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from config.env import env
|
||||
from core.utils.storage import Storage
|
||||
|
||||
AWS_ACCESS_KEY_ID = env.str("STORAGE_ID")
|
||||
AWS_SECRET_ACCESS_KEY = env.str("STORAGE_KEY")
|
||||
AWS_S3_ENDPOINT_URL = env.str("STORAGE_URL")
|
||||
AWS_S3_CUSTOM_DOMAIN = env.str("STORAGE_PATH")
|
||||
AWS_S3_URL_PROTOCOL = env.str("STORAGE_PROTOCOL", "https:")
|
||||
AWS_S3_FILE_OVERWRITE = False
|
||||
|
||||
default_storage = Storage(env.str("STORAGE_DEFAULT"), "default")
|
||||
static_storage = Storage(env.str("STORAGE_STATIC"), "static")
|
||||
|
||||
STORAGES = {
|
||||
"default": {
|
||||
"BACKEND": default_storage.get_backend(),
|
||||
"OPTIONS": default_storage.get_options(),
|
||||
},
|
||||
"staticfiles": {
|
||||
"BACKEND": static_storage.get_backend(),
|
||||
"OPTIONS": static_storage.get_options(),
|
||||
},
|
||||
}
|
||||
41
user/config/conf/unfold.py
Normal file
41
user/config/conf/unfold.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from . import navigation
|
||||
|
||||
UNFOLD = {
|
||||
"DASHBOARD_CALLBACK": "django_core.views.dashboard_callback",
|
||||
"SITE_TITLE": None,
|
||||
"SHOW_LANGUAGES": True,
|
||||
"SITE_HEADER": None,
|
||||
"SITE_URL": "/",
|
||||
"SITE_SYMBOL": "speed", # symbol from icon set
|
||||
"SHOW_HISTORY": True, # show/hide "History" button, default: True
|
||||
"SHOW_VIEW_ON_SITE": True,
|
||||
"COLORS": {
|
||||
"primary": {
|
||||
"50": "220 255 230",
|
||||
"100": "190 255 200",
|
||||
"200": "160 255 170",
|
||||
"300": "130 255 140",
|
||||
"400": "100 255 110",
|
||||
"500": "70 255 80",
|
||||
"600": "50 225 70",
|
||||
"700": "40 195 60",
|
||||
"800": "30 165 50",
|
||||
"900": "20 135 40",
|
||||
"950": "10 105 30",
|
||||
},
|
||||
},
|
||||
"EXTENSIONS": {
|
||||
"modeltranslation": {
|
||||
"flags": {
|
||||
"en": "🇬🇧",
|
||||
"uz": "🇺🇿",
|
||||
"ru": "🇷🇺",
|
||||
},
|
||||
},
|
||||
},
|
||||
"SIDEBAR": {
|
||||
"show_search": True, # Search in applications and models names
|
||||
"show_all_applications": True,
|
||||
# "navigation": navigation.PAGES, # Pagelarni qo'lda qo'shish
|
||||
},
|
||||
}
|
||||
28
user/config/env.py
Normal file
28
user/config/env.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Default value for environ variable
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import environ
|
||||
|
||||
environ.Env.read_env(os.path.join(".env"))
|
||||
|
||||
env = environ.Env(
|
||||
DEBUG=(bool, False),
|
||||
CACHE_TIME=(int, 180),
|
||||
OTP_EXPIRE_TIME=(int, 2),
|
||||
VITE_LIVE=(bool, False),
|
||||
ALLOWED_HOSTS=(str, "localhost"),
|
||||
CSRF_TRUSTED_ORIGINS=(str, "localhost"),
|
||||
DJANGO_SETTINGS_MODULE=(str, "config.settings.local"),
|
||||
CACHE_TIMEOUT=(int, 120),
|
||||
CACHE_ENABLED=(bool, False),
|
||||
VITE_PORT=(int, 5173),
|
||||
VITE_HOST=(str, "vite"),
|
||||
NGROK_AUTHTOKEN=(str, "TOKEN"),
|
||||
BOT_TOKEN=(str, "TOKEN"),
|
||||
OTP_MODULE="core.services.otp",
|
||||
OTP_SERVICE="EskizService",
|
||||
PROJECT_ENV=(str, "prod"),
|
||||
)
|
||||
0
user/config/settings/__init__.py
Normal file
0
user/config/settings/__init__.py
Normal file
169
user/config/settings/common.py
Normal file
169
user/config/settings/common.py
Normal file
@@ -0,0 +1,169 @@
|
||||
import os
|
||||
import pathlib
|
||||
from typing import List, Union
|
||||
|
||||
from config.conf import * # noqa
|
||||
from config.conf.apps import APPS
|
||||
from config.conf.modules import MODULES
|
||||
from config.env import env
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from rich.traceback import install
|
||||
|
||||
install(show_locals=True)
|
||||
BASE_DIR = pathlib.Path(__file__).resolve().parent.parent.parent
|
||||
|
||||
SECRET_KEY = env.str("DJANGO_SECRET_KEY")
|
||||
DEBUG = env.bool("DEBUG")
|
||||
|
||||
ALLOWED_HOSTS: Union[List[str]] = ["*"]
|
||||
|
||||
if env.bool("PROTOCOL_HTTPS", False):
|
||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": env.str("DB_ENGINE"),
|
||||
"NAME": env.str("DB_NAME"),
|
||||
"USER": env.str("DB_USER"),
|
||||
"PASSWORD": env.str("DB_PASSWORD"),
|
||||
"HOST": env.str("DB_HOST"),
|
||||
"PORT": env.str("DB_PORT"),
|
||||
}
|
||||
}
|
||||
|
||||
PASSWORD_HASHERS = [
|
||||
"django.contrib.auth.hashers.BCryptPasswordHasher",
|
||||
]
|
||||
|
||||
INSTALLED_APPS = [
|
||||
|
||||
"unfold",
|
||||
"unfold.contrib.filters",
|
||||
"unfold.contrib.forms",
|
||||
"unfold.contrib.guardian",
|
||||
"unfold.contrib.simple_history",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
] + APPS
|
||||
|
||||
MODULES = [app for app in MODULES if isinstance(app, str)]
|
||||
|
||||
for module_path in MODULES:
|
||||
INSTALLED_APPS.append("{}.apps.ModuleConfig".format(module_path))
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"corsheaders.middleware.CorsMiddleware", # Cors middleware
|
||||
"django.middleware.locale.LocaleMiddleware", # Locale middleware
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
if env.str("PROJECT_ENV") == "debug":
|
||||
MIDDLEWARE += [
|
||||
"silk.middleware.SilkyMiddleware",
|
||||
]
|
||||
|
||||
|
||||
ROOT_URLCONF = "config.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [os.path.join(BASE_DIR, "resources/templates")],
|
||||
"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",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
# fmt: off
|
||||
|
||||
WSGI_APPLICATION = "config.wsgi.application"
|
||||
|
||||
# fmt: on
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.{}".format(validator)
|
||||
} for validator in [
|
||||
"UserAttributeSimilarityValidator",
|
||||
"MinimumLengthValidator",
|
||||
"CommonPasswordValidator",
|
||||
"NumericPasswordValidator"
|
||||
]
|
||||
]
|
||||
|
||||
TIME_ZONE = "Asia/Tashkent"
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
STATIC_URL = "/auth/resources/static/"
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
# Date formats
|
||||
##
|
||||
DATE_FORMAT = "d.m.y"
|
||||
TIME_FORMAT = "H:i:s"
|
||||
DATE_INPUT_FORMATS = ["%d.%m.%Y", "%Y.%d.%m", "%Y.%d.%m"]
|
||||
|
||||
|
||||
SEEDERS = ["core.apps.accounts.seeder.UserSeeder"]
|
||||
|
||||
STATICFILES_DIRS = [
|
||||
os.path.join(BASE_DIR, "resources/static"),
|
||||
]
|
||||
|
||||
CORS_ORIGIN_ALLOW_ALL = True
|
||||
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, "resources/staticfiles")
|
||||
VITE_APP_DIR = os.path.join(BASE_DIR, "resources/static/vite")
|
||||
|
||||
LANGUAGES = (
|
||||
("ru", _("Russia")),
|
||||
("en", _("English")),
|
||||
("uz", _("Uzbek")),
|
||||
)
|
||||
LOCALE_PATHS = [os.path.join(BASE_DIR, "resources/locale")]
|
||||
|
||||
LANGUAGE_CODE = "uz"
|
||||
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, "resources/media") # Media files
|
||||
MEDIA_URL = "/auth/resources/media/"
|
||||
|
||||
AUTH_USER_MODEL = "accounts.User"
|
||||
|
||||
CELERY_BROKER_URL = env("REDIS_URL")
|
||||
CELERY_RESULT_BACKEND = env("REDIS_URL")
|
||||
|
||||
ALLOWED_HOSTS += env("ALLOWED_HOSTS").split(",")
|
||||
CSRF_TRUSTED_ORIGINS = env("CSRF_TRUSTED_ORIGINS").split(",")
|
||||
SILKY_AUTHORISATION = True
|
||||
SILKY_PYTHON_PROFILER = True
|
||||
|
||||
JST_LANGUAGES = [
|
||||
{
|
||||
"code": "uz",
|
||||
"name": "Uzbek",
|
||||
"is_default": True,
|
||||
},
|
||||
{
|
||||
"code": "en",
|
||||
"name": "English",
|
||||
},
|
||||
{
|
||||
"code": "ru",
|
||||
"name": "Russia",
|
||||
}
|
||||
]
|
||||
11
user/config/settings/local.py
Normal file
11
user/config/settings/local.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from config.settings.common import * # noqa
|
||||
from config.settings.common import (ALLOWED_HOSTS, INSTALLED_APPS,
|
||||
REST_FRAMEWORK)
|
||||
|
||||
INSTALLED_APPS += ["django_extensions"]
|
||||
|
||||
ALLOWED_HOSTS += ["127.0.0.1", "192.168.100.26"]
|
||||
|
||||
REST_FRAMEWORK["DEFAULT_THROTTLE_RATES"] = {
|
||||
"user": "60/min",
|
||||
}
|
||||
6
user/config/settings/production.py
Normal file
6
user/config/settings/production.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from config.settings.common import * # noqa
|
||||
from config.settings.common import ALLOWED_HOSTS, REST_FRAMEWORK
|
||||
|
||||
ALLOWED_HOSTS += ["192.168.100.26", "80.90.178.156"]
|
||||
|
||||
REST_FRAMEWORK["DEFAULT_THROTTLE_RATES"] = {"user": "60/min"}
|
||||
55
user/config/urls.py
Normal file
55
user/config/urls.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
All urls configurations tree
|
||||
"""
|
||||
|
||||
from django.conf import settings
|
||||
from config.env import env
|
||||
from django.contrib import admin
|
||||
from django.urls import include, path, re_path
|
||||
from django.views.static import serve
|
||||
from drf_spectacular.views import (SpectacularAPIView, SpectacularRedocView,
|
||||
SpectacularSwaggerView)
|
||||
|
||||
################
|
||||
# My apps url
|
||||
################
|
||||
urlpatterns = [
|
||||
path("", include("core.apps.accounts.urls")),
|
||||
]
|
||||
|
||||
|
||||
################
|
||||
# Library urls
|
||||
################
|
||||
urlpatterns += [
|
||||
path("admin/", admin.site.urls),
|
||||
path("accounts/", include("django.contrib.auth.urls")),
|
||||
path("i18n/", include("django.conf.urls.i18n")),
|
||||
|
||||
|
||||
]
|
||||
|
||||
################
|
||||
# Project env debug mode
|
||||
################
|
||||
if env.str("PROJECT_ENV") == "debug":
|
||||
urlpatterns += [
|
||||
path('silk/', include('silk.urls', namespace='silk'))
|
||||
]
|
||||
|
||||
################
|
||||
# Swagger urls
|
||||
################
|
||||
urlpatterns += [
|
||||
path("schema/", SpectacularAPIView.as_view(), name="schema"),
|
||||
path("swagger/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger-ui"),
|
||||
path("redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"),
|
||||
]
|
||||
|
||||
################
|
||||
# Media urls
|
||||
################
|
||||
urlpatterns += [
|
||||
re_path(r"static/(?P<path>.*)", serve, {"document_root": settings.STATIC_ROOT}),
|
||||
re_path(r"media/(?P<path>.*)", serve, {"document_root": settings.MEDIA_ROOT}),
|
||||
]
|
||||
8
user/config/wsgi.py
Normal file
8
user/config/wsgi.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
|
||||
from config.env import env
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", env("DJANGO_SETTINGS_MODULE"))
|
||||
|
||||
application = get_wsgi_application()
|
||||
0
user/core/__init__.py
Normal file
0
user/core/__init__.py
Normal file
0
user/core/apps/__init__.py
Normal file
0
user/core/apps/__init__.py
Normal file
0
user/core/apps/accounts/__init__.py
Normal file
0
user/core/apps/accounts/__init__.py
Normal file
2
user/core/apps/accounts/admin/__init__.py
Normal file
2
user/core/apps/accounts/admin/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .core import * # noqa
|
||||
from .user import * # noqa
|
||||
18
user/core/apps/accounts/admin/core.py
Normal file
18
user/core/apps/accounts/admin/core.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""
|
||||
Admin panel register
|
||||
"""
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth import models as db_models
|
||||
from django_core.models import SmsConfirm
|
||||
|
||||
from ..admin import user
|
||||
from .user import SmsConfirmAdmin
|
||||
|
||||
admin.site.unregister(db_models.Group)
|
||||
admin.site.register(db_models.Group, user.GroupAdmin)
|
||||
admin.site.register(db_models.Permission, user.PermissionAdmin)
|
||||
|
||||
admin.site.register(get_user_model(), user.CustomUserAdmin)
|
||||
admin.site.register(SmsConfirm, SmsConfirmAdmin)
|
||||
52
user/core/apps/accounts/admin/user.py
Normal file
52
user/core/apps/accounts/admin/user.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from django.contrib.auth import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from unfold.admin import ModelAdmin
|
||||
from unfold.forms import AdminPasswordChangeForm # UserCreationForm,
|
||||
from unfold.forms import UserChangeForm
|
||||
|
||||
|
||||
class CustomUserAdmin(admin.UserAdmin, ModelAdmin):
|
||||
change_password_form = AdminPasswordChangeForm
|
||||
# add_form = UserCreationForm
|
||||
form = UserChangeForm
|
||||
list_display = (
|
||||
"first_name",
|
||||
"last_name",
|
||||
"phone",
|
||||
"role",
|
||||
)
|
||||
autocomplete_fields = ["groups", "user_permissions"]
|
||||
fieldsets = ((None, {"fields": ("phone",)}),) + (
|
||||
(None, {"fields": ("username", "password")}),
|
||||
(_("Personal info"), {"fields": ("first_name", "last_name", "email")}),
|
||||
(
|
||||
_("Permissions"),
|
||||
{
|
||||
"fields": (
|
||||
"is_active",
|
||||
"is_staff",
|
||||
"is_superuser",
|
||||
"groups",
|
||||
"user_permissions",
|
||||
"role",
|
||||
),
|
||||
},
|
||||
),
|
||||
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
|
||||
)
|
||||
|
||||
|
||||
class PermissionAdmin(ModelAdmin):
|
||||
list_display = ("name",)
|
||||
search_fields = ("name",)
|
||||
|
||||
|
||||
class GroupAdmin(ModelAdmin):
|
||||
list_display = ["name"]
|
||||
search_fields = ["name"]
|
||||
autocomplete_fields = ("permissions",)
|
||||
|
||||
|
||||
class SmsConfirmAdmin(ModelAdmin):
|
||||
list_display = ["phone", "code", "resend_count", "try_count"]
|
||||
search_fields = ["phone", "code"]
|
||||
9
user/core/apps/accounts/apps.py
Normal file
9
user/core/apps/accounts/apps.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "core.apps.accounts"
|
||||
|
||||
def ready(self):
|
||||
from core.apps.accounts import signals # noqa
|
||||
1
user/core/apps/accounts/choices/__init__.py
Normal file
1
user/core/apps/accounts/choices/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .user import * # noqa
|
||||
12
user/core/apps/accounts/choices/user.py
Normal file
12
user/core/apps/accounts/choices/user.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class RoleChoice(models.TextChoices):
|
||||
"""
|
||||
User Role Choice
|
||||
"""
|
||||
|
||||
SUPERUSER = "superuser", _("Superuser")
|
||||
ADMIN = "admin", _("Admin")
|
||||
USER = "user", _("User")
|
||||
1
user/core/apps/accounts/managers/__init__.py
Normal file
1
user/core/apps/accounts/managers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .user import * # noqa
|
||||
23
user/core/apps/accounts/managers/user.py
Normal file
23
user/core/apps/accounts/managers/user.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.contrib.auth import base_user
|
||||
|
||||
|
||||
class UserManager(base_user.BaseUserManager):
|
||||
def create_user(self, phone, password=None, **extra_fields):
|
||||
if not phone:
|
||||
raise ValueError("The phone number must be set")
|
||||
|
||||
user = self.model(phone=phone, **extra_fields)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
def create_superuser(self, phone, password=None, **extra_fields):
|
||||
extra_fields.setdefault("is_staff", True)
|
||||
extra_fields.setdefault("is_superuser", True)
|
||||
|
||||
if extra_fields.get("is_staff") is not True:
|
||||
raise ValueError("Superuser must have is_staff=True.")
|
||||
if extra_fields.get("is_superuser") is not True:
|
||||
raise ValueError("Superuser must have is_superuser=True.")
|
||||
|
||||
return self.create_user(phone, password, **extra_fields)
|
||||
60
user/core/apps/accounts/migrations/0001_initial.py
Normal file
60
user/core/apps/accounts/migrations/0001_initial.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Generated by Django 5.1.3 on 2024-12-13 19:04
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
|
||||
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
|
||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('phone', models.CharField(max_length=255, unique=True)),
|
||||
('username', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('validated_at', models.DateTimeField(blank=True, null=True)),
|
||||
('role', models.CharField(choices=[('superuser', 'Superuser'), ('admin', 'Admin'), ('user', 'User')], default='user', max_length=255)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
'verbose_name_plural': 'users',
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ResetToken',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('token', models.CharField(max_length=255, unique=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Reset Token',
|
||||
'verbose_name_plural': 'Reset Tokens',
|
||||
},
|
||||
),
|
||||
]
|
||||
0
user/core/apps/accounts/migrations/__init__.py
Normal file
0
user/core/apps/accounts/migrations/__init__.py
Normal file
3
user/core/apps/accounts/models/__init__.py
Normal file
3
user/core/apps/accounts/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# isort: skip_file
|
||||
from .user import * # noqa
|
||||
from .reset_token import * # noqa
|
||||
15
user/core/apps/accounts/models/reset_token.py
Normal file
15
user/core/apps/accounts/models/reset_token.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django_core.models import AbstractBaseModel
|
||||
|
||||
|
||||
class ResetToken(AbstractBaseModel):
|
||||
token = models.CharField(max_length=255, unique=True)
|
||||
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.token
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Reset Token"
|
||||
verbose_name_plural = "Reset Tokens"
|
||||
24
user/core/apps/accounts/models/user.py
Normal file
24
user/core/apps/accounts/models/user.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.contrib.auth import models as auth_models
|
||||
from django.db import models
|
||||
|
||||
from ..choices import RoleChoice
|
||||
from ..managers import UserManager
|
||||
|
||||
|
||||
class User(auth_models.AbstractUser):
|
||||
phone = models.CharField(max_length=255, unique=True)
|
||||
username = models.CharField(max_length=255, null=True, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
validated_at = models.DateTimeField(null=True, blank=True)
|
||||
role = models.CharField(
|
||||
max_length=255,
|
||||
choices=RoleChoice,
|
||||
default=RoleChoice.USER,
|
||||
)
|
||||
|
||||
USERNAME_FIELD = "phone"
|
||||
objects = UserManager()
|
||||
|
||||
def __str__(self):
|
||||
return self.phone
|
||||
1
user/core/apps/accounts/seeder/__init__.py
Normal file
1
user/core/apps/accounts/seeder/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .core import * # noqa
|
||||
10
user/core/apps/accounts/seeder/core.py
Normal file
10
user/core/apps/accounts/seeder/core.py
Normal file
@@ -0,0 +1,10 @@
|
||||
"""
|
||||
Create a new user/superuser
|
||||
"""
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
|
||||
class UserSeeder:
|
||||
def run(self):
|
||||
get_user_model().objects.create_superuser("998888112309", "2309")
|
||||
4
user/core/apps/accounts/serializers/__init__.py
Normal file
4
user/core/apps/accounts/serializers/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .auth import * # noqa
|
||||
from .change_password import * # noqa
|
||||
from .set_password import * # noqa
|
||||
from .user import * # noqa
|
||||
59
user/core/apps/accounts/serializers/auth.py
Normal file
59
user/core/apps/accounts/serializers/auth.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils.translation import gettext as _
|
||||
from rest_framework import exceptions, serializers
|
||||
|
||||
|
||||
class LoginSerializer(serializers.Serializer):
|
||||
username = serializers.CharField(max_length=255)
|
||||
password = serializers.CharField(max_length=255)
|
||||
|
||||
|
||||
class RegisterSerializer(serializers.ModelSerializer):
|
||||
phone = serializers.CharField(max_length=255)
|
||||
|
||||
def validate_phone(self, value):
|
||||
user = get_user_model().objects.filter(phone=value, validated_at__isnull=False)
|
||||
if user.exists():
|
||||
raise exceptions.ValidationError(_("Phone number already registered."), code="unique")
|
||||
return value
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ["first_name", "last_name", "phone", "password"]
|
||||
extra_kwargs = {
|
||||
"first_name": {
|
||||
"required": True,
|
||||
},
|
||||
"last_name": {"required": True},
|
||||
}
|
||||
|
||||
|
||||
class ConfirmSerializer(serializers.Serializer):
|
||||
code = serializers.IntegerField(min_value=1000, max_value=9999)
|
||||
phone = serializers.CharField(max_length=255)
|
||||
|
||||
|
||||
class ResetPasswordSerializer(serializers.Serializer):
|
||||
phone = serializers.CharField(max_length=255)
|
||||
|
||||
def validate_phone(self, value):
|
||||
user = get_user_model().objects.filter(phone=value)
|
||||
if user.exists():
|
||||
return value
|
||||
|
||||
raise serializers.ValidationError(_("User does not exist"))
|
||||
|
||||
|
||||
class ResetConfirmationSerializer(serializers.Serializer):
|
||||
code = serializers.IntegerField(min_value=1000, max_value=9999)
|
||||
phone = serializers.CharField(max_length=255)
|
||||
|
||||
def validate_phone(self, value):
|
||||
user = get_user_model().objects.filter(phone=value)
|
||||
if user.exists():
|
||||
return value
|
||||
raise serializers.ValidationError(_("User does not exist"))
|
||||
|
||||
|
||||
class ResendSerializer(serializers.Serializer):
|
||||
phone = serializers.CharField(max_length=255)
|
||||
6
user/core/apps/accounts/serializers/change_password.py
Normal file
6
user/core/apps/accounts/serializers/change_password.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class ChangePasswordSerializer(serializers.Serializer):
|
||||
old_password = serializers.CharField(required=True)
|
||||
new_password = serializers.CharField(required=True, min_length=8)
|
||||
6
user/core/apps/accounts/serializers/set_password.py
Normal file
6
user/core/apps/accounts/serializers/set_password.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class SetPasswordSerializer(serializers.Serializer):
|
||||
password = serializers.CharField()
|
||||
token = serializers.CharField(max_length=255)
|
||||
23
user/core/apps/accounts/serializers/user.py
Normal file
23
user/core/apps/accounts/serializers/user.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
exclude = [
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"password",
|
||||
"groups",
|
||||
"user_permissions"
|
||||
]
|
||||
model = get_user_model()
|
||||
|
||||
|
||||
class UserUpdateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = [
|
||||
"first_name",
|
||||
"last_name"
|
||||
]
|
||||
1
user/core/apps/accounts/signals/__init__.py
Normal file
1
user/core/apps/accounts/signals/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .user import * # noqa
|
||||
10
user/core/apps/accounts/signals/user.py
Normal file
10
user/core/apps/accounts/signals/user.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
|
||||
@receiver(post_save, sender=get_user_model())
|
||||
def user_signal(sender, created, instance, **kwargs):
|
||||
if created and instance.username is None:
|
||||
instance.username = "U%(id)s" % {"id": 1000 + instance.id}
|
||||
instance.save()
|
||||
0
user/core/apps/accounts/test/__init__.py
Normal file
0
user/core/apps/accounts/test/__init__.py
Normal file
116
user/core/apps/accounts/test/test_auth.py
Normal file
116
user/core/apps/accounts/test/test_auth.py
Normal file
@@ -0,0 +1,116 @@
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from pydantic import BaseModel
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from core.apps.accounts.models import ResetToken
|
||||
from django_core.models import SmsConfirm
|
||||
from core.services import SmsService
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
|
||||
class TokenModel(BaseModel):
|
||||
access: str
|
||||
refresh: str
|
||||
|
||||
|
||||
class SmsViewTest(TestCase):
|
||||
def setUp(self):
|
||||
self.client = APIClient()
|
||||
self.phone = "998999999999"
|
||||
self.password = "password"
|
||||
self.code = "1111"
|
||||
self.token = "token"
|
||||
self.user = get_user_model().objects.create_user(
|
||||
phone=self.phone, first_name="John", last_name="Doe", password=self.password
|
||||
)
|
||||
SmsConfirm.objects.create(phone=self.phone, code=self.code)
|
||||
|
||||
def test_reg_view(self):
|
||||
"""Test register view."""
|
||||
data = {
|
||||
"phone": "998999999991",
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"password": "password",
|
||||
}
|
||||
with patch.object(SmsService, "send_confirm", return_value=True):
|
||||
response = self.client.post(reverse("auth-register"), data=data)
|
||||
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
||||
self.assertEqual(
|
||||
response.data["data"]["detail"],
|
||||
"Sms %(phone)s raqamiga yuborildi" % {"phone": data["phone"]},
|
||||
)
|
||||
|
||||
def test_confirm_view(self):
|
||||
"""Test confirm view."""
|
||||
data = {"phone": self.phone, "code": self.code}
|
||||
response = self.client.post(reverse("auth-confirm"), data=data)
|
||||
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
||||
|
||||
def test_invalid_confirm_view(self):
|
||||
"""Test confirm view."""
|
||||
data = {"phone": self.phone, "code": "1112"}
|
||||
response = self.client.post(reverse("auth-confirm"), data=data)
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
def test_reset_confirmation_code_view(self):
|
||||
"""Test reset confirmation code view."""
|
||||
data = {"phone": self.phone, "code": self.code}
|
||||
response = self.client.post(reverse("auth-confirm"), data=data)
|
||||
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
||||
self.assertIn("token", response.data["data"])
|
||||
|
||||
def test_reset_confirmation_code_view_invalid_code(self):
|
||||
"""Test reset confirmation code view with invalid code."""
|
||||
data = {"phone": self.phone, "code": "123456"}
|
||||
response = self.client.post(reverse("auth-confirm"), data=data)
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def test_reset_set_password_view(self):
|
||||
"""Test reset set password view."""
|
||||
token = ResetToken.objects.create(user=self.user, token=self.token)
|
||||
data = {"token": token.token, "password": "new_password"}
|
||||
response = self.client.post(reverse("reset-password-reset-password-set"), data=data)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_reset_set_password_view_invalid_token(self):
|
||||
"""Test reset set password view with invalid token."""
|
||||
token = "test_token"
|
||||
data = {"token": token, "password": "new_password"}
|
||||
with patch.object(get_user_model().objects, "filter", return_value=get_user_model().objects.none()):
|
||||
response = self.client.post(reverse("reset-password-reset-password-set"), data=data)
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
self.assertEqual(response.data["data"]["detail"], "Invalid token")
|
||||
|
||||
def test_resend_view(self):
|
||||
"""Test resend view."""
|
||||
data = {"phone": self.phone}
|
||||
response = self.client.post(reverse("auth-resend"), data=data)
|
||||
logging.error(response.json())
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_reset_password_view(self):
|
||||
"""Test reset password view."""
|
||||
data = {"phone": self.phone}
|
||||
response = self.client.post(reverse("reset-password-reset-password"), data=data)
|
||||
logging.error(response.json())
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_me_view(self):
|
||||
"""Test me view."""
|
||||
self.client.force_authenticate(user=self.user)
|
||||
response = self.client.get(reverse("me-me"))
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_me_update_view(self):
|
||||
"""Test me update view."""
|
||||
self.client.force_authenticate(user=self.user)
|
||||
data = {"first_name": "Updated"}
|
||||
response = self.client.patch(reverse("me-user-update"), data=data)
|
||||
logging.error(response.json())
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
58
user/core/apps/accounts/test/test_change_password.py
Normal file
58
user/core/apps/accounts/test/test_change_password.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from core.apps.accounts.serializers import ChangePasswordSerializer
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
|
||||
class ChangePasswordViewTest(TestCase):
|
||||
def setUp(self):
|
||||
self.client = APIClient()
|
||||
self.phone = "9981111111"
|
||||
self.password = "12345670"
|
||||
self.path = reverse("change-password-change-password")
|
||||
|
||||
self.user = get_user_model().objects.create_user(
|
||||
phone=self.phone, password=self.password, email="test@example.com"
|
||||
)
|
||||
self.client.force_authenticate(user=self.user)
|
||||
|
||||
def test_change_password_success(self):
|
||||
data = {
|
||||
"old_password": self.password,
|
||||
"new_password": "newpassword",
|
||||
}
|
||||
response = self.client.post(self.path, data=data, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['data']["detail"], "password changed successfully")
|
||||
self.assertTrue(self.user.check_password("newpassword"))
|
||||
|
||||
def test_change_password_invalid_old_password(self):
|
||||
data = {
|
||||
"old_password": "wrongpassword",
|
||||
"new_password": "newpassword",
|
||||
}
|
||||
response = self.client.post(self.path, data=data, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
|
||||
self.assertEqual(response.data['data']["detail"], "invalida password")
|
||||
|
||||
def test_change_password_serializer_validation(self):
|
||||
data = {
|
||||
"old_password": self.password,
|
||||
"new_password": "newpassword",
|
||||
}
|
||||
serializer = ChangePasswordSerializer(data=data)
|
||||
self.assertTrue(serializer.is_valid())
|
||||
|
||||
data = {
|
||||
"old_password": self.password,
|
||||
"new_password": "123",
|
||||
}
|
||||
serializer = ChangePasswordSerializer(data=data)
|
||||
self.assertFalse(serializer.is_valid())
|
||||
|
||||
def test_change_password_view_permissions(self):
|
||||
self.client.force_authenticate(user=None)
|
||||
response = self.client.post(self.path, data={}, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
26
user/core/apps/accounts/urls.py
Normal file
26
user/core/apps/accounts/urls.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
Accounts app urls
|
||||
"""
|
||||
|
||||
from django.urls import path, include
|
||||
from rest_framework_simplejwt import views as jwt_views
|
||||
from .views import RegisterView, ResetPasswordView, MeView, ChangePasswordView
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register("", RegisterView, basename="auth")
|
||||
router.register("", ResetPasswordView, basename="reset-password")
|
||||
router.register("", MeView, basename="me")
|
||||
router.register("", ChangePasswordView, basename="change-password")
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path("", include(router.urls)),
|
||||
path("token/", jwt_views.TokenObtainPairView.as_view(), name="token_obtain_pair"),
|
||||
path("token/verify/", jwt_views.TokenVerifyView.as_view(), name="token_verify"),
|
||||
path(
|
||||
"token/refresh/",
|
||||
jwt_views.TokenRefreshView.as_view(),
|
||||
name="token_refresh",
|
||||
),
|
||||
]
|
||||
1
user/core/apps/accounts/views/__init__.py
Normal file
1
user/core/apps/accounts/views/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .auth import * # noqa
|
||||
209
user/core/apps/accounts/views/auth.py
Normal file
209
user/core/apps/accounts/views/auth.py
Normal file
@@ -0,0 +1,209 @@
|
||||
import uuid
|
||||
from typing import Type
|
||||
|
||||
from core.services import UserService, SmsService
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_core import exceptions
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from rest_framework import status, throttling, request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
from django_core.mixins import BaseViewSetMixin
|
||||
from rest_framework.decorators import action
|
||||
from ..serializers import (
|
||||
RegisterSerializer,
|
||||
ConfirmSerializer,
|
||||
ResendSerializer,
|
||||
ResetPasswordSerializer,
|
||||
ResetConfirmationSerializer,
|
||||
SetPasswordSerializer,
|
||||
UserSerializer,
|
||||
UserUpdateSerializer,
|
||||
)
|
||||
from rest_framework.permissions import AllowAny
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from drf_spectacular.utils import OpenApiResponse
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from ..serializers import ChangePasswordSerializer
|
||||
|
||||
from .. import models
|
||||
|
||||
|
||||
@extend_schema(tags=["register"])
|
||||
class RegisterView(BaseViewSetMixin, GenericViewSet, UserService):
|
||||
throttle_classes = [throttling.UserRateThrottle]
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_serializer_class(self):
|
||||
match self.action:
|
||||
case "register":
|
||||
return RegisterSerializer
|
||||
case "confirm":
|
||||
return ConfirmSerializer
|
||||
case "resend":
|
||||
return ResendSerializer
|
||||
case _:
|
||||
return RegisterSerializer
|
||||
|
||||
@action(methods=["POST"], detail=False, url_path="register")
|
||||
def register(self, request):
|
||||
ser = self.get_serializer(data=request.data)
|
||||
ser.is_valid(raise_exception=True)
|
||||
data = ser.data
|
||||
phone = data.get("phone")
|
||||
# Create pending user
|
||||
self.create_user(phone, data.get("first_name"), data.get("last_name"), data.get("password"))
|
||||
self.send_confirmation(phone) # Send confirmation code for sms eskiz.uz
|
||||
return Response(
|
||||
{"detail": _("Sms %(phone)s raqamiga yuborildi") % {"phone": phone}},
|
||||
status=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
|
||||
@extend_schema(summary="Auth confirm.", description="Auth confirm user.")
|
||||
@action(methods=["POST"], detail=False, url_path="confirm")
|
||||
def confirm(self, request):
|
||||
ser = self.get_serializer(data=request.data)
|
||||
ser.is_valid(raise_exception=True)
|
||||
data = ser.data
|
||||
phone, code = data.get("phone"), data.get("code")
|
||||
try:
|
||||
if SmsService.check_confirm(phone, code=code):
|
||||
token = self.validate_user(get_user_model().objects.filter(phone=phone).first())
|
||||
return Response(
|
||||
data={
|
||||
"detail": _("Tasdiqlash ko'di qabul qilindi"),
|
||||
"token": token,
|
||||
},
|
||||
status=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
except exceptions.SmsException as e:
|
||||
raise PermissionDenied(e) # Response exception for APIException
|
||||
except Exception as e:
|
||||
raise PermissionDenied(e) # Api exception for APIException
|
||||
|
||||
@action(methods=["POST"], detail=False, url_path="resend")
|
||||
def resend(self, rq: Type[request.Request]):
|
||||
ser = self.get_serializer(data=rq.data)
|
||||
ser.is_valid(raise_exception=True)
|
||||
phone = ser.data.get("phone")
|
||||
self.send_confirmation(phone)
|
||||
return Response({"detail": _("Sms %(phone)s raqamiga yuborildi") % {"phone": phone}})
|
||||
|
||||
|
||||
@extend_schema(tags=["reset-password"])
|
||||
class ResetPasswordView(BaseViewSetMixin, GenericViewSet, UserService):
|
||||
permission_classes = [AllowAny]
|
||||
|
||||
def get_serializer_class(self):
|
||||
match self.action:
|
||||
case "reset_password":
|
||||
return ResetPasswordSerializer
|
||||
case "reset_confirm":
|
||||
return ResetConfirmationSerializer
|
||||
case "reset_password_set":
|
||||
return SetPasswordSerializer
|
||||
case _:
|
||||
return None
|
||||
|
||||
@action(methods=["POST"], detail=False, url_path="reset-password")
|
||||
def reset_password(self, request):
|
||||
ser = self.get_serializer(data=request.data)
|
||||
ser.is_valid(raise_exception=True)
|
||||
phone = ser.data.get("phone")
|
||||
self.send_confirmation(phone)
|
||||
return Response({"detail": _("Sms %(phone)s raqamiga yuborildi") % {"phone": phone}})
|
||||
|
||||
@action(methods=["POST"], detail=False, url_path="reset-password-confirm")
|
||||
def reset_confirm(self, request):
|
||||
ser = self.get_serializer(data=request.data)
|
||||
ser.is_valid(raise_exception=True)
|
||||
|
||||
data = ser.data
|
||||
code, phone = data.get("code"), data.get("phone")
|
||||
try:
|
||||
SmsService.check_confirm(phone, code)
|
||||
token = models.ResetToken.objects.create(
|
||||
user=get_user_model().objects.filter(phone=phone).first(),
|
||||
token=str(uuid.uuid4()),
|
||||
)
|
||||
return Response(
|
||||
data={
|
||||
"token": token.token,
|
||||
"created_at": token.created_at,
|
||||
"updated_at": token.updated_at,
|
||||
},
|
||||
status=status.HTTP_200_OK,
|
||||
)
|
||||
except exceptions.SmsException as e:
|
||||
raise PermissionDenied(str(e))
|
||||
except Exception as e:
|
||||
raise PermissionDenied(str(e))
|
||||
|
||||
@action(methods=["POST"], detail=False, url_path="reset-password-set")
|
||||
def reset_password_set(self, request):
|
||||
ser = self.get_serializer(data=request.data)
|
||||
ser.is_valid(raise_exception=True)
|
||||
data = ser.data
|
||||
token = data.get("token")
|
||||
password = data.get("password")
|
||||
token = models.ResetToken.objects.filter(token=token)
|
||||
if not token.exists():
|
||||
raise PermissionDenied(_("Invalid token"))
|
||||
phone = token.first().user.phone
|
||||
token.delete()
|
||||
self.change_password(phone, password)
|
||||
return Response({"detail": _("password updated")}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@extend_schema(tags=["me"])
|
||||
class MeView(BaseViewSetMixin, GenericViewSet, UserService):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_serializer_class(self):
|
||||
match self.action:
|
||||
case "me":
|
||||
return UserSerializer
|
||||
case "user_update":
|
||||
return UserUpdateSerializer
|
||||
case _:
|
||||
return None
|
||||
|
||||
@action(methods=["GET", "OPTIONS"], detail=False, url_path="me")
|
||||
def me(self, request):
|
||||
return Response(self.get_serializer(request.user).data)
|
||||
|
||||
@action(methods=["PATCH", "PUT"], detail=False, url_path="user-update")
|
||||
def user_update(self, request):
|
||||
ser = self.get_serializer(instance=request.user, data=request.data, partial=True)
|
||||
ser.is_valid(raise_exception=True)
|
||||
ser.save()
|
||||
return Response({"detail": _("Malumotlar yangilandi")})
|
||||
|
||||
|
||||
@extend_schema(tags=["change-password"], description="Parolni o'zgartirish uchun")
|
||||
class ChangePasswordView(BaseViewSetMixin, GenericViewSet):
|
||||
serializer_class = ChangePasswordSerializer
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
@extend_schema(
|
||||
request=serializer_class,
|
||||
responses={200: OpenApiResponse(ChangePasswordSerializer)},
|
||||
summary="Change user password.",
|
||||
description="Change password of the authenticated user.",
|
||||
)
|
||||
@action(methods=["POST"], detail=False, url_path="change-password")
|
||||
def change_password(self, request, *args, **kwargs):
|
||||
user = self.request.user
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
if user.check_password(request.data["old_password"]):
|
||||
user.password = make_password(request.data["new_password"])
|
||||
user.save()
|
||||
return Response(
|
||||
data={"detail": "password changed successfully"},
|
||||
status=status.HTTP_200_OK,
|
||||
)
|
||||
raise PermissionDenied(_("invalida password"))
|
||||
2
user/core/apps/logs/.gitignore
vendored
Normal file
2
user/core/apps/logs/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
3
user/core/services/__init__.py
Normal file
3
user/core/services/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .otp import * # noqa
|
||||
from .sms import * # noqa
|
||||
from .user import * # noqa
|
||||
135
user/core/services/otp.py
Normal file
135
user/core/services/otp.py
Normal file
@@ -0,0 +1,135 @@
|
||||
import requests
|
||||
from config.env import env
|
||||
|
||||
|
||||
class ConsoleService:
|
||||
|
||||
def __init__(self) -> None: ...
|
||||
|
||||
def send_sms(self, phone_number, message):
|
||||
print(phone_number, message)
|
||||
|
||||
|
||||
class EskizService:
|
||||
GET = "GET"
|
||||
POST = "POST"
|
||||
PATCH = "PATCH"
|
||||
CONTACT = "contact"
|
||||
|
||||
def __init__(self, api_url=None, email=None, password=None, callback_url=None):
|
||||
self.api_url = api_url or env("SMS_API_URL")
|
||||
self.email = email or env("SMS_LOGIN")
|
||||
self.password = password or env("SMS_PASSWORD")
|
||||
self.callback_url = callback_url
|
||||
self.headers = {}
|
||||
|
||||
self.methods = {
|
||||
"auth_user": "auth/user",
|
||||
"auth_login": "auth/login",
|
||||
"auth_refresh": "auth/refresh",
|
||||
"send_message": "message/sms/send",
|
||||
}
|
||||
|
||||
def request(self, api_path, data=None, method=None, headers=None):
|
||||
incoming_data = {"status": "error"}
|
||||
|
||||
try:
|
||||
response = requests.request(
|
||||
method,
|
||||
f"{self.api_url}/{api_path}",
|
||||
data=data,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
if api_path == self.methods["auth_refresh"]:
|
||||
if response.status_code == 200:
|
||||
incoming_data["status"] = "success"
|
||||
else:
|
||||
incoming_data = response.json()
|
||||
except requests.RequestException as error:
|
||||
raise Exception(str(error))
|
||||
|
||||
return incoming_data
|
||||
|
||||
def auth(self):
|
||||
data = {"email": self.email, "password": self.password}
|
||||
|
||||
return self.request(self.methods["auth_login"], data=data, method=self.POST)
|
||||
|
||||
def refresh_token(self):
|
||||
token = self.auth()["data"]["token"]
|
||||
self.headers["Authorization"] = "Bearer " + token
|
||||
|
||||
context = {
|
||||
"headers": self.headers,
|
||||
"method": self.PATCH,
|
||||
"api_path": self.methods["auth_refresh"],
|
||||
}
|
||||
|
||||
return self.request(
|
||||
context["api_path"],
|
||||
method=context["method"],
|
||||
headers=context["headers"],
|
||||
)
|
||||
|
||||
def get_my_user_info(self):
|
||||
token = self.auth()["data"]["token"]
|
||||
self.headers["Authorization"] = "Bearer " + token
|
||||
|
||||
data = {
|
||||
"headers": self.headers,
|
||||
"method": self.GET,
|
||||
"api_path": self.methods["auth_user"],
|
||||
}
|
||||
|
||||
return self.request(data["api_path"], method=data["method"], headers=data["headers"])
|
||||
|
||||
def add_sms_contact(self, first_name, phone_number, group):
|
||||
token = self.auth()["data"]["token"]
|
||||
self.headers["Authorization"] = "Bearer " + token
|
||||
|
||||
data = {
|
||||
"name": first_name,
|
||||
"email": self.email,
|
||||
"group": group,
|
||||
"mobile_phone": phone_number,
|
||||
}
|
||||
|
||||
context = {
|
||||
"headers": self.headers,
|
||||
"method": self.POST,
|
||||
"api_path": self.CONTACT,
|
||||
"data": data,
|
||||
}
|
||||
|
||||
return self.request(
|
||||
context["api_path"],
|
||||
data=context["data"],
|
||||
method=context["method"],
|
||||
headers=context["headers"],
|
||||
)
|
||||
|
||||
def send_sms(self, phone_number, message):
|
||||
token = self.auth()["data"]["token"]
|
||||
self.headers["Authorization"] = "Bearer " + token
|
||||
|
||||
data = {
|
||||
"from": 4546,
|
||||
"mobile_phone": phone_number,
|
||||
"callback_url": self.callback_url,
|
||||
"message": message,
|
||||
}
|
||||
|
||||
context = {
|
||||
"headers": self.headers,
|
||||
"method": self.POST,
|
||||
"api_path": self.methods["send_message"],
|
||||
"data": data,
|
||||
}
|
||||
|
||||
return self.request(
|
||||
context["api_path"],
|
||||
data=context["data"],
|
||||
method=context["method"],
|
||||
headers=context["headers"],
|
||||
)
|
||||
57
user/core/services/sms.py
Normal file
57
user/core/services/sms.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django_core import exceptions, models, tasks
|
||||
|
||||
|
||||
class SmsService:
|
||||
@staticmethod
|
||||
def send_confirm(phone):
|
||||
# TODO: Deploy this change when deploying -> code = random.randint(1000, 9999) # noqa
|
||||
code = 1111
|
||||
|
||||
sms_confirm, status = models.SmsConfirm.objects.get_or_create(phone=phone, defaults={"code": code})
|
||||
|
||||
sms_confirm.sync_limits()
|
||||
|
||||
if sms_confirm.resend_unlock_time is not None:
|
||||
expired = sms_confirm.interval(sms_confirm.resend_unlock_time)
|
||||
exception = exceptions.SmsException(f"Resend blocked, try again in {expired}", expired=expired)
|
||||
raise exception
|
||||
|
||||
sms_confirm.code = code
|
||||
sms_confirm.try_count = 0
|
||||
sms_confirm.resend_count += 1
|
||||
sms_confirm.phone = phone
|
||||
sms_confirm.expired_time = datetime.now() + timedelta(seconds=models.SmsConfirm.SMS_EXPIRY_SECONDS) # noqa
|
||||
sms_confirm.resend_unlock_time = datetime.now() + timedelta(
|
||||
seconds=models.SmsConfirm.SMS_EXPIRY_SECONDS
|
||||
) # noqa
|
||||
sms_confirm.save()
|
||||
|
||||
tasks.SendConfirm.delay(phone, code)
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def check_confirm(phone, code):
|
||||
sms_confirm = models.SmsConfirm.objects.filter(phone=phone).first()
|
||||
|
||||
if sms_confirm is None:
|
||||
raise exceptions.SmsException("Invalid confirmation code")
|
||||
|
||||
sms_confirm.sync_limits()
|
||||
|
||||
if sms_confirm.is_expired():
|
||||
raise exceptions.SmsException("Time for confirmation has expired")
|
||||
|
||||
if sms_confirm.is_block():
|
||||
expired = sms_confirm.interval(sms_confirm.unlock_time)
|
||||
raise exceptions.SmsException(f"Try again in {expired}")
|
||||
|
||||
if sms_confirm.code == code:
|
||||
sms_confirm.delete()
|
||||
return True
|
||||
|
||||
sms_confirm.try_count += 1
|
||||
sms_confirm.save()
|
||||
|
||||
raise exceptions.SmsException("Invalid confirmation code")
|
||||
64
user/core/services/user.py
Normal file
64
user/core/services/user.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from datetime import datetime
|
||||
|
||||
from core.services import sms
|
||||
from django.contrib.auth import get_user_model, hashers
|
||||
from django.utils.translation import gettext as _
|
||||
from django_core import exceptions
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
from rest_framework_simplejwt import tokens
|
||||
|
||||
|
||||
class UserService(sms.SmsService):
|
||||
def get_token(self, user):
|
||||
refresh = tokens.RefreshToken.for_user(user)
|
||||
|
||||
return {
|
||||
"refresh": str(refresh),
|
||||
"access": str(refresh.access_token),
|
||||
}
|
||||
|
||||
def create_user(self, phone, first_name, last_name, password):
|
||||
get_user_model().objects.update_or_create(
|
||||
phone=phone,
|
||||
defaults={
|
||||
"phone": phone,
|
||||
"first_name": first_name,
|
||||
"last_name": last_name,
|
||||
"password": hashers.make_password(password),
|
||||
},
|
||||
)
|
||||
|
||||
def send_confirmation(self, phone) -> bool:
|
||||
try:
|
||||
self.send_confirm(phone)
|
||||
return True
|
||||
except exceptions.SmsException as e:
|
||||
raise PermissionDenied(_("Qayta sms yuborish uchun kuting: {}").format(e.kwargs.get("expired")))
|
||||
except Exception:
|
||||
raise PermissionDenied(_("Serverda xatolik yuz berdi"))
|
||||
|
||||
def validate_user(self, user) -> dict:
|
||||
"""
|
||||
Create user if user not found
|
||||
"""
|
||||
if user.validated_at is None:
|
||||
user.validated_at = datetime.now()
|
||||
user.save()
|
||||
token = self.get_token(user)
|
||||
return token
|
||||
|
||||
def is_validated(self, user) -> bool:
|
||||
"""
|
||||
User is validated check
|
||||
"""
|
||||
if user.validated_at is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
def change_password(self, phone, password):
|
||||
"""
|
||||
Change password
|
||||
"""
|
||||
user = get_user_model().objects.filter(phone=phone).first()
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
3
user/core/utils/__init__.py
Normal file
3
user/core/utils/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .cache import * # noqa
|
||||
from .console import * # noqa
|
||||
from .core import * # noqa
|
||||
18
user/core/utils/cache.py
Normal file
18
user/core/utils/cache.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import hashlib
|
||||
|
||||
from django.core.cache import cache
|
||||
|
||||
from config.env import env
|
||||
|
||||
|
||||
class Cache:
|
||||
def remember(self, func, key: str, timeout=None, *args, **kwargs):
|
||||
cache_enabled = env.bool("CACHE_ENABLED")
|
||||
key = hashlib.md5(key.encode("utf-8")).hexdigest()
|
||||
response = cache.get(key)
|
||||
if not cache_enabled:
|
||||
return func(*args, **kwargs)
|
||||
elif response is None:
|
||||
response = func(*args, **kwargs)
|
||||
cache.set(key, response, env.int("CACHE_TIME") if timeout is None else timeout)
|
||||
return response
|
||||
79
user/core/utils/console.py
Normal file
79
user/core/utils/console.py
Normal file
@@ -0,0 +1,79 @@
|
||||
import logging
|
||||
import os
|
||||
from typing import Any, Union
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import management
|
||||
|
||||
|
||||
class Console(management.BaseCommand):
|
||||
"""
|
||||
Console logging class
|
||||
"""
|
||||
|
||||
def get_stdout(self):
|
||||
base_command = management.BaseCommand()
|
||||
return base_command.stdout
|
||||
|
||||
def get_style(self):
|
||||
base_command = management.BaseCommand()
|
||||
return base_command.style
|
||||
|
||||
def success(self, message):
|
||||
logging.debug(message)
|
||||
self.get_stdout().write(self.get_style().SUCCESS(message))
|
||||
|
||||
def error(self, message):
|
||||
logging.error(message)
|
||||
self.get_stdout().write(self.get_style().ERROR(message))
|
||||
|
||||
def log(self, message):
|
||||
self.get_stdout().write(
|
||||
self.get_style().ERROR(
|
||||
"\n{line}\n{message}\n{line}\n".format(
|
||||
message=message, line="=" * len(message)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class BaseMake(management.BaseCommand):
|
||||
path: str
|
||||
|
||||
def __init__(self, *args, **options):
|
||||
super().__init__(*args, **options)
|
||||
self.console = Console()
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("name")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
name = options.get("name")
|
||||
if name is None:
|
||||
name = ""
|
||||
|
||||
stub = open(os.path.join(settings.BASE_DIR, f"resources/stub/{self.path}.stub"))
|
||||
data: Union[Any] = stub.read()
|
||||
stub.close()
|
||||
|
||||
stub = data.replace("{{name}}", name or "")
|
||||
|
||||
|
||||
core_http_path = os.path.join(settings.BASE_DIR, "core/http")
|
||||
if os.path.exists(
|
||||
os.path.join(core_http_path, f"{self.path}/{name.lower()}.py")
|
||||
): # noqa
|
||||
self.console.error(f"{self.name} already exists")
|
||||
return
|
||||
|
||||
if not os.path.exists(os.path.join(core_http_path, self.path)):
|
||||
os.makedirs(os.path.join(core_http_path, self.path))
|
||||
|
||||
file = open(
|
||||
os.path.join(core_http_path, f"{self.path}/{name.lower()}.py"),
|
||||
"w+",
|
||||
)
|
||||
file.write(stub) # type: ignore
|
||||
file.close()
|
||||
|
||||
self.console.success(f"{self.name} created")
|
||||
6
user/core/utils/core.py
Normal file
6
user/core/utils/core.py
Normal file
@@ -0,0 +1,6 @@
|
||||
class Helper:
|
||||
"""
|
||||
Helper class to handle index
|
||||
"""
|
||||
|
||||
pass
|
||||
33
user/core/utils/storage.py
Normal file
33
user/core/utils/storage.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from typing import Optional, Union
|
||||
|
||||
from config.env import env
|
||||
|
||||
|
||||
class Storage:
|
||||
|
||||
storages = ["AWS", "MINIO", "FILE", "STATIC"]
|
||||
|
||||
def __init__(self, storage: Union[str], storage_type: Union[str] = "default") -> None:
|
||||
self.storage = storage
|
||||
self.sorage_type = storage_type
|
||||
if storage not in self.storages:
|
||||
raise ValueError(f"Invalid storage type: {storage}")
|
||||
|
||||
def get_backend(self) -> Optional[str]:
|
||||
match self.storage:
|
||||
case "AWS" | "MINIO":
|
||||
return "storages.backends.s3boto3.S3Boto3Storage"
|
||||
case "FILE":
|
||||
return "django.core.files.storage.FileSystemStorage"
|
||||
case "STATIC":
|
||||
return "django.contrib.staticfiles.storage.StaticFilesStorage"
|
||||
|
||||
def get_options(self) -> Optional[str]:
|
||||
match self.storage:
|
||||
case "AWS" | "MINIO":
|
||||
if self.sorage_type == "default":
|
||||
return {"bucket_name": env.str("STORAGE_BUCKET_MEDIA")}
|
||||
elif self.sorage_type == "static":
|
||||
return {"bucket_name": env.str("STORAGE_BUCKET_STATIC")}
|
||||
case _:
|
||||
return {}
|
||||
55
user/docker-compose.yml
Normal file
55
user/docker-compose.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
networks:
|
||||
auth:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
pg_data: null
|
||||
rabbitmq: null
|
||||
pycache: null
|
||||
|
||||
services:
|
||||
nginx:
|
||||
networks:
|
||||
- auth
|
||||
ports:
|
||||
- ${PORT:-8001}:80
|
||||
volumes:
|
||||
- ./resources/layout/nginx.conf:/etc/nginx/nginx.conf
|
||||
- ./resources/:/usr/share/nginx/html/resources/
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./docker/Dockerfile.nginx
|
||||
depends_on:
|
||||
- web
|
||||
web:
|
||||
networks:
|
||||
- auth
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./docker/Dockerfile.web
|
||||
restart: always
|
||||
command: ${COMMAND:-sh ./entrypoint.sh}
|
||||
environment:
|
||||
- PYTHONPYCACHEPREFIX=/var/cache/pycache
|
||||
volumes:
|
||||
- .:/code
|
||||
- pycache:/var/cache/pycache
|
||||
depends_on:
|
||||
- db
|
||||
- redis
|
||||
db:
|
||||
networks:
|
||||
- auth
|
||||
image: postgres:16
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_DB: django
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: '2309'
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
redis:
|
||||
networks:
|
||||
- auth
|
||||
restart: always
|
||||
image: redis
|
||||
3
user/docker/Dockerfile.nginx
Normal file
3
user/docker/Dockerfile.nginx
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM nginx:alpine
|
||||
|
||||
COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf
|
||||
9
user/docker/Dockerfile.web
Normal file
9
user/docker/Dockerfile.web
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM jscorptech/django:v0.5
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
COPY ./ /code
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
|
||||
|
||||
CMD ["sh", "./resources/scripts/entrypoint.sh"]
|
||||
8
user/jst.json
Normal file
8
user/jst.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"dirs": {
|
||||
"apps": "./core/apps/",
|
||||
"locale": "./resources/locale/"
|
||||
},
|
||||
"stubs": {},
|
||||
"apps": "core.apps."
|
||||
}
|
||||
24
user/manage.py
Normal file
24
user/manage.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
from config.env import env
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", env("DJANGO_SETTINGS_MODULE"))
|
||||
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()
|
||||
21
user/pyproject.toml
Normal file
21
user/pyproject.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[tool.black]
|
||||
line-length = 120
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
line_length = 120
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
DJANGO_SETTINGS_MODULE = "config.settings.local"
|
||||
python_files = "tests.py test_*.py *_tests.py"
|
||||
filterwarnings = [
|
||||
"ignore::DeprecationWarning",
|
||||
"ignore::PendingDeprecationWarning",
|
||||
"ignore::ResourceWarning",
|
||||
"ignore::Warning" # This line will ignore all warnings
|
||||
]
|
||||
|
||||
|
||||
[tool.flake8]
|
||||
max-line-length = 120
|
||||
ignore = ["E701", "E704", "W503"]
|
||||
45
user/requirements.txt
Normal file
45
user/requirements.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
backports.tarfile==1.2.0
|
||||
celery==5.4.0
|
||||
django-cors-headers==4.6.0
|
||||
django-environ==0.11.2
|
||||
django-extensions==3.2.3
|
||||
django-filter==24.3
|
||||
django-redis==5.4.0
|
||||
django-unfold==0.42.0
|
||||
djangorestframework-simplejwt==5.3.1
|
||||
drf-spectacular==0.28.0
|
||||
importlib-metadata==8.5.0
|
||||
importlib-resources==6.4.5
|
||||
inflect==7.3.1
|
||||
jaraco.collections==5.1.0
|
||||
packaging==24.2
|
||||
pip-chill==1.0.3
|
||||
platformdirs==4.3.6
|
||||
psycopg2-binary==2.9.10
|
||||
tomli==2.2.1
|
||||
uvicorn==0.32.1
|
||||
jst-django-core~=1.1.8
|
||||
rich
|
||||
pydantic
|
||||
bcrypt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
django-cacheops~=7.1
|
||||
django-silk
|
||||
|
||||
# !NOTE: on-server
|
||||
# gunicorn
|
||||
|
||||
|
||||
django-storages
|
||||
boto3
|
||||
|
||||
|
||||
# !NOTE: on-websocket
|
||||
# websockets
|
||||
# channels-redis
|
||||
1
user/resources/.gitignore
vendored
Normal file
1
user/resources/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
staticfiles/
|
||||
3
user/resources/layout/.flake8
Normal file
3
user/resources/layout/.flake8
Normal file
@@ -0,0 +1,3 @@
|
||||
[flake8]
|
||||
max-line-length = 120
|
||||
ignore = E701, E704, W503
|
||||
13
user/resources/layout/Dockerfile.alpine
Normal file
13
user/resources/layout/Dockerfile.alpine
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM python:3.13-alpine
|
||||
|
||||
ENV PYTHONPYCACHEPREFIX=/dev/null
|
||||
|
||||
RUN apk update && apk add git gettext
|
||||
|
||||
WORKDIR /code
|
||||
|
||||
COPY requirements.txt /code/requirements.txt
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
|
||||
|
||||
CMD ["sh", "./entrypoint.sh"]
|
||||
3
user/resources/layout/Dockerfile.nginx
Normal file
3
user/resources/layout/Dockerfile.nginx
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM nginx:alpine
|
||||
|
||||
COPY ./resources/layout/nginx.conf /etc/nginx/nginx.conf
|
||||
5
user/resources/layout/mypy.ini
Normal file
5
user/resources/layout/mypy.ini
Normal file
@@ -0,0 +1,5 @@
|
||||
[mypy]
|
||||
check_untyped_defs = True
|
||||
|
||||
[mypy-requests.*]
|
||||
ignore_missing_imports = True
|
||||
54
user/resources/layout/nginx.conf
Normal file
54
user/resources/layout/nginx.conf
Normal file
@@ -0,0 +1,54 @@
|
||||
# Main configuration block
|
||||
worker_processes 1;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Logging settings (optional)
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
client_max_body_size 1024M;
|
||||
|
||||
# Server block for handling requests
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
server_name _;
|
||||
|
||||
location / {
|
||||
proxy_pass http://user:8000;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_set_header Host $http_host;
|
||||
}
|
||||
location /ws/ {
|
||||
proxy_pass http://user:8000; # Uvicorn serveri ishga tushadigan port
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $http_host;
|
||||
}
|
||||
|
||||
location /resources/static/ {
|
||||
alias /usr/share/nginx/html/resources/staticfiles/;
|
||||
}
|
||||
|
||||
location /resources/media/ {
|
||||
alias /usr/share/nginx/html/resources/media/;
|
||||
}
|
||||
}
|
||||
}
|
||||
0
user/resources/locale/.gitkeep
Normal file
0
user/resources/locale/.gitkeep
Normal file
49
user/resources/locale/en/LC_MESSAGES/django.po
Normal file
49
user/resources/locale/en/LC_MESSAGES/django.po
Normal file
@@ -0,0 +1,49 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-02-15 16:40+0500\n"
|
||||
"PO-Revision-Date: 2024-02-09 15:09+0500\n"
|
||||
"Last-Translator: <admin@gmail.com>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
"X-Translated-Using: django-rosetta 0.10.0\n"
|
||||
|
||||
#: config/settings/common.py:148
|
||||
msgid "Russia"
|
||||
msgstr ""
|
||||
|
||||
#: config/settings/common.py:149
|
||||
msgid "English"
|
||||
msgstr ""
|
||||
|
||||
#: config/settings/common.py:150
|
||||
msgid "Uzbek"
|
||||
msgstr ""
|
||||
|
||||
#: core/http/admin/index.py:20
|
||||
msgid "Custom Field"
|
||||
msgstr ""
|
||||
|
||||
#: core/http/tasks/index.py:13
|
||||
#, python-format
|
||||
msgid "Sizning Tasdiqlash ko'dingiz: %(code)s"
|
||||
msgstr ""
|
||||
|
||||
#: resources/templates/user/home.html:18
|
||||
msgid "Django"
|
||||
msgstr ""
|
||||
|
||||
#: resources/templates/user/home.html:19
|
||||
msgid "Assalomu aleykum"
|
||||
msgstr ""
|
||||
51
user/resources/locale/ru/LC_MESSAGES/django.po
Normal file
51
user/resources/locale/ru/LC_MESSAGES/django.po
Normal file
@@ -0,0 +1,51 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-02-15 16:40+0500\n"
|
||||
"PO-Revision-Date: 2024-02-09 15:09+0500\n"
|
||||
"Last-Translator: <admin@gmail.com>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
|
||||
"n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || "
|
||||
"(n%100>=11 && n%100<=14)? 2 : 3);\n"
|
||||
"X-Translated-Using: django-rosetta 0.10.0\n"
|
||||
|
||||
#: config/settings/common.py:148
|
||||
msgid "Russia"
|
||||
msgstr ""
|
||||
|
||||
#: config/settings/common.py:149
|
||||
msgid "English"
|
||||
msgstr ""
|
||||
|
||||
#: config/settings/common.py:150
|
||||
msgid "Uzbek"
|
||||
msgstr ""
|
||||
|
||||
#: core/http/admin/index.py:20
|
||||
msgid "Custom Field"
|
||||
msgstr ""
|
||||
|
||||
#: core/http/tasks/index.py:13
|
||||
#, python-format
|
||||
msgid "Sizning Tasdiqlash ko'dingiz: %(code)s"
|
||||
msgstr ""
|
||||
|
||||
#: resources/templates/user/home.html:18
|
||||
msgid "Django"
|
||||
msgstr ""
|
||||
|
||||
#: resources/templates/user/home.html:19
|
||||
msgid "Assalomu aleykum"
|
||||
msgstr ""
|
||||
55
user/resources/locale/uz/LC_MESSAGES/django.po
Normal file
55
user/resources/locale/uz/LC_MESSAGES/django.po
Normal file
@@ -0,0 +1,55 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-02-15 16:40+0500\n"
|
||||
"PO-Revision-Date: 2024-02-10 22:46+0500\n"
|
||||
"Last-Translator: <admin@gmail.com>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=1; plural=0;\n"
|
||||
"X-Translated-Using: django-rosetta 0.10.0\n"
|
||||
|
||||
#: config/settings/common.py:148
|
||||
msgid "Russia"
|
||||
msgstr ""
|
||||
|
||||
#: config/settings/common.py:149
|
||||
msgid "English"
|
||||
msgstr ""
|
||||
|
||||
#: config/settings/common.py:150
|
||||
msgid "Uzbek"
|
||||
msgstr ""
|
||||
|
||||
#: core/http/admin/index.py:20
|
||||
msgid "Custom Field"
|
||||
msgstr ""
|
||||
|
||||
#: core/http/tasks/index.py:13
|
||||
#, python-format
|
||||
msgid "Sizning Tasdiqlash ko'dingiz: %(code)s"
|
||||
msgstr ""
|
||||
|
||||
#: resources/templates/user/home.html:18
|
||||
msgid "Django"
|
||||
msgstr ""
|
||||
|
||||
#: resources/templates/user/home.html:19
|
||||
msgid "Assalomu aleykum"
|
||||
msgstr ""
|
||||
|
||||
#~ msgid "Home"
|
||||
#~ msgstr "Bosh sahifa"
|
||||
|
||||
#~ msgid "Homes"
|
||||
#~ msgstr "Bosh sahifa"
|
||||
2
user/resources/logs/.gitignore
vendored
Normal file
2
user/resources/logs/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
user/resources/media/.gitignore
vendored
Normal file
2
user/resources/media/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
5
user/resources/scripts/backup.sh
Normal file
5
user/resources/scripts/backup.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
file=/tmp/db-$(/usr/bin/date +\%Y-%m-%d-%H:%M:%S).sql
|
||||
container=postgres
|
||||
/usr/bin/docker container exec $container pg_dump -U postgres django > $file
|
||||
mc cp $file b2/buket-name
|
||||
rm $file
|
||||
11
user/resources/scripts/entrypoint-server.sh
Normal file
11
user/resources/scripts/entrypoint-server.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
python3 manage.py collectstatic --noinput
|
||||
python3 manage.py migrate --noinput
|
||||
|
||||
gunicorn config.wsgi:application -b 0.0.0.0:8000 --workers $(($(nproc) * 2 + 1))
|
||||
|
||||
|
||||
|
||||
exit $?
|
||||
|
||||
|
||||
11
user/resources/scripts/entrypoint.sh
Normal file
11
user/resources/scripts/entrypoint.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
python3 manage.py collectstatic --noinput
|
||||
python3 manage.py migrate --noinput
|
||||
|
||||
uvicorn config.asgi:application --host 0.0.0.0 --port 8000 --reload --reload-dir core --reload-dir config
|
||||
|
||||
|
||||
|
||||
exit $?
|
||||
|
||||
|
||||
0
user/resources/static/css/app.css
Normal file
0
user/resources/static/css/app.css
Normal file
109
user/resources/static/css/error.css
Normal file
109
user/resources/static/css/error.css
Normal file
@@ -0,0 +1,109 @@
|
||||
* {
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#notfound {
|
||||
position: relative;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
#notfound .notfound {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
-webkit-transform: translate(-50%, -50%);
|
||||
-ms-transform: translate(-50%, -50%);
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.notfound {
|
||||
max-width: 710px;
|
||||
width: 100%;
|
||||
padding-left: 190px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.notfound .notfound-404 {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
}
|
||||
|
||||
.notfound .notfound-404 h1 {
|
||||
font-family: 'Passion One', cursive;
|
||||
color: #00b5c3;
|
||||
font-size: 150px;
|
||||
letter-spacing: 15.5px;
|
||||
margin: 0px;
|
||||
font-weight: 900;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
-webkit-transform: translate(-50%, -50%);
|
||||
-ms-transform: translate(-50%, -50%);
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.notfound h2 {
|
||||
font-family: 'Raleway', sans-serif;
|
||||
color: #292929;
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 2.5px;
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.notfound p {
|
||||
font-family: 'Raleway', sans-serif;
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
margin-top: 0;
|
||||
margin-bottom: 15px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.notfound a {
|
||||
font-family: 'Raleway', sans-serif;
|
||||
font-size: 14px;
|
||||
text-decoration: none;
|
||||
text-transform: uppercase;
|
||||
background: #fff;
|
||||
display: inline-block;
|
||||
padding: 15px 30px;
|
||||
border-radius: 40px;
|
||||
color: #292929;
|
||||
font-weight: 700;
|
||||
-webkit-box-shadow: 0px 4px 15px -5px rgba(0, 0, 0, 0.3);
|
||||
box-shadow: 0px 4px 15px -5px rgba(0, 0, 0, 0.3);
|
||||
-webkit-transition: 0.2s all;
|
||||
transition: 0.2s all;
|
||||
}
|
||||
|
||||
.notfound a:hover {
|
||||
color: #fff;
|
||||
background-color: #00b5c3;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 480px) {
|
||||
.notfound {
|
||||
text-align: center;
|
||||
}
|
||||
.notfound .notfound-404 {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.notfound {
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
}
|
||||
}
|
||||
3
user/resources/static/css/input.css
Normal file
3
user/resources/static/css/input.css
Normal file
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
5
user/resources/static/css/jazzmin.css
Normal file
5
user/resources/static/css/jazzmin.css
Normal file
@@ -0,0 +1,5 @@
|
||||
.login-logo img {
|
||||
border-radius: 100%;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
}
|
||||
772
user/resources/static/css/output.css
Normal file
772
user/resources/static/css/output.css
Normal file
@@ -0,0 +1,772 @@
|
||||
*, ::before, ::after {
|
||||
--tw-border-spacing-x: 0;
|
||||
--tw-border-spacing-y: 0;
|
||||
--tw-translate-x: 0;
|
||||
--tw-translate-y: 0;
|
||||
--tw-rotate: 0;
|
||||
--tw-skew-x: 0;
|
||||
--tw-skew-y: 0;
|
||||
--tw-scale-x: 1;
|
||||
--tw-scale-y: 1;
|
||||
--tw-pan-x: ;
|
||||
--tw-pan-y: ;
|
||||
--tw-pinch-zoom: ;
|
||||
--tw-scroll-snap-strictness: proximity;
|
||||
--tw-gradient-from-position: ;
|
||||
--tw-gradient-via-position: ;
|
||||
--tw-gradient-to-position: ;
|
||||
--tw-ordinal: ;
|
||||
--tw-slashed-zero: ;
|
||||
--tw-numeric-figure: ;
|
||||
--tw-numeric-spacing: ;
|
||||
--tw-numeric-fraction: ;
|
||||
--tw-ring-inset: ;
|
||||
--tw-ring-offset-width: 0px;
|
||||
--tw-ring-offset-color: #fff;
|
||||
--tw-ring-color: rgb(59 130 246 / 0.5);
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-shadow: 0 0 #0000;
|
||||
--tw-shadow-colored: 0 0 #0000;
|
||||
--tw-blur: ;
|
||||
--tw-brightness: ;
|
||||
--tw-contrast: ;
|
||||
--tw-grayscale: ;
|
||||
--tw-hue-rotate: ;
|
||||
--tw-invert: ;
|
||||
--tw-saturate: ;
|
||||
--tw-sepia: ;
|
||||
--tw-drop-shadow: ;
|
||||
--tw-backdrop-blur: ;
|
||||
--tw-backdrop-brightness: ;
|
||||
--tw-backdrop-contrast: ;
|
||||
--tw-backdrop-grayscale: ;
|
||||
--tw-backdrop-hue-rotate: ;
|
||||
--tw-backdrop-invert: ;
|
||||
--tw-backdrop-opacity: ;
|
||||
--tw-backdrop-saturate: ;
|
||||
--tw-backdrop-sepia: ;
|
||||
--tw-contain-size: ;
|
||||
--tw-contain-layout: ;
|
||||
--tw-contain-paint: ;
|
||||
--tw-contain-style: ;
|
||||
}
|
||||
|
||||
::backdrop {
|
||||
--tw-border-spacing-x: 0;
|
||||
--tw-border-spacing-y: 0;
|
||||
--tw-translate-x: 0;
|
||||
--tw-translate-y: 0;
|
||||
--tw-rotate: 0;
|
||||
--tw-skew-x: 0;
|
||||
--tw-skew-y: 0;
|
||||
--tw-scale-x: 1;
|
||||
--tw-scale-y: 1;
|
||||
--tw-pan-x: ;
|
||||
--tw-pan-y: ;
|
||||
--tw-pinch-zoom: ;
|
||||
--tw-scroll-snap-strictness: proximity;
|
||||
--tw-gradient-from-position: ;
|
||||
--tw-gradient-via-position: ;
|
||||
--tw-gradient-to-position: ;
|
||||
--tw-ordinal: ;
|
||||
--tw-slashed-zero: ;
|
||||
--tw-numeric-figure: ;
|
||||
--tw-numeric-spacing: ;
|
||||
--tw-numeric-fraction: ;
|
||||
--tw-ring-inset: ;
|
||||
--tw-ring-offset-width: 0px;
|
||||
--tw-ring-offset-color: #fff;
|
||||
--tw-ring-color: rgb(59 130 246 / 0.5);
|
||||
--tw-ring-offset-shadow: 0 0 #0000;
|
||||
--tw-ring-shadow: 0 0 #0000;
|
||||
--tw-shadow: 0 0 #0000;
|
||||
--tw-shadow-colored: 0 0 #0000;
|
||||
--tw-blur: ;
|
||||
--tw-brightness: ;
|
||||
--tw-contrast: ;
|
||||
--tw-grayscale: ;
|
||||
--tw-hue-rotate: ;
|
||||
--tw-invert: ;
|
||||
--tw-saturate: ;
|
||||
--tw-sepia: ;
|
||||
--tw-drop-shadow: ;
|
||||
--tw-backdrop-blur: ;
|
||||
--tw-backdrop-brightness: ;
|
||||
--tw-backdrop-contrast: ;
|
||||
--tw-backdrop-grayscale: ;
|
||||
--tw-backdrop-hue-rotate: ;
|
||||
--tw-backdrop-invert: ;
|
||||
--tw-backdrop-opacity: ;
|
||||
--tw-backdrop-saturate: ;
|
||||
--tw-backdrop-sepia: ;
|
||||
--tw-contain-size: ;
|
||||
--tw-contain-layout: ;
|
||||
--tw-contain-paint: ;
|
||||
--tw-contain-style: ;
|
||||
}
|
||||
|
||||
/*
|
||||
! tailwindcss v3.4.14 | MIT License | https://tailwindcss.com
|
||||
*/
|
||||
|
||||
/*
|
||||
1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4)
|
||||
2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116)
|
||||
*/
|
||||
|
||||
*,
|
||||
::before,
|
||||
::after {
|
||||
box-sizing: border-box;
|
||||
/* 1 */
|
||||
border-width: 0;
|
||||
/* 2 */
|
||||
border-style: solid;
|
||||
/* 2 */
|
||||
border-color: #e5e7eb;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
::before,
|
||||
::after {
|
||||
--tw-content: '';
|
||||
}
|
||||
|
||||
/*
|
||||
1. Use a consistent sensible line-height in all browsers.
|
||||
2. Prevent adjustments of font size after orientation changes in iOS.
|
||||
3. Use a more readable tab size.
|
||||
4. Use the user's configured `sans` font-family by default.
|
||||
5. Use the user's configured `sans` font-feature-settings by default.
|
||||
6. Use the user's configured `sans` font-variation-settings by default.
|
||||
7. Disable tap highlights on iOS
|
||||
*/
|
||||
|
||||
html,
|
||||
:host {
|
||||
line-height: 1.5;
|
||||
/* 1 */
|
||||
-webkit-text-size-adjust: 100%;
|
||||
/* 2 */
|
||||
-moz-tab-size: 4;
|
||||
/* 3 */
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
/* 3 */
|
||||
font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||
/* 4 */
|
||||
font-feature-settings: normal;
|
||||
/* 5 */
|
||||
font-variation-settings: normal;
|
||||
/* 6 */
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
/* 7 */
|
||||
}
|
||||
|
||||
/*
|
||||
1. Remove the margin in all browsers.
|
||||
2. Inherit line-height from `html` so users can set them as a class directly on the `html` element.
|
||||
*/
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
/* 1 */
|
||||
line-height: inherit;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
1. Add the correct height in Firefox.
|
||||
2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)
|
||||
3. Ensure horizontal rules are visible by default.
|
||||
*/
|
||||
|
||||
hr {
|
||||
height: 0;
|
||||
/* 1 */
|
||||
color: inherit;
|
||||
/* 2 */
|
||||
border-top-width: 1px;
|
||||
/* 3 */
|
||||
}
|
||||
|
||||
/*
|
||||
Add the correct text decoration in Chrome, Edge, and Safari.
|
||||
*/
|
||||
|
||||
abbr:where([title]) {
|
||||
-webkit-text-decoration: underline dotted;
|
||||
text-decoration: underline dotted;
|
||||
}
|
||||
|
||||
/*
|
||||
Remove the default font size and weight for headings.
|
||||
*/
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
font-size: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
/*
|
||||
Reset links to optimize for opt-in styling instead of opt-out.
|
||||
*/
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
/*
|
||||
Add the correct font weight in Edge and Safari.
|
||||
*/
|
||||
|
||||
b,
|
||||
strong {
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
/*
|
||||
1. Use the user's configured `mono` font-family by default.
|
||||
2. Use the user's configured `mono` font-feature-settings by default.
|
||||
3. Use the user's configured `mono` font-variation-settings by default.
|
||||
4. Correct the odd `em` font sizing in all browsers.
|
||||
*/
|
||||
|
||||
code,
|
||||
kbd,
|
||||
samp,
|
||||
pre {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
/* 1 */
|
||||
font-feature-settings: normal;
|
||||
/* 2 */
|
||||
font-variation-settings: normal;
|
||||
/* 3 */
|
||||
font-size: 1em;
|
||||
/* 4 */
|
||||
}
|
||||
|
||||
/*
|
||||
Add the correct font size in all browsers.
|
||||
*/
|
||||
|
||||
small {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
/*
|
||||
Prevent `sub` and `sup` elements from affecting the line height in all browsers.
|
||||
*/
|
||||
|
||||
sub,
|
||||
sup {
|
||||
font-size: 75%;
|
||||
line-height: 0;
|
||||
position: relative;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
sub {
|
||||
bottom: -0.25em;
|
||||
}
|
||||
|
||||
sup {
|
||||
top: -0.5em;
|
||||
}
|
||||
|
||||
/*
|
||||
1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)
|
||||
2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
|
||||
3. Remove gaps between table borders by default.
|
||||
*/
|
||||
|
||||
table {
|
||||
text-indent: 0;
|
||||
/* 1 */
|
||||
border-color: inherit;
|
||||
/* 2 */
|
||||
border-collapse: collapse;
|
||||
/* 3 */
|
||||
}
|
||||
|
||||
/*
|
||||
1. Change the font styles in all browsers.
|
||||
2. Remove the margin in Firefox and Safari.
|
||||
3. Remove default padding in all browsers.
|
||||
*/
|
||||
|
||||
button,
|
||||
input,
|
||||
optgroup,
|
||||
select,
|
||||
textarea {
|
||||
font-family: inherit;
|
||||
/* 1 */
|
||||
font-feature-settings: inherit;
|
||||
/* 1 */
|
||||
font-variation-settings: inherit;
|
||||
/* 1 */
|
||||
font-size: 100%;
|
||||
/* 1 */
|
||||
font-weight: inherit;
|
||||
/* 1 */
|
||||
line-height: inherit;
|
||||
/* 1 */
|
||||
letter-spacing: inherit;
|
||||
/* 1 */
|
||||
color: inherit;
|
||||
/* 1 */
|
||||
margin: 0;
|
||||
/* 2 */
|
||||
padding: 0;
|
||||
/* 3 */
|
||||
}
|
||||
|
||||
/*
|
||||
Remove the inheritance of text transform in Edge and Firefox.
|
||||
*/
|
||||
|
||||
button,
|
||||
select {
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
/*
|
||||
1. Correct the inability to style clickable types in iOS and Safari.
|
||||
2. Remove default button styles.
|
||||
*/
|
||||
|
||||
button,
|
||||
input:where([type='button']),
|
||||
input:where([type='reset']),
|
||||
input:where([type='submit']) {
|
||||
-webkit-appearance: button;
|
||||
/* 1 */
|
||||
background-color: transparent;
|
||||
/* 2 */
|
||||
background-image: none;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
Use the modern Firefox focus style for all focusable elements.
|
||||
*/
|
||||
|
||||
:-moz-focusring {
|
||||
outline: auto;
|
||||
}
|
||||
|
||||
/*
|
||||
Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737)
|
||||
*/
|
||||
|
||||
:-moz-ui-invalid {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/*
|
||||
Add the correct vertical alignment in Chrome and Firefox.
|
||||
*/
|
||||
|
||||
progress {
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
/*
|
||||
Correct the cursor style of increment and decrement buttons in Safari.
|
||||
*/
|
||||
|
||||
::-webkit-inner-spin-button,
|
||||
::-webkit-outer-spin-button {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/*
|
||||
1. Correct the odd appearance in Chrome and Safari.
|
||||
2. Correct the outline style in Safari.
|
||||
*/
|
||||
|
||||
[type='search'] {
|
||||
-webkit-appearance: textfield;
|
||||
/* 1 */
|
||||
outline-offset: -2px;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
Remove the inner padding in Chrome and Safari on macOS.
|
||||
*/
|
||||
|
||||
::-webkit-search-decoration {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
/*
|
||||
1. Correct the inability to style clickable types in iOS and Safari.
|
||||
2. Change font properties to `inherit` in Safari.
|
||||
*/
|
||||
|
||||
::-webkit-file-upload-button {
|
||||
-webkit-appearance: button;
|
||||
/* 1 */
|
||||
font: inherit;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
Add the correct display in Chrome and Safari.
|
||||
*/
|
||||
|
||||
summary {
|
||||
display: list-item;
|
||||
}
|
||||
|
||||
/*
|
||||
Removes the default spacing and border for appropriate elements.
|
||||
*/
|
||||
|
||||
blockquote,
|
||||
dl,
|
||||
dd,
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6,
|
||||
hr,
|
||||
figure,
|
||||
p,
|
||||
pre {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
legend {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ol,
|
||||
ul,
|
||||
menu {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Reset default styling for dialogs.
|
||||
*/
|
||||
|
||||
dialog {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Prevent resizing textareas horizontally by default.
|
||||
*/
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
/*
|
||||
1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300)
|
||||
2. Set the default placeholder color to the user's configured gray 400 color.
|
||||
*/
|
||||
|
||||
input::-moz-placeholder, textarea::-moz-placeholder {
|
||||
opacity: 1;
|
||||
/* 1 */
|
||||
color: #9ca3af;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
input::placeholder,
|
||||
textarea::placeholder {
|
||||
opacity: 1;
|
||||
/* 1 */
|
||||
color: #9ca3af;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
Set the default cursor for buttons.
|
||||
*/
|
||||
|
||||
button,
|
||||
[role="button"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/*
|
||||
Make sure disabled buttons don't get the pointer cursor.
|
||||
*/
|
||||
|
||||
:disabled {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/*
|
||||
1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
|
||||
2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
|
||||
This can trigger a poorly considered lint error in some tools but is included by design.
|
||||
*/
|
||||
|
||||
img,
|
||||
svg,
|
||||
video,
|
||||
canvas,
|
||||
audio,
|
||||
iframe,
|
||||
embed,
|
||||
object {
|
||||
display: block;
|
||||
/* 1 */
|
||||
vertical-align: middle;
|
||||
/* 2 */
|
||||
}
|
||||
|
||||
/*
|
||||
Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14)
|
||||
*/
|
||||
|
||||
img,
|
||||
video {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* Make elements with the HTML hidden attribute stay hidden by default */
|
||||
|
||||
[hidden]:where(:not([hidden="until-found"])) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.static {
|
||||
position: static;
|
||||
}
|
||||
|
||||
.m-2 {
|
||||
margin: 0.5rem;
|
||||
}
|
||||
|
||||
.mx-4 {
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.mb-3 {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.mb-5 {
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.ml-1 {
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
.mt-3 {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.mt-4 {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.mt-5 {
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
|
||||
.block {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.inline-block {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
.h-\[100vh\] {
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.w-\[100vw\] {
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
.w-full {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.grid-cols-1 {
|
||||
grid-template-columns: repeat(1, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.items-center {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.justify-end {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.justify-center {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.gap-8 {
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.gap-x-3 {
|
||||
-moz-column-gap: 0.75rem;
|
||||
column-gap: 0.75rem;
|
||||
}
|
||||
|
||||
.whitespace-nowrap {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.rounded {
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.border {
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
.border-black {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(0 0 0 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.bg-blue-100 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(219 234 254 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-gray-200 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(229 231 235 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.p-4 {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.px-2 {
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
|
||||
.px-\[40px\] {
|
||||
padding-left: 40px;
|
||||
padding-right: 40px;
|
||||
}
|
||||
|
||||
.py-1 {
|
||||
padding-top: 0.25rem;
|
||||
padding-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.text-\[20px\] {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.text-\[25px\] {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.text-\[30px\] {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.text-\[40px\] {
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
.font-\[400\] {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.font-\[600\] {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.font-bold {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.font-semibold {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.leading-normal {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.text-black {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(0 0 0 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.text-blue-500 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(59 130 246 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.text-red-500 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(239 68 68 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
.sm\:grid-cols-2 {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.md\:grid-cols-3 {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.lg\:grid-cols-4 {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
BIN
user/resources/static/images/logo.png
Normal file
BIN
user/resources/static/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user