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/*
|
webroot/*
|
||||||
venv/
|
venv/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
data/*
|
||||||
*.swp
|
*.swp
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
host='0.0.0.0'
|
host='0.0.0.0'
|
||||||
port=8080
|
port=8080
|
||||||
debug=True
|
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
|
17
main.py
17
main.py
@@ -2,6 +2,8 @@ from flask import Flask, render_template, request, redirect
|
|||||||
from markdown_it import MarkdownIt
|
from markdown_it import MarkdownIt
|
||||||
import os
|
import os
|
||||||
import config
|
import config
|
||||||
|
import functions
|
||||||
|
import data_management
|
||||||
|
|
||||||
md = MarkdownIt().enable('table')
|
md = MarkdownIt().enable('table')
|
||||||
|
|
||||||
@@ -46,19 +48,26 @@ def edit_page(page):
|
|||||||
|
|
||||||
# Forms
|
# Forms
|
||||||
@app.route('/submit-edit', methods=['POST'])
|
@app.route('/submit-edit', methods=['POST'])
|
||||||
def handle_data():
|
def submit_edit_page():
|
||||||
page = request.form['page']
|
page = request.form['page']
|
||||||
content = request.form['content']
|
content = request.form['content']
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
password = request.form['password']
|
password_hash = functions.sha512_hash(request.form['password'])
|
||||||
|
|
||||||
|
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:
|
with open(f'./wiki-pages/{page}.md', 'w') as file:
|
||||||
print(content)
|
|
||||||
file.write(content)
|
file.write(content)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
return redirect(f'/wiki/{page}', 302)
|
return redirect(f'/wiki/{page}', 302)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return 'Incorrect password'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(
|
app.run(
|
||||||
|
Reference in New Issue
Block a user