From bf9a17a98adbefbbe57ce8b29f9329286b66f121 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Wed, 3 May 2023 14:38:01 -0700 Subject: [PATCH] better templating, improving rpc api calls --- lws-web/lws/app.py | 8 +++- lws-web/lws/models.py | 5 ++ lws-web/lws/templates/includes/base.html | 53 ++++++++++++++++++++++ lws-web/lws/templates/includes/navbar.html | 0 lws-web/lws/templates/index.html | 7 ++- lws-web/lws/templates/login.html | 10 ++-- lws-web/lws/templates/setup.html | 10 ++-- lws-web/lws/templates/wallet/add.html | 12 +++-- lws-web/lws/templates/wallet/show.html | 6 ++- 9 files changed, 93 insertions(+), 18 deletions(-) delete mode 100644 lws-web/lws/templates/includes/navbar.html diff --git a/lws-web/lws/app.py b/lws-web/lws/app.py index 550d095..062af1e 100644 --- a/lws-web/lws/app.py +++ b/lws-web/lws/app.py @@ -2,7 +2,7 @@ import requests import monero.address from quart import Quart, render_template, redirect, request, flash, jsonify from quart_auth import ( - AuthUser, AuthManager, login_required, login_user, current_user, Unauthorized + AuthUser, AuthManager, login_required, login_user, logout_user, current_user, Unauthorized ) from quart_bcrypt import Bcrypt from quart_session import Session @@ -75,6 +75,12 @@ async def login(): return await render_template("login.html") +@app.route("/logout") +async def logout(): + if current_user.is_authenticated: + logout_user() + return redirect("/") + @app.route("/setup", methods=["GET", "POST"]) async def setup(): if User.select().first(): diff --git a/lws-web/lws/models.py b/lws-web/lws/models.py index 0563aea..17f6cce 100644 --- a/lws-web/lws/models.py +++ b/lws-web/lws/models.py @@ -56,6 +56,11 @@ class Wallet(Model): return False def add_wallet_lws(self): + if self.check_wallet_lws() and self.added is False: + self.added = True + self.date_added = datetime.utcnow() + self.save() + return True endpoint = f"{config.LWS_ADMIN_URL}/add_account" data = { "auth": self.user.view_key, diff --git a/lws-web/lws/templates/includes/base.html b/lws-web/lws/templates/includes/base.html index e69de29..c2999a9 100644 --- a/lws-web/lws/templates/includes/base.html +++ b/lws-web/lws/templates/includes/base.html @@ -0,0 +1,53 @@ + + + + Monero LWS Web App + + + + + + + + + + + + + + + + + + + + + + +
+
+ {% for message in get_flashed_messages() %} +
  • {{ message }}
  • + {% endfor %} +
    + {% block content %} + {% endblock %} +
    + + diff --git a/lws-web/lws/templates/includes/navbar.html b/lws-web/lws/templates/includes/navbar.html deleted file mode 100644 index e69de29..0000000 diff --git a/lws-web/lws/templates/index.html b/lws-web/lws/templates/index.html index caf1923..e96f22c 100644 --- a/lws-web/lws/templates/index.html +++ b/lws-web/lws/templates/index.html @@ -1,5 +1,10 @@ +{% extends 'includes/base.html' %} + +{% block content %} {% if current_user.is_authenticated %}

    hi {{ current_user.username }}

    {% else %}

    hi anon

    -{% endif %} \ No newline at end of file +{% endif %} +{% endblock %} + diff --git a/lws-web/lws/templates/login.html b/lws-web/lws/templates/login.html index 1842061..cd7c818 100644 --- a/lws-web/lws/templates/login.html +++ b/lws-web/lws/templates/login.html @@ -1,7 +1,6 @@ -{% for message in get_flashed_messages() %} -
  • {{ message }}
  • -{% endfor %} -
    +{% extends 'includes/base.html' %} + +{% block content %}
    @@ -18,4 +17,5 @@ padding-bottom: .5em; margin-bottom: 1em; } - \ No newline at end of file + +{% endblock %} \ No newline at end of file diff --git a/lws-web/lws/templates/setup.html b/lws-web/lws/templates/setup.html index 95070bb..a8286cc 100644 --- a/lws-web/lws/templates/setup.html +++ b/lws-web/lws/templates/setup.html @@ -1,7 +1,6 @@ -{% for message in get_flashed_messages() %} -
  • {{ message }}
  • -{% endfor %} -
    +{% extends 'includes/base.html' %} + +{% block content %}
    @@ -22,4 +21,5 @@ padding-bottom: .5em; margin-bottom: 1em; } - \ No newline at end of file + +{% endblock %} diff --git a/lws-web/lws/templates/wallet/add.html b/lws-web/lws/templates/wallet/add.html index 92415f2..9168b2a 100644 --- a/lws-web/lws/templates/wallet/add.html +++ b/lws-web/lws/templates/wallet/add.html @@ -1,7 +1,6 @@ -{% for message in get_flashed_messages() %} -
  • {{ message }}
  • -{% endfor %} -
    +{% extends 'includes/base.html' %} + +{% block content %}
    @@ -17,7 +16,6 @@
    - +{% endblock %} + + + diff --git a/lws-web/lws/templates/wallet/show.html b/lws-web/lws/templates/wallet/show.html index 1d1a820..d80f3fa 100644 --- a/lws-web/lws/templates/wallet/show.html +++ b/lws-web/lws/templates/wallet/show.html @@ -1,3 +1,6 @@ +{% extends 'includes/base.html' %} + +{% block content %}

    {{ wallet.name }}

    {{ wallet.description }}

    {{ wallet.date }}

    @@ -7,4 +10,5 @@ {{ wallet.get_wallet_info() }} - \ No newline at end of file + +{% endblock %} \ No newline at end of file