From 25e0ec2c60c3fbbc01db821a5f5fa35a5cfc6ae2 Mon Sep 17 00:00:00 2001 From: deadvey Date: Mon, 13 Oct 2025 18:05:41 +0100 Subject: [PATCH] Is this the initial commit? I forgot --- .gitignore | 1 + config.py | 1 + data_management.py | 14 ++++++++++++++ functions.py | 5 +++++ main.py | 23 ++++++++++++++++------- 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 data_management.py create mode 100644 functions.py diff --git a/.gitignore b/.gitignore index 82bd622..2149892 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ wiki-pages/* webroot/* venv/ __pycache__/ +data/* *.swp diff --git a/config.py b/config.py index 89a09e0..aadc2d7 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,4 @@ host='0.0.0.0' port=8080 debug=True +database={'host': 'localhost', 'username': 'root', 'database': 'deadwiki', 'password': '123'} diff --git a/data_management.py b/data_management.py new file mode 100644 index 0000000..8b722d3 --- /dev/null +++ b/data_management.py @@ -0,0 +1,14 @@ +import config +import json + +def get_data(data_type, key, value): + if data_type == 'users': + users_json_string = open('data/users.json', 'r').read() + json_data = json.loads(users_json_string) + for json_object in json_data: + if json_object[key] == value: + return json_object + + return -1 + + diff --git a/functions.py b/functions.py new file mode 100644 index 0000000..d33bcbe --- /dev/null +++ b/functions.py @@ -0,0 +1,5 @@ +import hashlib + +def sha512_hash(Password): + HashedPassword = hashlib.sha512(Password.encode('utf-8')).hexdigest() + return HashedPassword diff --git a/main.py b/main.py index 9f84222..e38623c 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ from flask import Flask, render_template, request, redirect from markdown_it import MarkdownIt import os import config +import functions +import data_management md = MarkdownIt().enable('table') @@ -46,18 +48,25 @@ def edit_page(page): # Forms @app.route('/submit-edit', methods=['POST']) -def handle_data(): +def submit_edit_page(): page = request.form['page'] content = request.form['content'] username = request.form['username'] - password = request.form['password'] + password_hash = functions.sha512_hash(request.form['password']) - with open(f'./wiki-pages/{page}.md', 'w') as file: - print(content) - file.write(content) - file.close() + user_object = data_management.get_data('users', 'username', username) + print(user_object['password_hash']) + print(password_hash) + + if user_object['password_hash'] == password_hash: + with open(f'./wiki-pages/{page}.md', 'w') as file: + file.write(content) + file.close() + return redirect(f'/wiki/{page}', 302) + + else: + return 'Incorrect password' - return redirect(f'/wiki/{page}', 302) if __name__ == '__main__':