From 111d726de7e0432e1b13959414ea50d5260a1479 Mon Sep 17 00:00:00 2001 From: freamon Date: Wed, 11 Dec 2024 00:45:17 +0000 Subject: [PATCH] API: login and out when using x-api theme --- app/api/alpha/routes.py | 57 ++++++++ app/templates/themes/x_api/auth/login.html | 38 +++++ app/templates/themes/x_api/auth/logout.html | 5 + app/templates/themes/x_api/base.html | 136 ++++++------------ app/templates/themes/x_api/donate.html | 12 ++ app/templates/themes/x_api/index.html | 19 +-- .../themes/x_api/js/list_communities.js | 15 ++ app/templates/themes/x_api/js/login.js | 38 +++++ app/templates/themes/x_api/js/logout.js | 6 + app/templates/themes/x_api/js/site.js | 66 ++++++--- .../themes/x_api/list_communities.html | 10 ++ 11 files changed, 269 insertions(+), 133 deletions(-) create mode 100644 app/templates/themes/x_api/auth/login.html create mode 100644 app/templates/themes/x_api/auth/logout.html create mode 100644 app/templates/themes/x_api/donate.html create mode 100644 app/templates/themes/x_api/js/list_communities.js create mode 100644 app/templates/themes/x_api/js/login.js create mode 100644 app/templates/themes/x_api/js/logout.js create mode 100644 app/templates/themes/x_api/list_communities.html diff --git a/app/api/alpha/routes.py b/app/api/alpha/routes.py index f26fe531..f14b7446 100644 --- a/app/api/alpha/routes.py +++ b/app/api/alpha/routes.py @@ -404,5 +404,62 @@ def alpha_emoji(): return jsonify({"error": "not_yet_implemented"}), 400 +# HTML routes +from flask import abort, render_template +from app.utils import current_theme +import os + +@bp.route('/api/alpha/', methods=['GET']) +def get_alpha(): + if not current_app.debug: + abort(404) + + template_name = "index.html" + + theme = current_theme() + if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): + return render_template(f'themes/{theme}/{template_name}') + else: + return render_template(template_name) +@bp.route('/api/alpha/auth/login', methods=['GET']) +def get_alpha_auth_login(): + if not current_app.debug: + abort(404) + + template_name = "auth/login.html" + + theme = current_theme() + if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): + return render_template(f'themes/{theme}/{template_name}') + else: + return render_template(template_name) + + +@bp.route('/api/alpha/auth/logout', methods=['GET']) +def get_alpha_auth_logout(): + if not current_app.debug: + abort(404) + + template_name = "auth/logout.html" + + theme = current_theme() + if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): + return render_template(f'themes/{theme}/{template_name}') + else: + return render_template(template_name) + + +@bp.route('/api/alpha/communities', methods=['GET']) +def get_alpha_communities(): + if not current_app.debug: + abort(404) + + template_name = "list_communities.html" + + theme = current_theme() + if theme != '' and os.path.exists(f'app/templates/themes/{theme}/{template_name}'): + return render_template(f'themes/{theme}/{template_name}') + else: + return render_template(template_name) diff --git a/app/templates/themes/x_api/auth/login.html b/app/templates/themes/x_api/auth/login.html new file mode 100644 index 00000000..b3798f35 --- /dev/null +++ b/app/templates/themes/x_api/auth/login.html @@ -0,0 +1,38 @@ +{% extends 'themes/' + theme() + '/base.html' %} + +{% block app_content %} +

GET /api/alpha/site

+
JSON
+ +

POST /api/alpha/user/login

+
JSON
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +

+ {{ _('New User?') }} {{ _('Register new account') }} +

+

+ {{ _('Forgot Your Password?') }} {{ _('Reset it') }} +

+ + +{% endblock %} diff --git a/app/templates/themes/x_api/auth/logout.html b/app/templates/themes/x_api/auth/logout.html new file mode 100644 index 00000000..f09d3703 --- /dev/null +++ b/app/templates/themes/x_api/auth/logout.html @@ -0,0 +1,5 @@ +{% extends 'themes/' + theme() + '/base.html' %} + +{% block app_content %} + +{% endblock %} diff --git a/app/templates/themes/x_api/base.html b/app/templates/themes/x_api/base.html index 80190a66..5bce7ec5 100644 --- a/app/templates/themes/x_api/base.html +++ b/app/templates/themes/x_api/base.html @@ -1,9 +1,46 @@ +{% macro render_username(user, add_domain=True) -%} + + {% if user.deleted -%} + [deleted] + {% else -%} + + {{ user.display_name() }}{% if not user.is_local() %}@{{ user.ap_domain }}{% endif %} + + {% if user.bot -%} + + {% endif -%} + {% endif -%} + +{% endmacro -%} + +{% macro render_communityname(community, add_domain=True) -%} + + + {{ community.title }}{% if not community.is_local() %}@{{ community.ap_domain }}{% endif %} + + +{% endmacro -%} + + - {% if not debug_mode %}{{ g.site.name }}{% endif %} + + + + + + + + + + + + + + {{ bootstrap.load_css() }} @@ -44,99 +81,12 @@