diff --git a/platypush/backend/http/app/routes/execute.py b/platypush/backend/http/app/routes/execute.py index 770dddf2..148c6687 100644 --- a/platypush/backend/http/app/routes/execute.py +++ b/platypush/backend/http/app/routes/execute.py @@ -1,6 +1,7 @@ import json -from flask import Blueprint, abort, request, Response +from flask import Blueprint, abort, request +from flask.wrappers import Response from platypush.backend.http.app import template_folder from platypush.backend.http.app.utils import authenticate, logger, send_message @@ -14,8 +15,8 @@ __routes__ = [ @execute.route('/execute', methods=['POST']) -@authenticate() -def execute(): +@authenticate(json=True) +def execute_route(): """Endpoint to execute commands""" try: msg = json.loads(request.data.decode('utf-8')) diff --git a/platypush/backend/http/app/routes/resources.py b/platypush/backend/http/app/routes/resources.py index 8705caab..ef558aed 100644 --- a/platypush/backend/http/app/routes/resources.py +++ b/platypush/backend/http/app/routes/resources.py @@ -8,22 +8,27 @@ from platypush.backend.http.app import template_folder img_folder = os.path.join(template_folder, 'img') +fonts_folder = os.path.join(template_folder, 'fonts') icons_folder = os.path.join(template_folder, 'icons') resources = Blueprint('resources', __name__, template_folder=template_folder) favicon = Blueprint('favicon', __name__, template_folder=template_folder) img = Blueprint('img', __name__, template_folder=template_folder) +icons = Blueprint('icons', __name__, template_folder=template_folder) +fonts = Blueprint('fonts', __name__, template_folder=template_folder) # Declare routes list __routes__ = [ resources, favicon, img, + icons, + fonts, ] @resources.route('/resources/', methods=['GET']) def resources_path(path): - """ Custom static resources """ + """Custom static resources""" path_tokens = path.split('/') http_conf = Config.get('backend.http') resource_dirs = http_conf.get('resource_dirs', {}) @@ -42,9 +47,11 @@ def resources_path(path): real_path = real_base_path file_path = [ - s for s in re.sub( - r'^{}(.*)$'.format(base_path), '\\1', path # lgtm [py/regex-injection] - ).split('/') if s + s + for s in re.sub( + r'^{}(.*)$'.format(base_path), '\\1', path # lgtm [py/regex-injection] + ).split('/') + if s ] for p in file_path[:-1]: @@ -61,20 +68,26 @@ def resources_path(path): @favicon.route('/favicon.ico', methods=['GET']) def serve_favicon(): - """ favicon.ico icon """ + """favicon.ico icon""" return send_from_directory(template_folder, 'favicon.ico') @img.route('/img/', methods=['GET']) def imgpath(path): - """ Default static images """ + """Default static images""" return send_from_directory(img_folder, path) -@img.route('/icons/', methods=['GET']) +@icons.route('/icons/', methods=['GET']) def iconpath(path): - """ Default static icons """ + """Default static icons""" return send_from_directory(icons_folder, path) +@fonts.route('/fonts/', methods=['GET']) +def fontpath(path): + """Default fonts""" + return send_from_directory(fonts_folder, path) + + # vim:sw=4:ts=4:et: diff --git a/platypush/backend/http/app/utils.py b/platypush/backend/http/app/utils.py index 70113b45..e05c1028 100644 --- a/platypush/backend/http/app/utils.py +++ b/platypush/backend/http/app/utils.py @@ -3,7 +3,8 @@ import logging import os from functools import wraps -from flask import abort, request, redirect, Response, current_app +from flask import abort, request, redirect, jsonify, current_app +from flask.wrappers import Response from redis import Redis # NOTE: The HTTP service will *only* work on top of a Redis bus. The default @@ -184,7 +185,25 @@ def _authenticate_csrf_token(): ) -def authenticate(redirect_page='', skip_auth_methods=None, check_csrf_token=False): +def authenticate( + redirect_page='', + skip_auth_methods=None, + check_csrf_token=False, + json=False, +): + def on_auth_fail(): + if json: + return ( + jsonify( + { + 'message': 'Not logged in', + } + ), + 401, + ) + + return redirect('/login?redirect=' + (redirect_page or request.url), 307) + def decorator(f): @wraps(f) def wrapper(*args, **kwargs): @@ -213,9 +232,7 @@ def authenticate(redirect_page='', skip_auth_methods=None, check_csrf_token=Fals if session_auth_ok: return f(*args, **kwargs) - return redirect( - '/login?redirect=' + (redirect_page or request.url), 307 - ) + return on_auth_fail() # CSRF token check if check_csrf_token: @@ -224,9 +241,7 @@ def authenticate(redirect_page='', skip_auth_methods=None, check_csrf_token=Fals return abort(403, 'Invalid or missing csrf_token') if n_users == 0 and 'session' not in skip_methods: - return redirect( - '/register?redirect=' + (redirect_page or request.url), 307 - ) + return on_auth_fail() if ( ('http' not in skip_methods and http_auth_ok) diff --git a/platypush/backend/http/webapp/package-lock.json b/platypush/backend/http/webapp/package-lock.json index bc2bebd7..ea94a91c 100644 --- a/platypush/backend/http/webapp/package-lock.json +++ b/platypush/backend/http/webapp/package-lock.json @@ -3705,9 +3705,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001320", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001320.tgz", - "integrity": "sha512-MWPzG54AGdo3nWx7zHZTefseM5Y1ccM7hlQKHRqJkPozUaw3hNbBTMmLn16GG2FUzjR13Cr3NPfhIieX5PzXDA==", + "version": "1.0.30001416", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001416.tgz", + "integrity": "sha512-06wzzdAkCPZO+Qm4e/eNghZBDfVNDsCgw33T27OwBH9unE9S478OYw//Q2L7Npf/zBzs7rjZOszIFQkwQKAEqA==", "funding": [ { "type": "opencollective", @@ -14544,9 +14544,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001320", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001320.tgz", - "integrity": "sha512-MWPzG54AGdo3nWx7zHZTefseM5Y1ccM7hlQKHRqJkPozUaw3hNbBTMmLn16GG2FUzjR13Cr3NPfhIieX5PzXDA==" + "version": "1.0.30001416", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001416.tgz", + "integrity": "sha512-06wzzdAkCPZO+Qm4e/eNghZBDfVNDsCgw33T27OwBH9unE9S478OYw//Q2L7Npf/zBzs7rjZOszIFQkwQKAEqA==" }, "case-sensitive-paths-webpack-plugin": { "version": "2.4.0", diff --git a/platypush/backend/http/webapp/public/fonts/Poppins.ttf b/platypush/backend/http/webapp/public/fonts/Poppins.ttf new file mode 100644 index 00000000..8e2c0127 Binary files /dev/null and b/platypush/backend/http/webapp/public/fonts/Poppins.ttf differ diff --git a/platypush/backend/http/webapp/public/fonts/poppins.css b/platypush/backend/http/webapp/public/fonts/poppins.css new file mode 100644 index 00000000..d90a3494 --- /dev/null +++ b/platypush/backend/http/webapp/public/fonts/poppins.css @@ -0,0 +1,7 @@ +@font-face { + font-family: 'Poppins'; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url(./Poppins.ttf) format('truetype'); +} diff --git a/platypush/backend/http/webapp/public/img/logo.png b/platypush/backend/http/webapp/public/img/logo.png new file mode 100644 index 00000000..e4da4308 Binary files /dev/null and b/platypush/backend/http/webapp/public/img/logo.png differ diff --git a/platypush/backend/http/webapp/public/index.html b/platypush/backend/http/webapp/public/index.html index 85af3d06..6729d8fe 100644 --- a/platypush/backend/http/webapp/public/index.html +++ b/platypush/backend/http/webapp/public/index.html @@ -5,6 +5,7 @@ + <%= htmlWebpackPlugin.options.title %> diff --git a/platypush/backend/http/webapp/src/App.vue b/platypush/backend/http/webapp/src/App.vue index edfdb80b..0bea19ca 100644 --- a/platypush/backend/http/webapp/src/App.vue +++ b/platypush/backend/http/webapp/src/App.vue @@ -59,7 +59,7 @@ export default { }, async initConfig() { - this.config = await this.request('config.get') + this.config = await this.request('config.get', {}, 60000, false) this.userAuthenticated = true }, }, diff --git a/platypush/backend/http/webapp/src/utils/Api.vue b/platypush/backend/http/webapp/src/utils/Api.vue index e22789c9..5118813d 100644 --- a/platypush/backend/http/webapp/src/utils/Api.vue +++ b/platypush/backend/http/webapp/src/utils/Api.vue @@ -4,7 +4,7 @@ import axios from 'axios' export default { name: "Api", methods: { - execute(request, timeout=60000) { + execute(request, timeout=60000, showError=true) { const opts = {}; if (!('target' in request) || !request['target']) { @@ -36,22 +36,23 @@ export default { } }) .catch((error) => { - this.notify({ - text: error, - error: true, - }) + if (showError) + this.notify({ + text: error, + error: true, + }) reject(error) }) }) }, - request(action, args={}, timeout=60000) { + request(action, args={}, timeout=60000, showError=true) { return this.execute({ type: 'request', action: action, args: args, - }, timeout); + }, timeout, showError); } }, } diff --git a/platypush/backend/http/webapp/src/views/Login.vue b/platypush/backend/http/webapp/src/views/Login.vue index 485fe5c5..1200eeca 100644 --- a/platypush/backend/http/webapp/src/views/Login.vue +++ b/platypush/backend/http/webapp/src/views/Login.vue @@ -1,8 +1,9 @@