all repos — myprecious @ 4f12dee46f1c595f99cb80b659909d4ce88d7dd5

A lightweight web service to backup precious game saves.

create all pages, minor tweaks
Andronaco Marco marco.andronaco@olivetti.com
Mon, 17 Jul 2023 21:14:51 +0200
commit

4f12dee46f1c595f99cb80b659909d4ce88d7dd5

parent

5acbe103e332613faff043d102cc215dc13380d2

M myprecious/GamesApi.pymyprecious/GamesApi.py

@@ -6,6 +6,9 @@ import requests

import os, json def get_token(): + if None in [ c.CLIENT_ID, c.CLIENT_SECRET ]: + print("Please check your .env file.") + exit(1) url = f"{ c.AUTH_URL }?{ urlencode(c.AUTH_URL_PARAMS) }" response = requests.request("POST", url).json() return response['access_token']
M myprecious/__main__.pymyprecious/__main__.py

@@ -59,7 +59,6 @@

def render(template): return render_template(template, user=current_user) - def handle_platform(game, platform): try: game_cover = "https:" + game["cover"]["url"]

@@ -125,6 +124,16 @@ return redirect("/")

else: return render_template("login.html", user=current_user, last_user=username) +@app.route('/register', methods=['GET', 'POST']) +def route_register(): + if current_user.is_authenticated: + return redirect('/') + + if request.method == "GET": + return render("register.html") + + return render("register.html") + @app.route('/logout') def route_logout(): logout_user()

@@ -176,6 +185,24 @@ return redirect("/upload")

save_file = os.path.join(save_folder, secure_filename(f.filename)) f.save(save_file) return render("index.html") + + +@app.route('/admin', methods=['GET', 'POST']) +def route_admin(): + if not current_user.is_authenticated: + return redirect('/') + + if current_user.id != 1: + return redirect('/') + + if request.method == "GET": + return render("admin.html") + + return render("admin.html") + +@app.route('/about') +def route_about(): + return render("about.html") if __name__ == "__main__": app.debug=c.DEBUG_SWITCH
M myprecious/static/style.cssmyprecious/static/style.css

@@ -41,3 +41,7 @@

.link::before { content: "↗ "; } + +.hidden { + display: none !important; +}
A myprecious/templates/about.html

@@ -0,0 +1,10 @@

+{% extends "base.html" %} +{% block title %}faqs{% endblock %} +{% block content %} +<h2>What am I looking at?</h2> +<p>It's my favorite (overcomplicated and not safe at all) way of storing your most precious savefiles!</p> +<h2>This is useless</h2> +<p>I know, right?</p> +<h2>Your minimal design looks familiar...</h2> +<p>You should check out <a href="https://lipu.li/?u=m15o&p=projects">m15o</a>'s projects.</p> +{% endblock %}
A myprecious/templates/admin.html

@@ -0,0 +1,8 @@

+{% extends "base.html" %} +{% block title %}admin{% endblock %} +{% block content %} +to be implemented... +<form action="/admin" method="POST" enctype="multipart/form-data"> + <input type="submit" value="save" /> +</form> +{% endblock %}
M myprecious/templates/base.htmlmyprecious/templates/base.html

@@ -1,6 +1,5 @@

<!DOCTYPE html> <html lang="en"> - <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1">

@@ -16,24 +15,28 @@ {% block header %}

<a href="/">home</a> {% if user.is_authenticated %} <a href="/upload">upload</a> + {% if user.id == 1 %} + <a href="/admin">admin</a> + {% endif %} <a href="/logout">logout</a> {% else %} <a href="/login">login</a> <a href="/register">register</a> {% endif %} + {% endblock %} </nav> <hr> </header> <main> <h1>{% block title %}{% endblock %}</h1> - <p></p> {% block content %}{% endblock %} + <hr /> <nav> {% block footer %} <span>questions: </span> - <a href="#">what is this?</a> - <a href="https://birabittoh.github.io/">who made this?</a> + <a href="/about">what is this?</a> + <a href="https://birabittoh.github.io/" target="_blank">who made this?</a> {% endblock %} </nav> </main>
M myprecious/templates/index.htmlmyprecious/templates/index.html

@@ -1,6 +1,5 @@

{% extends "base.html" %} {% block title %}myprecious{% endblock %} {% block content %} -<p>A simple library for game saves.</p> -<p></p> +<p>A simple game saves archive.</p> {% endblock %}
M myprecious/templates/login.htmlmyprecious/templates/login.html

@@ -2,10 +2,10 @@ {% extends "base.html" %}

{% block title %}login{% endblock %} {% block content %} <form action="/login" method="POST" enctype="multipart/form-data"> - <input type="text" name="username" placeholder="User" {% if last_user %}value="{{ last_user }}" {% endif %}/> - <input type="password" name="password" placeholder="Password" /> + <input type="text" name="username" placeholder="username" {% if last_user %}value="{{ last_user }}" {% endif %}/> + <input type="password" name="password" placeholder="password" /> <input type="checkbox" name="remember" checked> - <label for="remember">Remember me</label><br /> + <label for="remember">remember me</label><br /> <input type="submit" value="login" /> </form> {% endblock %}
A myprecious/templates/register.html

@@ -0,0 +1,11 @@

+{% extends "base.html" %} +{% block title %}register{% endblock %} +{% block content %} +to be implemented... +<form action="/register" method="POST" enctype="multipart/form-data"> + <input type="text" name="username" placeholder="username" /> + <input type="email" name="email" placeholder="e-mail (optional)"/> + <input type="password" name="password" placeholder="password" /> + <input type="submit" value="register" /> +</form> +{% endblock %}
M myprecious/templates/upload.htmlmyprecious/templates/upload.html

@@ -2,8 +2,8 @@ {% extends "base.html" %}

{% block title %}upload{% endblock %} {% block content %} <form action="/upload" method="POST" enctype="multipart/form-data"> - <input type="text" name="game_id" value="{{ game.game_id }}" required /> - <input type="text" name="platform_id" value="{{ game.platform_id }}" required /> + <input class="hidden" type="text" name="game_id" value="{{ game.game_id }}" required /> + <input class="hidden" type="text" name="platform_id" value="{{ game.platform_id }}" required /> <table> <tr onClick="window.location.href = '/search';"> <td>