initial commit

This commit is contained in:
trinkey 2024-12-20 08:59:39 -05:00
commit 42389fe7ac
26 changed files with 344 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
__pycache__/

8
config.py Normal file
View file

@ -0,0 +1,8 @@
ALLOW_NEW_USERS = True
DEBUG = True
ENABLED_APPLICATIONS = {
"search": False,
"music": False,
"messages": False,
"info": False
}

14
manage.py Normal file
View file

@ -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()

0
tauth/__init__.py Normal file
View file

6
tauth/asgi.py Normal file
View file

@ -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()

70
tauth/settings.py Normal file
View file

@ -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"]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

7
tauth/templates/404.html Normal file
View file

@ -0,0 +1,7 @@
{% extends "base.html" %}
{% block card %}
<h1>Hmm. That doesn't look right.</h1>
Make sure the URL is correct and try again.
<small>(Error 404 - Page not found)</small>
{% endblock %}

36
tauth/templates/base.html Normal file
View file

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}{% if title %}{{ title }} - {% endif %}{% endblock %}tAuth</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="pronouns" content="she/her">
{% block head %}{% endblock %}
<style>
{% include "css/base.css" %}
{% block head_css %}{% endblock %}
html {
--accent: var(--{{ accent }});
}
</style>
<script>
{% include "js/theme.js" %}
{% block head_js %}{% endblock %}
</script>
</head>
<body>
<div id="container">
<noscript>Please enable JavaScript!</noscript>
{% block body %}
Something went horribly wrong! Please contact us so we can fix this.
{% endblock %}
</div>
</body>
</html>

View file

@ -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);
}

View file

@ -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();

View file

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block body %}
<h1>tAuth</h1>
<div>The only account you'll ever need</div>
<div><small>(assuming you don't need much)</small></div>
<p>
<a href="/login/">Log in</a>
{% if new_users %} - <a href="/signup/">Sign up</a>{% endif %}
</p>
{% if not new_users %}
<div>This instance isn't accepting new users.</div>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block body %}
<h1>Sign Up</h1>
<div>tAuth</div>
<p>
<form>
{% csrf_token %}
<p>
<div><input required type="text" pattern="[a-z0-9A-Z_][a-z0-9A-Z_\-]{0,30}[a-z0-9A-Z_]" placeholder="Username"></div>
<div><small>2-30 characters, <code>A-Z</code>, <code>0-9</code>, <code>_</code>, and <code>-</code>. Can't start or end with a <code>-</code></small></div>
</p>
</form>
</p>
{% endblock %}

11
tauth/urls.py Normal file
View file

@ -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),
]

1
tauth/views/__init__.py Normal file
View file

@ -0,0 +1 @@
from .templates import index, login, signup # noqa: F401

35
tauth/views/helper.py Normal file
View file

@ -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

30
tauth/views/templates.py Normal file
View file

@ -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"
)

6
tauth/wsgi.py Normal file
View file

@ -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()