diff --git a/royalnet/web/royalprints/diarioview/__init__.py b/royalnet/web/royalprints/diarioview/__init__.py index b3c81030..2cb5521b 100644 --- a/royalnet/web/royalprints/diarioview/__init__.py +++ b/royalnet/web/royalprints/diarioview/__init__.py @@ -2,7 +2,8 @@ import flask as f import os -from ... import Royalprint +from ...royalprint import Royalprint +from ...shortcuts import error from ....database.tables import Royal, Diario @@ -16,6 +17,8 @@ rp = Royalprint("diarioview", __name__, url_prefix="/diario", template_folder=tm def diarioview_page(page): alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"] if page < 1: - return "Page should be >1", 404 + return error(404, "Il numero di pagina deve essere maggiore di 0.") entries = alchemy_session.query(alchemy.Diario).order_by(alchemy.Diario.diario_id.desc()).offset((page - 1) * 1000).limit(1000).all() + if len(entries) == 0: + return error(404, "Non ci sono righe di diario in questa pagina (e in tutte le successive).") return f.render_template("diarioview_page.html", page=page, entries=entries) diff --git a/royalnet/web/royalprints/home/__init__.py b/royalnet/web/royalprints/home/__init__.py index e3dcb59d..b5739c11 100644 --- a/royalnet/web/royalprints/home/__init__.py +++ b/royalnet/web/royalprints/home/__init__.py @@ -1,7 +1,7 @@ """Homepage :py:class:`royalnet.web.Royalprint` of the Royal Games website.""" import flask as f import os -from ... import Royalprint +from ...royalprint import Royalprint tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') diff --git a/royalnet/web/royalprints/mcstatus/__init__.py b/royalnet/web/royalprints/mcstatus/__init__.py index 50c723a5..06b39912 100644 --- a/royalnet/web/royalprints/mcstatus/__init__.py +++ b/royalnet/web/royalprints/mcstatus/__init__.py @@ -2,7 +2,8 @@ import os import flask as f import socket -from ... import Royalprint +from ...royalprint import Royalprint +from ...shortcuts import error from mcstatus import MinecraftServer @@ -22,7 +23,7 @@ def mcstatus_index(server_str: str): except (socket.timeout, ConnectionRefusedError, OSError): query = None except socket.gaierror: - return "No such address", 404 + return error(400, "L'indirizzo richiesto non è valido.") except (socket.timeout, ConnectionRefusedError, OSError): status = None query = None diff --git a/royalnet/web/royalprints/profile/__init__.py b/royalnet/web/royalprints/profile/__init__.py index 6c146e5d..46d54dd0 100644 --- a/royalnet/web/royalprints/profile/__init__.py +++ b/royalnet/web/royalprints/profile/__init__.py @@ -2,7 +2,8 @@ import flask as f import os -from ... import Royalprint +from ...royalprint import Royalprint +from ...shortcuts import error from ....database.tables import * @@ -25,5 +26,5 @@ def profile_by_username(username): alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"] royal = alchemy_session.query(alchemy.Royal).filter_by(username=username).one_or_none() if royal is None: - return "No such user", 404 + return error(404, "Non esiste nessun utente con l'username richiesto.") return f.render_template("profile_page.html", royal=royal) diff --git a/royalnet/web/royalprints/tglogin/__init__.py b/royalnet/web/royalprints/tglogin/__init__.py index 1fac857f..64fab63a 100644 --- a/royalnet/web/royalprints/tglogin/__init__.py +++ b/royalnet/web/royalprints/tglogin/__init__.py @@ -4,7 +4,8 @@ import hashlib import hmac import datetime import os -from ... import Royalprint +from ...royalprint import Royalprint +from ...shortcuts import error from ....database.tables import Royal, Telegram @@ -15,6 +16,8 @@ rp = Royalprint("tglogin", __name__, url_prefix="/login/telegram", required_tabl @rp.route("/") def tglogin_index(): + if f.request.url_root != "https://ryg.steffo.eu/": + return error(404, "Il login tramite Telegram non è possibile su questo dominio.") f.session.pop("royal", None) return f.render_template("tglogin_index.html") @@ -32,10 +35,10 @@ def tglogin_done(): secret_key = hashlib.sha256(bytes(f.current_app.config["TG_AK"], encoding="ascii")).digest() hex_data = hmac.new(key=secret_key, msg=data_check, digestmod="sha256").hexdigest() if hex_data != f.request.args["hash"]: - return "Invalid authentication", 403 + return error(400, "L'autenticazione è fallita: l'hash ricevuto non coincide con quello calcolato.") tg_user = alchemy_session.query(alchemy.Telegram).filter(alchemy.Telegram.tg_id == f.request.args["id"]).one_or_none() if tg_user is None: - return "No such telegram", 404 + return error(404, "L'account Telegram con cui hai fatto il login non è connesso a nessun account Royal Games. Se sei un membro Royal Games, assicurati di aver syncato con il bot il tuo account di Telegram!") royal_user = tg_user.royal f.session["royal"] = { "uid": royal_user.uid, diff --git a/royalnet/web/royalprints/tglogin/templates/tglogin_index.html b/royalnet/web/royalprints/tglogin/templates/tglogin_index.html index 5752ffc8..373d0ffc 100644 --- a/royalnet/web/royalprints/tglogin/templates/tglogin_index.html +++ b/royalnet/web/royalprints/tglogin/templates/tglogin_index.html @@ -12,32 +12,26 @@
- Facendo il login su questo sito, acconsenti a ricevere due biscottini che memorizzino l'account con cui hai fatto il login.
-
- Essi avranno il seguente formato: -
-session["royal"] = {
- "uid": [il tuo id Royalnet]
- "username": [il tuo username Royalnet],
- "avatar": [il tuo avatar Royalnet],
- "role": [il tuo ruolo Royalnet]
+
+ Facendo il login su questo sito, acconsenti a ricevere due biscottini che memorizzino l'account con cui hai fatto il login.
+
+
+ Essi avranno il seguente formato:
+
+ session["royal"] = {
+"uid": [il tuo id Royalnet]
+"username": [il tuo username Royalnet],
+"avatar": [il tuo avatar Royalnet],
+"role": [il tuo ruolo Royalnet]
}
session["login_date"] = [la data e l'ora di adesso]
-
-
-
-
- Nota: per fare il login, devi aver sync
ato il tuo account sul gruppo Telegram Royal Games!
-
- {% else %}
-
- Il login con Telegram non è attivo su questo dominio.
-
- {% endif %}
+
+
+
+
+ Nota: per fare il login, devi aver sync
ato il tuo account sul gruppo Telegram Royal Games!
+
+ {{ reason }} +
+