From 9bb18a6cca00bc2bc7f45913508e98dbf11b1447 Mon Sep 17 00:00:00 2001
From: trinkey
- Hmm. That doesn't look right.
Make sure the URL is correct and try again.
(Error 404 - Page not found)
diff --git a/tauth/templates/base.html b/tauth/templates/base.html
index 4c55939..8538d86 100644
--- a/tauth/templates/base.html
+++ b/tauth/templates/base.html
@@ -8,21 +8,14 @@
+
+
+
{% block head %}{% endblock %}
-
-
-
+
+
+
diff --git a/tauth/templates/css/base.css b/tauth/templates/css/base.css
deleted file mode 100644
index 965550e..0000000
--- a/tauth/templates/css/base.css
+++ /dev/null
@@ -1,60 +0,0 @@
-/* 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/index.html b/tauth/templates/index.html
new file mode 100644
index 0000000..73cc965
--- /dev/null
+++ b/tauth/templates/index.html
@@ -0,0 +1,6 @@
+{% extends "base.html" %}
+
+{% block body %}
+ Welcome back, {{ username }}!
+ tAuth
+{% endblock %}
diff --git a/tauth/templates/js/theme.js b/tauth/templates/js/theme.js
deleted file mode 100644
index e0fd755..0000000
--- a/tauth/templates/js/theme.js
+++ /dev/null
@@ -1,30 +0,0 @@
-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/signup.html b/tauth/templates/noauth/signup.html
index aa41700..77b8806 100644
--- a/tauth/templates/noauth/signup.html
+++ b/tauth/templates/noauth/signup.html
@@ -4,12 +4,30 @@
Sign Up
+
+ + + {% endblock %} diff --git a/tauth/views/helper.py b/tauth/views/helper.py index c5a9676..d60faa9 100644 --- a/tauth/views/helper.py +++ b/tauth/views/helper.py @@ -4,6 +4,8 @@ from django.core.handlers.wsgi import WSGIRequest from django.http import HttpResponse from django.template import loader +from tauth.settings import config + COLORS = ["rosewater", "flamingo", "pink", "mauve", "red", "maroon", "peach", "yellow", "green", "teal", "sky", "sapphire", "blue", "lavender"] def render_template( @@ -17,7 +19,8 @@ def render_template( ) -> HttpResponse: c = { "theme": "auto", - "accent": random.choice(COLORS) + "accent": random.choice(COLORS), + "config": config } for key, val in context.items(): diff --git a/tauth/views/templates.py b/tauth/views/templates.py index 8442a88..5cf989e 100644 --- a/tauth/views/templates.py +++ b/tauth/views/templates.py @@ -1,19 +1,67 @@ +import re + +from django.contrib.auth import login as set_auth +from django.contrib.auth import logout as remove_auth +from django.contrib.auth.models import User from django.core.handlers.wsgi import WSGIRequest -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from config import ALLOW_NEW_USERS +from tauth.models import TUser from .helper import render_template def index(request: WSGIRequest) -> HttpResponse: + if request.user.is_authenticated: + return render_template( + request, "index.html", + username=request.user.get_username() + ) return render_template( request, "noauth/index.html", new_users=ALLOW_NEW_USERS ) def signup(request: WSGIRequest) -> HttpResponse: + if request.user.is_authenticated: + return HttpResponseRedirect("/") + if ALLOW_NEW_USERS: + if request.method == "POST": + username = (request.POST.get("username") or "").lower().strip() + password = (request.POST.get("password") or "") + error = None + + if len(username) < 2 or len(username) > 30 or not re.match("^[a-z0-9_][a-z0-9_\\-]{0,28}[a-z0-9_]$", username): + error = "Invalid username" + + elif len(password) < 6 or len(password) > 100 or not (any([i.isalpha() for i in password]) and any([i.isnumeric() for i in password]) and any([not i.isalnum() for i in password])): + error = "Invalid password" + + else: + try: + u = User.objects.create_user( + username=username, + password=password + ) + except User.DoesNotExist: + error = "Username already in use" + else: + TUser.objects.create(user=u) + + set_auth(request, u) + return HttpResponseRedirect("/") + + return render_template( + request, "noauth/signup.html", + title="Sign Up", + error=error, + repopulate={ + "username": username + } + ) + return render_template( request, "noauth/signup.html", title="Sign Up"