added all my images and stuff
@ -48,7 +48,7 @@ statuses = {}
|
||||
def get_posts(category_filter : str | None = None) -> list[tuple[dict, list]]:
|
||||
post_files = glob.glob(f'{POSTS_FOLDER}/*')
|
||||
try:
|
||||
post_files.remove(f'{POSTS_FOLDER}/POST_TEMPLATE.md')
|
||||
post_files.remove(f'{POSTS_FOLDER}\\POST_TEMPLATE.md')
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
print(f'Couldn\'t remove the template file probably; {post_files}')
|
||||
|
||||
125
app/comment.py
@ -1,61 +1,64 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import flask
|
||||
import flask_wtf.csrf
|
||||
import wtforms
|
||||
|
||||
COMMENTS_PATH = "./data/comments.json"
|
||||
comments = flask.Blueprint('comment', __name__, template_folder='./templates')
|
||||
|
||||
class CommentForm(flask_wtf.FlaskForm):
|
||||
textbox = wtforms.TextAreaField('Input')
|
||||
|
||||
@comments.route('/comment/<string:post_title>', methods=['POST'])
|
||||
def comment(post_title: str):
|
||||
form = CommentForm(csrf_enabled=True)
|
||||
|
||||
save_comment(form.textbox.data, post_title)
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
def save_comment(content: str, post_title: str):
|
||||
with open(COMMENTS_PATH, 'r') as file:
|
||||
comment_data = json.loads(file.read())
|
||||
|
||||
# See if user is logged in, otherwise setup as anon
|
||||
if 'username' in flask.session:
|
||||
username = flask.session['username']
|
||||
else:
|
||||
username = 'Anon'
|
||||
|
||||
comment = {
|
||||
"username" : username,
|
||||
"content" : content
|
||||
}
|
||||
|
||||
# Add comment to JSON data
|
||||
if post_title in comment_data:
|
||||
comment_data[post_title].append(comment)
|
||||
else:
|
||||
comment_data[post_title] = [comment]
|
||||
|
||||
# Save JSON data
|
||||
with open(COMMENTS_PATH, 'w') as file:
|
||||
file.write(json.dumps(comment_data))
|
||||
|
||||
def get_comments(post_title : int) -> list[dict]:
|
||||
|
||||
with open(COMMENTS_PATH, 'r') as file:
|
||||
comment_data = json.loads(file.read())
|
||||
|
||||
if post_title in comment_data:
|
||||
return comment_data[post_title]
|
||||
else:
|
||||
return []
|
||||
|
||||
# Check Comments file exists
|
||||
if not os.path.exists(COMMENTS_PATH):
|
||||
with open(COMMENTS_PATH, 'w+') as file:
|
||||
file.write('{}')
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
import flask
|
||||
import flask_wtf.csrf
|
||||
import wtforms
|
||||
|
||||
COMMENTS_PATH = "./data/comments.json"
|
||||
|
||||
if not os.path.exists('./data/'):
|
||||
os.mkdir('./data/')
|
||||
|
||||
if not os.path.exists(COMMENTS_PATH):
|
||||
with open(COMMENTS_PATH, 'w+') as file:
|
||||
file.write('{}')
|
||||
|
||||
comments = flask.Blueprint('comment', __name__, template_folder='./templates')
|
||||
|
||||
class CommentForm(flask_wtf.FlaskForm):
|
||||
textbox = wtforms.TextAreaField('Input')
|
||||
|
||||
@comments.route('/comment/<string:post_title>', methods=['POST'])
|
||||
def comment(post_title: str):
|
||||
form = CommentForm(csrf_enabled=True)
|
||||
|
||||
save_comment(form.textbox.data, post_title)
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
def save_comment(content: str, post_title: str):
|
||||
with open(COMMENTS_PATH, 'r') as file:
|
||||
comment_data = json.loads(file.read())
|
||||
|
||||
# See if user is logged in, otherwise setup as anon
|
||||
if 'username' in flask.session:
|
||||
username = flask.session['username']
|
||||
else:
|
||||
username = 'Anon'
|
||||
|
||||
comment = {
|
||||
"username" : username,
|
||||
"content" : content
|
||||
}
|
||||
|
||||
# Add comment to JSON data
|
||||
if post_title in comment_data:
|
||||
comment_data[post_title].append(comment)
|
||||
else:
|
||||
comment_data[post_title] = [comment]
|
||||
|
||||
# Save JSON data
|
||||
with open(COMMENTS_PATH, 'w') as file:
|
||||
file.write(json.dumps(comment_data))
|
||||
|
||||
def get_comments(post_title : int) -> list[dict]:
|
||||
|
||||
with open(COMMENTS_PATH, 'r') as file:
|
||||
comment_data = json.loads(file.read())
|
||||
|
||||
if post_title in comment_data:
|
||||
return comment_data[post_title]
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
@ -1,19 +1,19 @@
|
||||
.albums {
|
||||
height: 100%;
|
||||
|
||||
line-height: 0;
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.albums img {
|
||||
padding: 0 0;
|
||||
margin: 0 0;
|
||||
border: 0 0;
|
||||
}
|
||||
|
||||
|
||||
.body {
|
||||
height: 100%;
|
||||
padding: 0 0;
|
||||
margin: 0 0;
|
||||
}
|
||||
.albums {
|
||||
height: 100%;
|
||||
|
||||
line-height: 0;
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.albums img {
|
||||
padding: 0 0;
|
||||
margin: 0 0;
|
||||
border: 0 0;
|
||||
}
|
||||
|
||||
|
||||
.body {
|
||||
height: 100%;
|
||||
padding: 0 0;
|
||||
margin: 0 0;
|
||||
}
|
||||
|
||||
BIN
app/static/canal-banner1.jpg
Normal file
|
After Width: | Height: | Size: 609 KiB |
BIN
app/static/deadwell-banner.png
Normal file
|
After Width: | Height: | Size: 1.5 MiB |
BIN
app/static/game_screenshots/darkthroat_bottom.jpg
Normal file
|
After Width: | Height: | Size: 624 KiB |
BIN
app/static/game_screenshots/darkthroat_whirlpool.jpg
Normal file
|
After Width: | Height: | Size: 684 KiB |
BIN
app/static/game_screenshots/deadwell_bridge.jpg
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
app/static/game_screenshots/fallcrush.jpg
Normal file
|
After Width: | Height: | Size: 1.0 MiB |
BIN
app/static/game_screenshots/greensilt_overlook.jpg
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
app/static/game_screenshots/greensilt_tower.jpg
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
app/static/game_screenshots/nokkpond.jpg
Normal file
|
After Width: | Height: | Size: 832 KiB |
BIN
app/static/game_screenshots/nokkpond_mountians.jpg
Normal file
|
After Width: | Height: | Size: 465 KiB |
BIN
app/static/game_screenshots/sourwood_bridge_1.jpg
Normal file
|
After Width: | Height: | Size: 1.0 MiB |
BIN
app/static/game_screenshots/sourwood_bridge_2.jpg
Normal file
|
After Width: | Height: | Size: 828 KiB |
BIN
app/static/greensilt-banner-2.png
Normal file
|
After Width: | Height: | Size: 639 KiB |
BIN
app/static/greensilt-banner-3.png
Normal file
|
After Width: | Height: | Size: 728 KiB |
BIN
app/static/greensilt-banner-scaled.png
Normal file
|
After Width: | Height: | Size: 198 KiB |
BIN
app/static/greensilt-banner.png
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
@ -1,12 +1,12 @@
|
||||
EOF Mark,
|
||||
Glassit-VSC,
|
||||
JSON formatter,
|
||||
Pylance,
|
||||
Remote - SSH,
|
||||
Synthwave '84 Blues,
|
||||
Trailing Spaces,
|
||||
Helm Intellisense,
|
||||
background,
|
||||
Helium Icon Theme,
|
||||
SQLite Viewer,
|
||||
EOF Mark,
|
||||
Glassit-VSC,
|
||||
JSON formatter,
|
||||
Pylance,
|
||||
Remote - SSH,
|
||||
Synthwave '84 Blues,
|
||||
Trailing Spaces,
|
||||
Helm Intellisense,
|
||||
background,
|
||||
Helium Icon Theme,
|
||||
SQLite Viewer,
|
||||
Docker
|
||||
BIN
app/static/real-greensilt-banner.png
Normal file
|
After Width: | Height: | Size: 202 KiB |
BIN
app/static/render.jpg
Normal file
|
After Width: | Height: | Size: 2.0 MiB |
BIN
app/static/render.png
Normal file
|
After Width: | Height: | Size: 1.7 MiB |
BIN
app/static/roland_think.png
Normal file
|
After Width: | Height: | Size: 120 KiB |
@ -12,8 +12,9 @@ h1, h2, h3, h4, h5 {
|
||||
}
|
||||
|
||||
html {
|
||||
--text: hsl(224, 83%, 91%);
|
||||
--background: hsl(224, 31%, 23%);
|
||||
--text: black;
|
||||
--background: #c0c0b0;
|
||||
/* --background: #2b2d31; */
|
||||
--primary: hsl(229, 81%, 73%);
|
||||
--primary10: hsla(209, 61%, 71%, 10%);
|
||||
--primary20: hsla(209, 61%, 71%, 20%);
|
||||
@ -70,15 +71,19 @@ li {
|
||||
/* Other */
|
||||
|
||||
.header {
|
||||
background-image: url("render.jpg");
|
||||
background-size: cover;
|
||||
text-align: center;
|
||||
|
||||
margin: 0 30%;
|
||||
padding: 2em;
|
||||
margin: 2em 25%;
|
||||
padding: 3em;
|
||||
|
||||
border-style: var(--borders-style);
|
||||
border-color: #1E2022;
|
||||
background-color: var(--background);
|
||||
border-radius: var(--border-radius);
|
||||
|
||||
color: white;
|
||||
}
|
||||
|
||||
.header a {
|
||||
@ -91,7 +96,7 @@ li {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
margin: 0px 5%;
|
||||
margin: 0px 20%;
|
||||
|
||||
border-style: var(--borders-style);
|
||||
border-color: #1E2022;
|
||||
@ -223,6 +228,7 @@ li {
|
||||
}
|
||||
|
||||
.post p {
|
||||
font-family: Verdana, Geneva, sans-serif;
|
||||
line-height: 2.25;
|
||||
text-indent: 3em;
|
||||
}
|
||||
|
||||
BIN
app/static/yosemite-banner.png
Normal file
|
After Width: | Height: | Size: 2.4 MiB |
BIN
app/static/yosemite.png
Normal file
|
After Width: | Height: | Size: 6.2 MiB |
@ -1,20 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<header>
|
||||
<link rel="shortcut icon" href="index_favicon.ico">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='albumsquare.css') }}">
|
||||
<title>Album Square</title>
|
||||
</header>
|
||||
<body>
|
||||
<div class="albums">
|
||||
{% for album in top_albums %}
|
||||
<a title="{{ album.album_name}} by {{ album.artist_name }} - {{ album.listen_time }} Hours">
|
||||
<img src="{{ album.album_cover }}" style="width: {{ res }}px; height: {{ res }}px;">
|
||||
</a>
|
||||
{% if loop.index % limit == 0 %}
|
||||
<br>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<header>
|
||||
<link rel="shortcut icon" href="index_favicon.ico">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='albumsquare.css') }}">
|
||||
<title>Album Square</title>
|
||||
</header>
|
||||
<body>
|
||||
<div class="albums">
|
||||
{% for album in top_albums %}
|
||||
<a title="{{ album.album_name}} by {{ album.artist_name }} - {{ album.listen_time }} Hours">
|
||||
<img src="{{ album.album_cover }}" style="width: {{ res }}px; height: {{ res }}px;">
|
||||
</a>
|
||||
{% if loop.index % limit == 0 %}
|
||||
<br>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,40 +1,40 @@
|
||||
<!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 - Login</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><br>
|
||||
<a href="/login/">Login</a>
|
||||
</div>
|
||||
|
||||
<div class="dlog">
|
||||
<h1>Login</h1>
|
||||
<form method="post" action="/user/login/">
|
||||
{{ form.hidden_tag() }}
|
||||
Username: {{ form.username }} <br>
|
||||
Password: {{ form.password }} <br>
|
||||
<input type="submit" value="Login">
|
||||
</form>
|
||||
<br>
|
||||
|
||||
<h1>Need to Register?</h1>
|
||||
<a href="/user/register/">Register</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<!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 - Login</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><br>
|
||||
<a href="/login/">Login</a>
|
||||
</div>
|
||||
|
||||
<div class="dlog">
|
||||
<h1>Login</h1>
|
||||
<form method="post" action="/user/login/">
|
||||
{{ form.hidden_tag() }}
|
||||
Username: {{ form.username }} <br>
|
||||
Password: {{ form.password }} <br>
|
||||
<input type="submit" value="Login">
|
||||
</form>
|
||||
<br>
|
||||
|
||||
<h1>Need to Register?</h1>
|
||||
<a href="/user/register/">Register</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,36 +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><br>
|
||||
<a href="/login/">Login</a>
|
||||
</div>
|
||||
|
||||
<div class="dlog">
|
||||
<h1>Register</h1>
|
||||
<form method="post" action="/user/add/">
|
||||
{{ form.hidden_tag() }}
|
||||
Username: {{ form.username }} <br>
|
||||
Password: {{ form.password }} <br>
|
||||
<input type="submit" value="Register">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<!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><br>
|
||||
<a href="/login/">Login</a>
|
||||
</div>
|
||||
|
||||
<div class="dlog">
|
||||
<h1>Register</h1>
|
||||
<form method="post" action="/user/add/">
|
||||
{{ form.hidden_tag() }}
|
||||
Username: {{ form.username }} <br>
|
||||
Password: {{ form.password }} <br>
|
||||
<input type="submit" value="Register">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
204
app/user.py
@ -1,102 +1,102 @@
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
|
||||
import flask
|
||||
import flask_wtf.csrf
|
||||
import wtforms
|
||||
|
||||
user = flask.Blueprint('user', __name__, template_folder='./templates/user')
|
||||
USERS_PATH = "./data/users.json"
|
||||
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()
|
||||
])
|
||||
|
||||
class LoginUserForm(flask_wtf.FlaskForm):
|
||||
username = wtforms.StringField("Username", [
|
||||
wtforms.validators.DataRequired()
|
||||
])
|
||||
password = wtforms.PasswordField("Password", [
|
||||
wtforms.validators.DataRequired()
|
||||
])
|
||||
|
||||
@user.route('/user/add/', methods=["POST"])
|
||||
def add_user():
|
||||
|
||||
# Get form data
|
||||
form = RegisterUserForm(csrf_enabled=True)
|
||||
|
||||
username = form.username.data
|
||||
password = form.password.data
|
||||
|
||||
# Read existing user data
|
||||
with open(USERS_PATH, 'r') as file:
|
||||
user_data = json.loads(file.read())
|
||||
|
||||
# check if user exists
|
||||
if username in user_data:
|
||||
return 'ERROR PROCESSING REQUEST - That user already exists'
|
||||
|
||||
# Store password / server side cookie
|
||||
user_data[username] = base64.b64encode(password.encode()).decode()
|
||||
flask.session['username'] = username
|
||||
|
||||
# Write user data
|
||||
with open(USERS_PATH, 'w') as file:
|
||||
file.write(json.dumps(user_data))
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
@user.route('/user/register/')
|
||||
def register_page():
|
||||
form = RegisterUserForm()
|
||||
|
||||
return flask.render_template('register.html', form=form)
|
||||
|
||||
@user.route('/user/login/', methods=["POST"])
|
||||
def login_user():
|
||||
form = LoginUserForm(csrf_enabled=True)
|
||||
|
||||
username = form.username.data
|
||||
password = base64.b64encode(form.password.data.encode()).decode()
|
||||
|
||||
# Read existing user data
|
||||
with open(USERS_PATH, 'r') as file:
|
||||
user_data = json.loads(file.read())
|
||||
|
||||
# check if user exists
|
||||
if username not in user_data:
|
||||
return 'ERROR PROCESSING REQUEST - Bad username OR password'
|
||||
|
||||
# Does password match?
|
||||
if user_data[username] != password:
|
||||
return 'ERROR PROCESSING REQUEST - Bad username OR password'
|
||||
|
||||
flask.session['username'] = username
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
@user.route('/login/')
|
||||
def login_page():
|
||||
form = LoginUserForm()
|
||||
|
||||
return flask.render_template('login.html', form=form)
|
||||
|
||||
@user.route('/logout/')
|
||||
def logout_user():
|
||||
|
||||
if 'username' in flask.session:
|
||||
flask.session.pop('username')
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
# Check User file exists
|
||||
if not os.path.exists(USERS_PATH):
|
||||
with open(USERS_PATH, 'w+') as file:
|
||||
file.write('{}')
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
|
||||
import flask
|
||||
import flask_wtf.csrf
|
||||
import wtforms
|
||||
|
||||
user = flask.Blueprint('user', __name__, template_folder='./templates/user')
|
||||
USERS_PATH = "./data/users.json"
|
||||
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()
|
||||
])
|
||||
|
||||
class LoginUserForm(flask_wtf.FlaskForm):
|
||||
username = wtforms.StringField("Username", [
|
||||
wtforms.validators.DataRequired()
|
||||
])
|
||||
password = wtforms.PasswordField("Password", [
|
||||
wtforms.validators.DataRequired()
|
||||
])
|
||||
|
||||
@user.route('/user/add/', methods=["POST"])
|
||||
def add_user():
|
||||
|
||||
# Get form data
|
||||
form = RegisterUserForm(csrf_enabled=True)
|
||||
|
||||
username = form.username.data
|
||||
password = form.password.data
|
||||
|
||||
# Read existing user data
|
||||
with open(USERS_PATH, 'r') as file:
|
||||
user_data = json.loads(file.read())
|
||||
|
||||
# check if user exists
|
||||
if username in user_data:
|
||||
return 'ERROR PROCESSING REQUEST - That user already exists'
|
||||
|
||||
# Store password / server side cookie
|
||||
user_data[username] = base64.b64encode(password.encode()).decode()
|
||||
flask.session['username'] = username
|
||||
|
||||
# Write user data
|
||||
with open(USERS_PATH, 'w') as file:
|
||||
file.write(json.dumps(user_data))
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
@user.route('/user/register/')
|
||||
def register_page():
|
||||
form = RegisterUserForm()
|
||||
|
||||
return flask.render_template('register.html', form=form)
|
||||
|
||||
@user.route('/user/login/', methods=["POST"])
|
||||
def login_user():
|
||||
form = LoginUserForm(csrf_enabled=True)
|
||||
|
||||
username = form.username.data
|
||||
password = base64.b64encode(form.password.data.encode()).decode()
|
||||
|
||||
# Read existing user data
|
||||
with open(USERS_PATH, 'r') as file:
|
||||
user_data = json.loads(file.read())
|
||||
|
||||
# check if user exists
|
||||
if username not in user_data:
|
||||
return 'ERROR PROCESSING REQUEST - Bad username OR password'
|
||||
|
||||
# Does password match?
|
||||
if user_data[username] != password:
|
||||
return 'ERROR PROCESSING REQUEST - Bad username OR password'
|
||||
|
||||
flask.session['username'] = username
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
@user.route('/login/')
|
||||
def login_page():
|
||||
form = LoginUserForm()
|
||||
|
||||
return flask.render_template('login.html', form=form)
|
||||
|
||||
@user.route('/logout/')
|
||||
def logout_user():
|
||||
|
||||
if 'username' in flask.session:
|
||||
flask.session.pop('username')
|
||||
|
||||
return flask.redirect('/')
|
||||
|
||||
# Check User file exists
|
||||
if not os.path.exists(USERS_PATH):
|
||||
with open(USERS_PATH, 'w+') as file:
|
||||
file.write('{}')
|
||||
|
||||