mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
A lot of new stuff
This commit is contained in:
parent
87c616e041
commit
26e1974035
17 changed files with 114 additions and 31 deletions
|
@ -8,10 +8,11 @@ from royalnet.web.royalprints import *
|
|||
class TestConfig:
|
||||
DB_PATH = os.environ["DB_PATH"]
|
||||
TG_AK = os.environ["TG_AK"]
|
||||
SITE_NAME = "Royalnet"
|
||||
|
||||
|
||||
app = create_app(TestConfig, [rp_home, rp_wikiview, rp_tglogin, rp_docs, rp_wikiedit, rp_mcstatus, rp_diarioview,
|
||||
rp_profile, rp_login])
|
||||
rp_profile, rp_login, rp_newaccount])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -9,6 +9,7 @@ from . import mcstatus
|
|||
from . import diarioview
|
||||
from . import profile
|
||||
from . import login
|
||||
from . import newaccount
|
||||
|
||||
rp_home = home.rp
|
||||
rp_wikiview = wikiview.rp
|
||||
|
@ -19,6 +20,7 @@ rp_mcstatus = mcstatus.rp
|
|||
rp_diarioview = diarioview.rp
|
||||
rp_profile = profile.rp
|
||||
rp_login = login.rp
|
||||
rp_newaccount = newaccount.rp
|
||||
|
||||
__all__ = ["rp_home", "rp_wikiview", "rp_tglogin", "rp_docs", "rp_wikiedit", "rp_mcstatus", "rp_diarioview",
|
||||
"rp_profile", "rp_login"]
|
||||
"rp_profile", "rp_login", "rp_newaccount"]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Pagina {{ page }} - Diario RYG
|
||||
Diario: Pagina {{ page }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -22,15 +22,15 @@ def login_index():
|
|||
@rp.route("/done", methods=["POST"])
|
||||
def login_done():
|
||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||
data = f.request.form
|
||||
if "username" not in data:
|
||||
fd = f.request.form
|
||||
if "username" not in fd:
|
||||
return error(400, "Nessun username inserito.")
|
||||
royal_user = alchemy_session.query(alchemy.Royal).filter_by(username=data["username"]).one_or_none()
|
||||
royal_user = alchemy_session.query(alchemy.Royal).filter_by(username=fd["username"]).one_or_none()
|
||||
if royal_user is None:
|
||||
return error(404, "L'username inserito non corrisponde a nessun account registrato.")
|
||||
if "password" not in data:
|
||||
if "password" not in fd:
|
||||
return error(400, "Nessuna password inserita.")
|
||||
if not bcrypt.checkpw(bytes(data["password"], encoding="utf8"), royal_user.password):
|
||||
if not bcrypt.checkpw(bytes(fd["password"], encoding="utf8"), royal_user.password):
|
||||
return error(400, "La password inserita non è valida.")
|
||||
f.session["royal"] = {
|
||||
"uid": royal_user.uid,
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
<p>
|
||||
Non hai una password? Prova il <a href="{{ url_for("tglogin.tglogin_index") }}">Login con Telegram</a>!
|
||||
</p>
|
||||
<p>
|
||||
Facendo il login su questo sito, acconsenti a ricevere due <abbr title="cookie">biscottini</abbr> che memorizzino l'account con cui hai fatto il login.<br>
|
||||
</p>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Successful Password Login
|
||||
Password Login riuscito
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{{ server_str }} - RYG MCstatus
|
||||
Minecraft {{ server_str }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
40
royalnet/web/royalprints/newaccount/__init__.py
Normal file
40
royalnet/web/royalprints/newaccount/__init__.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
"""A :py:class:`royalnet.web.Royalprint` to create new Royals."""
|
||||
import flask as f
|
||||
import os
|
||||
import datetime
|
||||
import bcrypt
|
||||
from ...royalprint import Royalprint
|
||||
from ...shortcuts import error
|
||||
from ....database.tables import Royal, Alias
|
||||
|
||||
|
||||
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
|
||||
rp = Royalprint("newaccount", __name__, url_prefix="/newaccount", required_tables={Royal, Alias},
|
||||
template_folder=tmpl_dir)
|
||||
|
||||
|
||||
@rp.route("/", methods=["GET", "POST"])
|
||||
def login_index():
|
||||
if f.request.method == "GET":
|
||||
return f.render_template("newaccount_index.html")
|
||||
elif f.request.method == "POST":
|
||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||
fd = f.request.form
|
||||
if "username" not in fd:
|
||||
return error(400, "Non è stato inserito nessun username.")
|
||||
if "password" not in fd:
|
||||
return error(400, "Non è stata inserita nessuna password.")
|
||||
royal = alchemy_session.query(alchemy.Royal).filter_by(username=fd["username"]).one_or_none()
|
||||
if royal is not None:
|
||||
return error(403, "Esiste già un utente con quell'username.")
|
||||
alias = alchemy_session.query(alchemy.Alias).filter_by(alias=fd["username"]).one_or_none()
|
||||
if alias is not None:
|
||||
return error(403, "Esiste già un utente con quell'alias.")
|
||||
royal = alchemy.Royal(username=fd["username"],
|
||||
password=bcrypt.hashpw(bytes(fd["password"], encoding="utf8"), bcrypt.gensalt()),
|
||||
role="Guest")
|
||||
alchemy_session.add(royal)
|
||||
alias = alchemy.Alias(royal=royal, alias=royal.username.lower())
|
||||
alchemy_session.add(alias)
|
||||
alchemy_session.commit()
|
||||
return f.redirect(f.url_for("login.login_index"))
|
|
@ -0,0 +1,36 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Nuovo account
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="login">
|
||||
<div class="doublebox">
|
||||
<div class="top">
|
||||
<span class="left">
|
||||
Nuovo account
|
||||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
<form method="post" class="newaccount-form fullsize">
|
||||
<label for="newaccount-username">
|
||||
<span class="label-text">Username</span>
|
||||
<input id="newaccount-username" type="text" name="username">
|
||||
</label>
|
||||
<label for="newaccount-password">
|
||||
<span class="label-text">Password</span>
|
||||
<input id="newaccount-password" type="password" name="password">
|
||||
</label>
|
||||
<label for="newaccount-role">
|
||||
<span class="label-text">Ruolo</span>
|
||||
<input id="newaccount-role" type="text" name="role" disabled value="Guest">
|
||||
</label>
|
||||
<label for="newaccount-submit">
|
||||
<input id="newaccount-submit" type="submit" value="Login">
|
||||
</label>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,14 +1,14 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Elenco Utenti
|
||||
Elenco profili
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="doublebox">
|
||||
<div class="top">
|
||||
<span class="left">
|
||||
Elenco Utenti
|
||||
Elenco profili
|
||||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{{ royal.username }} - Profilo RYG
|
||||
Profilo: {{ royal.username }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Successful Telegram Login
|
||||
Telegram Login riuscito
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -5,7 +5,7 @@ import os
|
|||
import datetime
|
||||
import difflib
|
||||
from ...royalprint import Royalprint
|
||||
from ...shortcuts import error
|
||||
from ...shortcuts import error, from_urluuid
|
||||
from ....database.tables import Royal, WikiPage, WikiRevision
|
||||
|
||||
|
||||
|
@ -41,17 +41,18 @@ def wikiedit_newpage():
|
|||
alchemy_session.add(page)
|
||||
alchemy_session.add(revision)
|
||||
alchemy_session.commit()
|
||||
return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_id, title=page.title))
|
||||
return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_short_id, title=page.title))
|
||||
|
||||
|
||||
@rp.route("/<uuid:page_id>", defaults={"title": ""}, methods=["GET", "POST"])
|
||||
@rp.route("/<uuid:page_id>/<title>", methods=["GET", "POST"])
|
||||
def wikiedit_by_id(page_id: uuid.UUID, title: str):
|
||||
@rp.route("/<page_id>", defaults={"title": ""}, methods=["GET", "POST"])
|
||||
@rp.route("/<page_id>/<title>", methods=["GET", "POST"])
|
||||
def wikiedit_by_id(page_id: str, title: str):
|
||||
page_uuid = from_urluuid(page_id)
|
||||
if "royal" not in f.session:
|
||||
return error(403, "Devi aver effettuato il login per modificare pagine wiki.")
|
||||
|
||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||
page = alchemy_session.query(alchemy.WikiPage).filter(alchemy.WikiPage.page_id == page_id).one_or_none()
|
||||
page = alchemy_session.query(alchemy.WikiPage).filter(alchemy.WikiPage.page_id == page_uuid).one_or_none()
|
||||
if page is None:
|
||||
return error(404, "La pagina che stai cercando di modificare non esiste.")
|
||||
|
||||
|
@ -75,4 +76,4 @@ def wikiedit_by_id(page_id: uuid.UUID, title: str):
|
|||
page.title = fd["title"]
|
||||
page.css = fd["css"] if fd["css"] != "None" else None
|
||||
alchemy_session.commit()
|
||||
return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_id, title=page.title))
|
||||
return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_short_id, title=page.title))
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</label>
|
||||
<label for="wikiedit-format">
|
||||
<span class="label-text">Formato</span>
|
||||
<input id="wikiedit-format" type="text" name="format" disabled value="{{ page.format }}">
|
||||
<input id="wikiedit-format" type="text" name="format" disabled value="markdown">
|
||||
</label>
|
||||
<!--suppress HtmlFormInputWithoutLabel -->
|
||||
<textarea id="wikiedit-content" name="content">{{ page.content }}</textarea>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Indice RYGwiki
|
||||
Wiki
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="doublebox">
|
||||
<div class="top">
|
||||
<span class="left">
|
||||
Pagine Wiki
|
||||
Wiki
|
||||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{{ page.title }} - RYGwiki
|
||||
Wiki: {{ page.title }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -12,12 +12,12 @@
|
|||
</span>
|
||||
<span class="right">
|
||||
{% if session.royal %}
|
||||
<a class="edit no-icon" href="{{ url_for("wikiedit.wikiedit_by_id", page_id=page.page_id|string, title=page.title) }}">Modifica</a>
|
||||
<a class="edit no-icon" href="{{ url_for("wikiedit.wikiedit_by_id", page_id=page.page_short_id, title=page.title) }}">Modifica</a>
|
||||
{% else %}
|
||||
<a class="edit no-icon faded" title="Devi fare il login per modificare pagine!">Modifica</a>
|
||||
{% endif %}
|
||||
|
|
||||
<a class="permalink no-icon" href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_id|string, title=page.title) }}">Permalink</a>
|
||||
<a class="permalink no-icon" href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_short_id, title=page.title) }}">Permalink</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<meta name="keywords" content="Royal Games,RYG,Gaming,Videogames,Community">
|
||||
<meta name="description" content="Royal Games Community">
|
||||
<meta property="og:site_name" content="Royal Games">
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<title>{% block title %}{% endblock %} - {{ config["SITE_NAME"] }}</title>
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
|
||||
{% if css %}
|
||||
<link rel="stylesheet" href="{{ url_for("static", filename=css) }}">
|
||||
|
@ -23,12 +23,12 @@
|
|||
<div class="nav-left">
|
||||
<a class="nav-site no-icon" href="{{ url_for("home.home_index") }}">
|
||||
<img class="nav-image" alt="" src="{{ url_for("static", filename="logo.svg") }}">
|
||||
<span class="nav-sitename">Royal Games</span>
|
||||
<span class="nav-sitename">{{ config["SITE_NAME"] }}</span>
|
||||
</a>
|
||||
<span class="nav-modules">
|
||||
<a class="no-icon" href="{{ url_for("wikiview.wikiview_index") }}">Wiki</a>
|
||||
<a class="no-icon" href="{{ url_for("diarioview.diarioview_page", page=1) }}">Diario</a>
|
||||
<a class="no-icon" href="{{ url_for("profile.profile_index") }}">Membri</a>
|
||||
<a class="no-icon" href="{{ url_for("profile.profile_index") }}">Profili</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="nav-center">
|
||||
|
@ -46,7 +46,7 @@
|
|||
</a>
|
||||
{% else %}
|
||||
<span class="nav-login">
|
||||
<a class="no-icon" href="{{ url_for("tglogin.tglogin_index") }}">
|
||||
<a class="no-icon" href="{{ url_for("login.login_index") }}">
|
||||
Login
|
||||
<img class="nav-image faded" alt="" src="{{ url_for("static", filename="generic.png") }}">
|
||||
</a>
|
||||
|
|
Loading…
Reference in a new issue