JS, login, basic listing
This commit is contained in:
parent
b20826ed35
commit
9ce2e08810
|
@ -6,5 +6,11 @@
|
|||
</head>
|
||||
<body>
|
||||
Hello, and welcome to the index.
|
||||
|
||||
{% for thought in thoughts %}
|
||||
<div>
|
||||
{{thought.text}}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
Please enter the password to access this page.
|
||||
|
||||
<form id="password-form">
|
||||
<input type="password" id="password">
|
||||
<input type="submit">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
document.getElementById("password-form").addEventListener("submit", evt => {
|
||||
document.cookie = `password=${document.getElementById("password").value}; max-age=15768000; samesite=strict`;
|
||||
window.location.reload();
|
||||
})
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -15,7 +15,22 @@
|
|||
<input type="submit">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
const textEl = document.getElementById("text");
|
||||
const textExtEl = document.getElementById("extended_text");
|
||||
textEl.addEventListener("keypressed", evt => {
|
||||
// If the length is more than 120
|
||||
const value = textEl.value;
|
||||
if (value.length > 120) {
|
||||
const toMove = value.substring(value.lastIndexOf(" ") + 1); //Plus 1 trims the space
|
||||
textExtEl.value = toMove + textExtEl.value;
|
||||
textEl.value = value.substring(0, value.lastIndexOf(" ") + 1)// Plus 1 keeps the space
|
||||
}
|
||||
});
|
||||
|
||||
const timezoneOffsetEl = document.getElementById("timezone_offset");
|
||||
timezoneOffsetEl.value = (new Date()).getTimezoneOffset();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -4,17 +4,17 @@ from .models import Thought
|
|||
|
||||
|
||||
def index(request):
|
||||
return render(request, "whispermaphone/index.html", {})
|
||||
return render(request, "whispermaphone/index.html", {"thoughts": Thought.objects.all()})
|
||||
|
||||
|
||||
def post(request):
|
||||
if request.method == "POST":
|
||||
try:
|
||||
if not request.COOKIES["password"] == "ChromaticWave":
|
||||
return HttpResponse("Unauthorized", status=401)
|
||||
except KeyError:
|
||||
return HttpResponse("Unauthorized", status=401)
|
||||
try:
|
||||
if not request.COOKIES["password"] == "ChromaticWave":
|
||||
return render(request, "whispermaphone/login.html", status=401)
|
||||
except KeyError:
|
||||
return render(request, "whispermaphone/login.html", status=401)
|
||||
|
||||
if request.method == "POST":
|
||||
Thought(
|
||||
text=request.POST["text"],
|
||||
extended_text=request.POST["extended_text"],
|
||||
|
|
Loading…
Reference in New Issue