Is this the initial commit? I forgot
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,4 +2,5 @@ wiki-pages/*
|
||||
webroot/*
|
||||
venv/
|
||||
__pycache__/
|
||||
data/*
|
||||
*.swp
|
||||
|
@@ -1,3 +1,4 @@
|
||||
host='0.0.0.0'
|
||||
port=8080
|
||||
debug=True
|
||||
database={'host': 'localhost', 'username': 'root', 'database': 'deadwiki', 'password': '123'}
|
||||
|
14
data_management.py
Normal file
14
data_management.py
Normal file
@@ -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
|
||||
|
||||
|
5
functions.py
Normal file
5
functions.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import hashlib
|
||||
|
||||
def sha512_hash(Password):
|
||||
HashedPassword = hashlib.sha512(Password.encode('utf-8')).hexdigest()
|
||||
return HashedPassword
|
23
main.py
23
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__':
|
||||
|
Reference in New Issue
Block a user