started working on the comments feature
This commit is contained in:
parent
f569620fce
commit
76688b2d2c
5
.gitignore
vendored
5
.gitignore
vendored
@ -5,8 +5,11 @@ __pycache__
|
||||
|
||||
docker-compose.yaml
|
||||
*.sh
|
||||
*.ini
|
||||
|
||||
# Ignore images in posts
|
||||
*.jpg
|
||||
*.png
|
||||
|
||||
# Flask Data & Config
|
||||
*.ini
|
||||
data
|
||||
|
||||
21
app/app.py
21
app/app.py
@ -1,6 +1,7 @@
|
||||
import glob
|
||||
import configparser
|
||||
import random
|
||||
import base64
|
||||
|
||||
import flask
|
||||
import flask_wtf.csrf
|
||||
@ -10,12 +11,13 @@ import markdown
|
||||
|
||||
from post import Post
|
||||
import comment
|
||||
import user
|
||||
|
||||
app = flask.Flask(__name__, static_url_path='', static_folder='static')
|
||||
app.register_blueprint(comment.comments)
|
||||
app.register_blueprint(user.user)
|
||||
|
||||
csrf = flask_wtf.csrf.CSRFProtect()
|
||||
csrf.init_app(app)
|
||||
|
||||
# CONFIG
|
||||
CONFIG_PATH = "./config.ini"
|
||||
config = configparser.ConfigParser()
|
||||
config.read(CONFIG_PATH)
|
||||
@ -25,6 +27,17 @@ STATUS_FILE = config['STATUS']['STATUS_FILE']
|
||||
PORT = int(config['NETWORK']['PORT'])
|
||||
DEV = int(config['NETWORK']['DEV'])
|
||||
|
||||
|
||||
# CSRF Protect
|
||||
app.config['SECRET_KEY'] = base64.b64decode(config["FLASK"]["SECRET"])
|
||||
csrf = flask_wtf.csrf.CSRFProtect()
|
||||
csrf.init_app(app)
|
||||
|
||||
# Session Setup
|
||||
app.config['SESSION_TYPE'] = 'filesystem'
|
||||
app.config['SESSION_FILE_DIR'] = './data/.flask_session/'
|
||||
flask_session.Session(app)
|
||||
|
||||
def get_posts(category_filter : str | None = None) -> list[Post]:
|
||||
post_files = glob.glob(f'{POSTS_FOLDER}/*')
|
||||
try:
|
||||
@ -85,7 +98,7 @@ def index():
|
||||
# Setup Comment Form
|
||||
form = comment.CommentForm()
|
||||
|
||||
return flask.render_template('index.html', posts=posts_and_comments, status=status, form=form)
|
||||
return flask.render_template('index.html', posts=posts_and_comments, status=status, form=form, user="yes")
|
||||
|
||||
# Games Page
|
||||
@app.route('/games/')
|
||||
|
||||
@ -1,14 +1,22 @@
|
||||
import json
|
||||
|
||||
import flask
|
||||
import flask_session
|
||||
import flask_wtf
|
||||
import flask_wtf.csrf
|
||||
import wtforms
|
||||
|
||||
|
||||
|
||||
comments = flask.Blueprint('comment', __name__, template_folder='./templates')
|
||||
|
||||
class CommentForm(flask_wtf.FlaskForm):
|
||||
textbox = wtforms.TextAreaField()
|
||||
textbox = wtforms.TextAreaField('Input')
|
||||
|
||||
@comments.route('/comment/', methods=['POST'])
|
||||
def comment():
|
||||
form = CommentForm(csrf_enabled=True)
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
|
||||
def get_comments(post_id : int) -> list[dict]:
|
||||
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ class Post:
|
||||
date : datetime.datetime
|
||||
body : str
|
||||
file : str
|
||||
id : int
|
||||
|
||||
def __init__(self, file_path):
|
||||
self.file = file_path
|
||||
@ -21,5 +22,7 @@ class Post:
|
||||
date = lines[3].split(":")[1].strip()
|
||||
self.date = datetime.datetime.strptime(date, "%d-%m-%Y")
|
||||
|
||||
self.body = markdown.markdown(''.join(lines[6:]))
|
||||
self.id = int(lines[4].split(":")[1].strip())
|
||||
|
||||
self.body = markdown.markdown(''.join(lines[7:]))
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
category: category
|
||||
author: author
|
||||
date: date
|
||||
id: post id
|
||||
|
||||
# POST
|
||||
## TITLE
|
||||
|
||||
@ -182,16 +182,16 @@ a:hover {
|
||||
margin: 1em;
|
||||
}
|
||||
|
||||
.comment-editor input {
|
||||
.comment-editor textarea {
|
||||
width: 100%;
|
||||
padding: 3em 0;
|
||||
line-height: 140%;
|
||||
height: 6em;
|
||||
padding: 0.75em;
|
||||
|
||||
border-style: solid;
|
||||
/* border-color: var(--secondary50); */
|
||||
border-color: var(--secondary50);
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.comment-editor input:focus {
|
||||
.comment-editor textarea:focus {
|
||||
border: 3px solid var(--accent);
|
||||
}
|
||||
|
||||
@ -34,8 +34,7 @@
|
||||
{% if user %}
|
||||
<div class="comment-editor">
|
||||
<h3>{{ user }}</h3>
|
||||
<form method="post" action="/comment">
|
||||
<!-- <input type="text" class="commenter"> -->
|
||||
<form method="post" action="/comment/">
|
||||
{{ form.textbox }}
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
|
||||
36
app/templates/user/register.html
Normal file
36
app/templates/user/register.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<header>
|
||||
<link rel="shortcut icon" href="index_favicon.ico">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
||||
<title>0x01fe.net - Register</title>
|
||||
</header>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>0x01fe.net</h1>
|
||||
{{ status|safe }}
|
||||
</div>
|
||||
<div class="container">
|
||||
<!-- Sidebar -->
|
||||
<div class="sidebar">
|
||||
<a href="."><u>Home</u></a><br>
|
||||
<a href="./games/">Games</a><br>
|
||||
<a href="./music/">Music</a><br>
|
||||
<a href="./motion-pictures/">Motion Picture</a><br>
|
||||
<a href="./programming/">Programming</a><br>
|
||||
<a href="./about/">About</a>
|
||||
</div>
|
||||
|
||||
<!-- Main Page -->
|
||||
<!-- Get it? D-Log? Like digital log? -->
|
||||
<div class="dlog">
|
||||
<h1>Register</h1>
|
||||
<form method="post" action="/user/register/">
|
||||
{{ form.username }}
|
||||
{{ form.password }}
|
||||
<input type="submit" value="Register">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
25
app/user.py
Normal file
25
app/user.py
Normal file
@ -0,0 +1,25 @@
|
||||
import flask
|
||||
import flask_wtf.csrf
|
||||
import wtforms
|
||||
|
||||
user = flask.Blueprint('user', __name__, template_folder='./templates/user')
|
||||
|
||||
class RegisterUserForm(flask_wtf.FlaskForm):
|
||||
username = wtforms.StringField("Username", [
|
||||
wtforms.validators.Length(min=4, max=32),
|
||||
wtforms.validators.DataRequired()
|
||||
])
|
||||
password = wtforms.PasswordField("Password", [
|
||||
wtforms.validators.Length(min=8, max=64),
|
||||
wtforms.validators.DataRequired()
|
||||
])
|
||||
|
||||
@user.route('/user/add/', methods=["POST"])
|
||||
def add_user():
|
||||
pass
|
||||
|
||||
@user.route('/user/register/')
|
||||
def register_user():
|
||||
form = RegisterUserForm()
|
||||
|
||||
return flask.render_template('register.html', form=form)
|
||||
Loading…
x
Reference in New Issue
Block a user