Various fixes

This commit is contained in:
Tracker-Friendly 2024-05-14 07:47:59 +01:00
parent 930db146ff
commit 41f2a74ed1
4 changed files with 11 additions and 35 deletions

View File

@ -1,6 +1,6 @@
[config] [config]
PORT = 8080 PORT = 8083
SECRET_KEY = placeholder SECRET_KEY = placeholdeqwoihqrqigriqukvfblisubgsierhueofbor
UPLOAD_FOLDER = uploads UPLOAD_FOLDER = uploads
PASSWORD_REQUIREMENT = 8 PASSWORD_REQUIREMENT = 8
UPLOAD_LIMIT = 8 UPLOAD_LIMIT = 8

34
main
View File

@ -240,9 +240,9 @@ async def user(pageusername):
if usersession: if usersession:
userCookie = get_session(usersession) userCookie = get_session(usersession)
user = get_user(userCookie["id"]) user = get_user(userCookie["id"])
return await render_template("user.html", userdata=user, createddate=datetime.datetime.utcfromtimestamp(int(str(pageuser["created"]).split(".")[0])).strftime("%Y-%m-%d"), pageuser=pageuser) return await render_template("user.html", userdata=user, createddate=datetime.datetime.fromtimestamp(int(str(pageuser["created"]).split(".")[0])).strftime("%Y-%m-%d"), pageuser=pageuser)
else: else:
return await render_template("user.html", createddate=datetime.datetime.utcfromtimestamp(int(str(pageuser["created"]).split(".")[0])).strftime("%Y-%m-%d"), pageuser=pageuser) return await render_template("user.html", createddate=datetime.datetime.fromtimestamp(int(str(pageuser["created"]).split(".")[0])).strftime("%Y-%m-%d"), pageuser=pageuser)
else: else:
return """<img src="https://http.cat/images/404.jpg">""", 404 return """<img src="https://http.cat/images/404.jpg">""", 404
@ -553,39 +553,13 @@ async def cdn(filename):
else: else:
return "file doesn't exist!!" return "file doesn't exist!!"
@app.route("/signup", methods=("GET", "POST")) @app.route("/signup", methods=("GET", "POST"))
async def signup(): async def signup():
usersession = request.cookies.get("session_DO_NOT_SHARE") usersession = request.cookies.get("session_DO_NOT_SHARE")
if usersession: if usersession:
return redirect(url_for("main")) return redirect(url_for("main"))
if request.method == "POST":
requestData = await request.form
if not check_username_taken(requestData["username"]) == "error":
await flash("Username already taken :3")
return redirect(url_for("signup"))
if not requestData["username"].isalnum():
await flash("Username must be alphanumeric :3")
return redirect(url_for("signup"))
if not len(requestData["password"]) > int(PASSWORD_REQUIREMENT):
await flash("Password must contain at least " + PASSWORD_REQUIREMENT + " characters")
return redirect(url_for("signup"))
hashedpassword = generate_password_hash(requestData["password"])
conn = get_db_connection()
conn.execute("INSERT INTO users (username, password, created, htmldescription) VALUES (?, ?, ?, ?)",
(requestData["username"], hashedpassword, str(time.time()), ""))
conn.commit()
conn.close()
return redirect(url_for("login"))
else: else:
return await render_template("signup.html") return redirect(url_for("oauth"))
@app.route("/login", methods=("GET", "POST")) @app.route("/login", methods=("GET", "POST"))
async def login(): async def login():
@ -637,7 +611,7 @@ async def settings():
userCookie = get_session(usersession) userCookie = get_session(usersession)
user = get_user(userCookie["id"]) user = get_user(userCookie["id"])
return await render_template("settings.html", userdata=user, createddate=datetime.datetime.utcfromtimestamp(int(str(user["created"]).split(".")[0])).strftime("%Y-%m-%d %H:%m:%S")) return await render_template("settings.html", userdata=user, createddate=datetime.datetime.fromtimestamp(int(str(user["created"]).split(".")[0])).strftime("%Y-%m-%d %H:%m:%S"))
else: else:
return redirect("/") return redirect("/")

View File

@ -19,8 +19,7 @@
<a href="/settings/logout" class="right r">log out</a> <a href="/settings/logout" class="right r">log out</a>
<a href="/settings" class="right">{{ userdata.username }}</a> <a href="/settings" class="right">{{ userdata.username }}</a>
{% else %} {% else %}
<a href="/signup" class="right r">sign up</a> <a href="/oauth" class="right r">login</a>
<a href="/login" class="right">log in</a>
{% endif %} {% endif %}
</div> </div>

View File

@ -10,6 +10,9 @@
</head> </head>
<body> <body>
<script>
window.location.replace("/oauth")
</script>
<form class="accountform" method="post"> <form class="accountform" method="post">
<br> <br>
<a href="/">back</a> <a href="/">back</a>