commit 42389fe7acdb64e5252894ed55782e8de1b2d566 Author: trinkey Date: Fri Dec 20 08:59:39 2024 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/config.py b/config.py new file mode 100644 index 0000000..7f340fe --- /dev/null +++ b/config.py @@ -0,0 +1,8 @@ +ALLOW_NEW_USERS = True +DEBUG = True +ENABLED_APPLICATIONS = { + "search": False, + "music": False, + "messages": False, + "info": False +} diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..23de32c --- /dev/null +++ b/manage.py @@ -0,0 +1,14 @@ +import os +import sys + + +def main(): + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tauth.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError("Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?") from exc + execute_from_command_line(sys.argv) + +if __name__ == "__main__": + main() diff --git a/tauth/__init__.py b/tauth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tauth/asgi.py b/tauth/asgi.py new file mode 100644 index 0000000..23d45e3 --- /dev/null +++ b/tauth/asgi.py @@ -0,0 +1,6 @@ +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tauth.settings") +application = get_asgi_application() diff --git a/tauth/settings.py b/tauth/settings.py new file mode 100644 index 0000000..5e71183 --- /dev/null +++ b/tauth/settings.py @@ -0,0 +1,70 @@ +from pathlib import Path + +from config import DEBUG # noqa: F401 + +BASE_DIR = Path(__file__).resolve().parent.parent + +SECRET_KEY = "django-insecure--h3t*!a-h+(m7537)oxl9&fpjsin)#ht(5e!8w^5%ea1@f84u1" + +ALLOWED_HOSTS = [] + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "tauth.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [ + BASE_DIR / "tauth/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", + ], + }, + }, +] + +WSGI_APPLICATION = "tauth.wsgi.application" + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + +AUTH_PASSWORD_VALIDATORS = [] + +LANGUAGE_CODE = "en-us" +TIME_ZONE = "UTC" +USE_I18N = True +USE_TZ = True + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +STATIC_ROOT = BASE_DIR / "collected-static" +STATIC_URL = "/static/" +STATICFILES_DIRS = [BASE_DIR / "tauth/static"] diff --git a/tauth/static/font/DejaVuSans-Bold.ttf b/tauth/static/font/DejaVuSans-Bold.ttf new file mode 100644 index 0000000..06db62c Binary files /dev/null and b/tauth/static/font/DejaVuSans-Bold.ttf differ diff --git a/tauth/static/font/DejaVuSans-BoldOblique.ttf b/tauth/static/font/DejaVuSans-BoldOblique.ttf new file mode 100644 index 0000000..802137f Binary files /dev/null and b/tauth/static/font/DejaVuSans-BoldOblique.ttf differ diff --git a/tauth/static/font/DejaVuSans-ExtraLight.ttf b/tauth/static/font/DejaVuSans-ExtraLight.ttf new file mode 100644 index 0000000..0c92b97 Binary files /dev/null and b/tauth/static/font/DejaVuSans-ExtraLight.ttf differ diff --git a/tauth/static/font/DejaVuSans-Oblique.ttf b/tauth/static/font/DejaVuSans-Oblique.ttf new file mode 100644 index 0000000..6c5e38a Binary files /dev/null and b/tauth/static/font/DejaVuSans-Oblique.ttf differ diff --git a/tauth/static/font/DejaVuSans.ttf b/tauth/static/font/DejaVuSans.ttf new file mode 100644 index 0000000..2fbbe69 Binary files /dev/null and b/tauth/static/font/DejaVuSans.ttf differ diff --git a/tauth/static/font/UbuntuMono-Bold.ttf b/tauth/static/font/UbuntuMono-Bold.ttf new file mode 100644 index 0000000..01ad81b Binary files /dev/null and b/tauth/static/font/UbuntuMono-Bold.ttf differ diff --git a/tauth/static/font/UbuntuMono-BoldItalic.ttf b/tauth/static/font/UbuntuMono-BoldItalic.ttf new file mode 100644 index 0000000..731884e Binary files /dev/null and b/tauth/static/font/UbuntuMono-BoldItalic.ttf differ diff --git a/tauth/static/font/UbuntuMono-Italic.ttf b/tauth/static/font/UbuntuMono-Italic.ttf new file mode 100644 index 0000000..b89338d Binary files /dev/null and b/tauth/static/font/UbuntuMono-Italic.ttf differ diff --git a/tauth/static/font/UbuntuMono-Regular.ttf b/tauth/static/font/UbuntuMono-Regular.ttf new file mode 100644 index 0000000..4977028 Binary files /dev/null and b/tauth/static/font/UbuntuMono-Regular.ttf differ diff --git a/tauth/templates/404.html b/tauth/templates/404.html new file mode 100644 index 0000000..823d322 --- /dev/null +++ b/tauth/templates/404.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block card %} +

Hmm. That doesn't look right.

+ Make sure the URL is correct and try again. + (Error 404 - Page not found) +{% endblock %} diff --git a/tauth/templates/base.html b/tauth/templates/base.html new file mode 100644 index 0000000..4c55939 --- /dev/null +++ b/tauth/templates/base.html @@ -0,0 +1,36 @@ + + + + + {% block title %}{% if title %}{{ title }} - {% endif %}{% endblock %}tAuth + + + + + + {% block head %}{% endblock %} + + + + + + + +
+ + {% block body %} + Something went horribly wrong! Please contact us so we can fix this. + {% endblock %} +
+ + diff --git a/tauth/templates/css/base.css b/tauth/templates/css/base.css new file mode 100644 index 0000000..965550e --- /dev/null +++ b/tauth/templates/css/base.css @@ -0,0 +1,60 @@ +/* Colors */ +html { --rosewater: #f5e0dc; --flamingo: #f2cdcd; --pink: #f5c2e7; --mauve: #cba6f7; --red: #f38ba8; --maroon: #eba0ac; --peach: #fab387; --yellow: #f9e2af; --green: #a6e3a1; --teal: #94e2d5; --sky: #89dceb; --sapphire: #74c7ec; --blue: #89b4fa; --lavender: #b4befe; --text: #cdd6f4; --subtext1: #bac2de; --subtext0: #a6adc8; --overlay2: #9399b2; --overlay1: #7f849c; --overlay0: #6c7086; --surface2: #585b70; --surface1: #45475a; --surface0: #313244; --base: #1e1e2e; --mantle: #181825; --crust: #11111b; --base-low-op: #1e1e2ed0 } +html[data-light] { --rosewater: #dc8a78; --flamingo: #dd7878; --pink: #ea76cb; --mauve: #8839ef; --red: #d20f39; --maroon: #e64553; --peach: #fe640b; --yellow: #df8e1d; --green: #40a02b; --teal: #179299; --sky: #04a5e5; --sapphire: #209fb5; --blue: #1e66f5; --lavender: #7287fd; --text: #4c4f69; --subtext1: #5c5f77; --subtext0: #6c6f85; --overlay2: #7c7f93; --overlay1: #8c8fa1; --overlay0: #9ca0b0; --surface2: #acb0be; --surface1: #bcc0cc; --surface0: #ccd0da; --base: #eff1f5; --mantle: #e6e9ef; --crust: #dce0e8; --base-low-op: #eff1f5b0} + +/* Font */ +@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 400; font-display: block; src: url("/static/font/DejaVuSans.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 700; font-display: block; src: url("/static/font/DejaVuSans-Bold.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: italic; font-weight: 400; font-display: block; src: url("/static/font/DejaVuSans-Oblique.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: italic; font-weight: 700; font-display: block; src: url("/static/font/DejaVuSans-BoldOblique.ttf") format("truetype"); } +@font-face { font-family: 'DejaVu Sans'; font-style: normal; font-weight: 200; font-display: block; src: url("/static/font/DejaVuSans-ExtraLight.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: normal; font-weight: 400; font-display: block; src: url("/static/font/UbuntuMono-Regular.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: italic; font-weight: 400; font-display: block; src: url("/static/font/UbuntuMono-Italic.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: normal; font-weight: 700; font-display: block; src: url("/static/font/UbuntuMono-Bold.ttf") format("truetype"); } +@font-face { font-family: "Ubuntu Mono"; font-style: italic; font-weight: 700; font-display: block; src: url("/static/font/UbuntuMono-BoldItalic.ttf") format("truetype"); } + +body { + margin: 0; + width: 100vw; + min-height: 100vh; + overflow-x: hidden; + background-color: var(--base); + color: var(--text); + font-family: "DejaVu Sans"; + /* background-image: linear-gradient( + 135deg, + var(--base) 25%, + var(--mantle) 25%, + var(--mantle) 50%, + var(--base) 50%, + var(--base) 75%, + var(--mantle) 75% + ); + background-size: 20px 20px; + background-repeat: repeat; */ +} + +code, pre { + font-family: "Ubuntu Mono" +} + +small, i { + color: var(--subtext0); +} + +h1 { + color: var(--accent); +} + +a:link, +a:visited { + color: var(--accent); + font-weight: 700; +} + +#container { + text-align: center; + padding: 10px; + width: calc(100vw - 20px); + max-width: calc(100vw - 20px); +} diff --git a/tauth/templates/js/theme.js b/tauth/templates/js/theme.js new file mode 100644 index 0000000..e0fd755 --- /dev/null +++ b/tauth/templates/js/theme.js @@ -0,0 +1,30 @@ +let _themeMM = matchMedia("(prefers-color-scheme: light)"); +let light, useAutoTheme; +// {% if theme == "auto" %} + light = _themeMM.matches; + useAutoTheme = true; +// {% else %} + // {% if theme == "light" %} + light = true; + // {% else %} + light = false; + // {% endif %} + useAutoTheme = false; +// {% endif %} + +function setTheme() { + if (light) { + document.documentElement.setAttribute("data-light", ""); + } else { + document.documentElement.removeAttribute("data-light"); + } +} + +_themeMM.addEventListener("change", function() { + if (useAutoTheme) { + light = _themeMM.matches; + setTheme(); + } +}); + +setTheme(); diff --git a/tauth/templates/noauth/index.html b/tauth/templates/noauth/index.html new file mode 100644 index 0000000..0a23e19 --- /dev/null +++ b/tauth/templates/noauth/index.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block body %} +

tAuth

+
The only account you'll ever need
+
(assuming you don't need much)
+

+ Log in + {% if new_users %} - Sign up{% endif %} +

+ {% if not new_users %} +
This instance isn't accepting new users.
+ {% endif %} +{% endblock %} diff --git a/tauth/templates/noauth/signup.html b/tauth/templates/noauth/signup.html new file mode 100644 index 0000000..aa41700 --- /dev/null +++ b/tauth/templates/noauth/signup.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block body %} +

Sign Up

+
tAuth
+

+

+ {% csrf_token %} +

+

+
2-30 characters, A-Z, 0-9, _, and -. Can't start or end with a -
+

+
+

+{% endblock %} diff --git a/tauth/urls.py b/tauth/urls.py new file mode 100644 index 0000000..4d69972 --- /dev/null +++ b/tauth/urls.py @@ -0,0 +1,11 @@ +from django.contrib import admin +from django.urls import path + +from .views import index, login, signup + +urlpatterns = [ + path("", index), + path("login/", login), + path("signup/", signup), + path("django-admin/", admin.site.urls), +] diff --git a/tauth/views/__init__.py b/tauth/views/__init__.py new file mode 100644 index 0000000..2a70170 --- /dev/null +++ b/tauth/views/__init__.py @@ -0,0 +1 @@ +from .templates import index, login, signup # noqa: F401 diff --git a/tauth/views/helper.py b/tauth/views/helper.py new file mode 100644 index 0000000..c5a9676 --- /dev/null +++ b/tauth/views/helper.py @@ -0,0 +1,35 @@ +import random + +from django.core.handlers.wsgi import WSGIRequest +from django.http import HttpResponse +from django.template import loader + +COLORS = ["rosewater", "flamingo", "pink", "mauve", "red", "maroon", "peach", "yellow", "green", "teal", "sky", "sapphire", "blue", "lavender"] + +def render_template( + request: WSGIRequest, + template: str, + /, *, + status: int=200, + headers: dict[str, str]={}, + content_type: str="text/html", + **context +) -> HttpResponse: + c = { + "theme": "auto", + "accent": random.choice(COLORS) + } + + for key, val in context.items(): + c[key] = val + + resp = HttpResponse( + loader.get_template(template).render(c, request), + status=status, + content_type=content_type + ) + + for key, val in headers.items(): + resp[key] = val + + return resp diff --git a/tauth/views/templates.py b/tauth/views/templates.py new file mode 100644 index 0000000..8442a88 --- /dev/null +++ b/tauth/views/templates.py @@ -0,0 +1,30 @@ +from django.core.handlers.wsgi import WSGIRequest +from django.http import HttpResponse + +from config import ALLOW_NEW_USERS + +from .helper import render_template + + +def index(request: WSGIRequest) -> HttpResponse: + return render_template( + request, "noauth/index.html", + new_users=ALLOW_NEW_USERS + ) + +def signup(request: WSGIRequest) -> HttpResponse: + if ALLOW_NEW_USERS: + return render_template( + request, "noauth/signup.html", + title="Sign Up" + ) + + return render_template( + request, "404.html" + ) + +def login(request: WSGIRequest) -> HttpResponse: + return render_template( + request, "noauth/login.html", + title="Log In" + ) diff --git a/tauth/wsgi.py b/tauth/wsgi.py new file mode 100644 index 0000000..c6e9432 --- /dev/null +++ b/tauth/wsgi.py @@ -0,0 +1,6 @@ +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tauth.settings") +application = get_wsgi_application()