mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
some unfinished stuff
This commit is contained in:
parent
7a110be2b9
commit
44053eef4e
17 changed files with 183 additions and 48 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
bcrypt
|
||||||
python-telegram-bot>=11.1.0
|
python-telegram-bot>=11.1.0
|
||||||
websockets>=7.0
|
websockets>=7.0
|
||||||
pytest>=4.3.1
|
pytest>=4.3.1
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
"""The production Royalnet, active at @royalgamesbot on Telegram and Royalbot on Discord."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
"""The production Royalnet available at ryg.steffo.eu ."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from royalnet.web import create_app
|
from royalnet.web import create_app
|
||||||
from royalnet.web.royalprints import *
|
from royalnet.web.royalprints import *
|
||||||
|
@ -9,7 +11,7 @@ class TestConfig:
|
||||||
|
|
||||||
|
|
||||||
app = create_app(TestConfig, [rp_home, rp_wikiview, rp_tglogin, rp_docs, rp_wikiedit, rp_mcstatus, rp_diarioview,
|
app = create_app(TestConfig, [rp_home, rp_wikiview, rp_tglogin, rp_docs, rp_wikiedit, rp_mcstatus, rp_diarioview,
|
||||||
rp_profile])
|
rp_profile, rp_login])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -14,7 +14,7 @@ def create_app(config_obj: typing.Type, blueprints: typing.List[Royalprint]):
|
||||||
Also requires a ``DB_PATH`` key in ``config_obj`` to initialize the database connection.
|
Also requires a ``DB_PATH`` key in ``config_obj`` to initialize the database connection.
|
||||||
|
|
||||||
Warning:
|
Warning:
|
||||||
The code for this class was written at 1 AM, and I have no clue of how and why it works or even of if it really does work.
|
The code for this class was written at 1 AM, and I have no clue of how and why it works or even if it really does work.
|
||||||
Use with caution?
|
Use with caution?
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
"""Some Royalprints that can be used with the Royalnet Flask server."""
|
"""Some Royalprints that can be used with the Royalnet Flask server."""
|
||||||
|
|
||||||
from .home import rp as rp_home
|
from . import home
|
||||||
from .wikiview import rp as rp_wikiview
|
from . import wikiview
|
||||||
from .tglogin import rp as rp_tglogin
|
from . import tglogin
|
||||||
from .docs import rp as rp_docs
|
from . import docs
|
||||||
from .wikiedit import rp as rp_wikiedit
|
from . import wikiedit
|
||||||
from .mcstatus import rp as rp_mcstatus
|
from . import mcstatus
|
||||||
from .diarioview import rp as rp_diarioview
|
from . import diarioview
|
||||||
from .profile import rp as rp_profile
|
from . import profile
|
||||||
|
from . import login
|
||||||
|
|
||||||
__all__ = ["rp_home", "rp_wikiview", "rp_tglogin", "rp_docs", "rp_wikiedit", "rp_mcstatus", "rp_diarioview", "rp_profile"]
|
rp_home = home.rp
|
||||||
|
rp_wikiview = wikiview.rp
|
||||||
|
rp_tglogin = tglogin.rp
|
||||||
|
rp_docs = docs.rp
|
||||||
|
rp_wikiedit = wikiedit.rp
|
||||||
|
rp_mcstatus = mcstatus.rp
|
||||||
|
rp_diarioview = diarioview.rp
|
||||||
|
rp_profile = profile.rp
|
||||||
|
rp_login = login.rp
|
||||||
|
|
||||||
|
__all__ = ["rp_home", "rp_wikiview", "rp_tglogin", "rp_docs", "rp_wikiedit", "rp_mcstatus", "rp_diarioview",
|
||||||
|
"rp_profile", "rp_login"]
|
||||||
|
|
42
royalnet/web/royalprints/login/__init__.py
Normal file
42
royalnet/web/royalprints/login/__init__.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
"""A Royalnet password-based login :py:class:`royalnet.web.Royalprint`."""
|
||||||
|
import flask as f
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import bcrypt
|
||||||
|
from ...royalprint import Royalprint
|
||||||
|
from ...shortcuts import error
|
||||||
|
from ....database.tables import Royal
|
||||||
|
|
||||||
|
|
||||||
|
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
|
||||||
|
rp = Royalprint("login", __name__, url_prefix="/login/password", required_tables={Royal},
|
||||||
|
template_folder=tmpl_dir)
|
||||||
|
|
||||||
|
|
||||||
|
@rp.route("/")
|
||||||
|
def login_index():
|
||||||
|
f.session.pop("royal", None)
|
||||||
|
return f.render_template("login_index.html")
|
||||||
|
|
||||||
|
|
||||||
|
@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:
|
||||||
|
return error(400, "Nessun username inserito.")
|
||||||
|
royal_user = alchemy_session.query(alchemy.Royal).filter_by(username=data["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:
|
||||||
|
return error(400, "Nessuna password inserita.")
|
||||||
|
if not bcrypt.checkpw(bytes(data["password"], encoding="utf8"), royal_user.password):
|
||||||
|
return error(400, "La password inserita non è valida.")
|
||||||
|
f.session["royal"] = {
|
||||||
|
"uid": royal_user.uid,
|
||||||
|
"username": royal_user.username,
|
||||||
|
"avatar": royal_user.avatar,
|
||||||
|
"role": royal_user.role
|
||||||
|
}
|
||||||
|
f.session["login_date"] = datetime.datetime.now()
|
||||||
|
return f.render_template("login_success.html")
|
46
royalnet/web/royalprints/login/templates/login_index.html
Normal file
46
royalnet/web/royalprints/login/templates/login_index.html
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Password Login
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="login">
|
||||||
|
<div class="doublebox">
|
||||||
|
<div class="top">
|
||||||
|
<span class="left">
|
||||||
|
Password Login
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="bot">
|
||||||
|
<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>
|
||||||
|
<p>
|
||||||
|
Essi avranno il seguente formato:
|
||||||
|
</p>
|
||||||
|
<pre><code>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]</code></pre>
|
||||||
|
<form action="{{ url_for("login.login_done") }}" method="post" class="login-form fullsize">
|
||||||
|
<label for="login-username">
|
||||||
|
<span class="label-text">Username</span>
|
||||||
|
<input id="login-username" type="text" name="username">
|
||||||
|
</label>
|
||||||
|
<label for="login-password">
|
||||||
|
<span class="label-text">Password</span>
|
||||||
|
<input id="login-password" type="password" name="password">
|
||||||
|
</label>
|
||||||
|
<label for="login-submit">
|
||||||
|
<input id="login-submit" type="submit" value="Login">
|
||||||
|
</label>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
18
royalnet/web/royalprints/login/templates/login_success.html
Normal file
18
royalnet/web/royalprints/login/templates/login_success.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Successful Password Login
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="doublebox">
|
||||||
|
<div class="top">
|
||||||
|
<span class="left">
|
||||||
|
Password Login
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="bot">
|
||||||
|
Login riuscito! Sei connesso come <b>{{ session["royal"]["username"] }}</b>!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -1,14 +1,14 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
Indice RYGwiki
|
Elenco Utenti
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="doublebox">
|
<div class="doublebox">
|
||||||
<div class="top">
|
<div class="top">
|
||||||
<span class="left">
|
<span class="left">
|
||||||
Elenco Membri
|
Elenco Utenti
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bot">
|
<div class="bot">
|
||||||
|
|
|
@ -47,4 +47,4 @@ def tglogin_done():
|
||||||
"role": royal_user.role
|
"role": royal_user.role
|
||||||
}
|
}
|
||||||
f.session["login_date"] = datetime.datetime.now()
|
f.session["login_date"] = datetime.datetime.now()
|
||||||
return f.render_template("tglogin_success.html")
|
return f.render_template("login_success.html")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
Login with Telegram
|
Telegram Login
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
Login with Telegram
|
Successful Telegram Login
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="doublebox">
|
<div class="doublebox">
|
||||||
<div class="top">
|
<div class="top">
|
||||||
<span class="left">
|
<span class="left">
|
||||||
Telegram login
|
Telegram Login
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bot">
|
<div class="bot">
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bot">
|
<div class="bot">
|
||||||
<form method="POST" class="wikiedit-form">
|
<form method="POST" class="wikiedit-form fullsize">
|
||||||
<label for="wikiedit-title">
|
<label for="wikiedit-title">
|
||||||
<span class="label-text">Titolo</span>
|
<span class="label-text">Titolo</span>
|
||||||
<input id="wikiedit-title" type="text" name="title" value="{{ page.title }}">
|
<input id="wikiedit-title" type="text" name="title" value="{{ page.title }}">
|
||||||
|
|
|
@ -6,7 +6,7 @@ import re
|
||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
from ...royalprint import Royalprint
|
from ...royalprint import Royalprint
|
||||||
from ...shortcuts import error
|
from ...shortcuts import error, from_urluuid
|
||||||
from ....database.tables import Royal, WikiPage, WikiRevision
|
from ....database.tables import Royal, WikiPage, WikiRevision
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,11 +58,12 @@ def wikiview_index():
|
||||||
return f.render_template("wikiview_index.html", pages=pages)
|
return f.render_template("wikiview_index.html", pages=pages)
|
||||||
|
|
||||||
|
|
||||||
@rp.route("/<uuid:page_id>", defaults={"title": ""})
|
@rp.route("/<page_id>", defaults={"title": ""})
|
||||||
@rp.route("/<uuid:page_id>/<title>")
|
@rp.route("/<page_id>/<title>")
|
||||||
def wikiview_by_id(page_id: uuid.UUID, title: str):
|
def wikiview_by_id(page_id: str, title: str):
|
||||||
|
page_uuid = from_urluuid(page_id)
|
||||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
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:
|
if page is None:
|
||||||
return error(404, f"La pagina richiesta non esiste.")
|
return error(404, f"La pagina richiesta non esiste.")
|
||||||
return prepare_page(page)
|
return prepare_page(page)
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
import flask as f
|
import flask as f
|
||||||
|
import uuid as _uuid
|
||||||
|
import base64
|
||||||
|
|
||||||
|
|
||||||
def error(code, reason):
|
def error(code, reason):
|
||||||
return f.render_template("error.html", title=f"Errore {code}", reason=reason), code
|
return f.render_template("error.html", title=f"Errore {code}", reason=reason), code
|
||||||
|
|
||||||
|
|
||||||
|
def to_urluuid(uuid: _uuid.UUID) -> str:
|
||||||
|
"""Return a base64 url-friendly short UUID."""
|
||||||
|
return str(base64.urlsafe_b64encode(uuid.bytes), encoding="ascii")
|
||||||
|
|
||||||
|
|
||||||
|
def from_urluuid(b: str) -> _uuid.UUID:
|
||||||
|
return _uuid.UUID(bytes=base64.urlsafe_b64decode(bytes(b, encoding="ascii")))
|
||||||
|
|
|
@ -504,52 +504,52 @@ input[disabled=""],
|
||||||
button[disabled=""] {
|
button[disabled=""] {
|
||||||
opacity: 0.3;
|
opacity: 0.3;
|
||||||
}
|
}
|
||||||
.wikiedit-form label {
|
form.fullsize label {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.wikiedit-form label .label-text {
|
form.fullsize label .label-text {
|
||||||
margin-right: 12px;
|
margin-right: 12px;
|
||||||
min-width: 60px;
|
min-width: 60px;
|
||||||
}
|
}
|
||||||
.wikiedit-form label input {
|
form.fullsize label input {
|
||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
.wikiedit-form label[for="wikiedit-title"] {
|
form.fullsize label[for="wikiedit-title"] {
|
||||||
font-size: x-large;
|
font-size: x-large;
|
||||||
}
|
}
|
||||||
.wikiedit-form label[for="wikiedit-title"] * {
|
form.fullsize label[for="wikiedit-title"] * {
|
||||||
font-size: x-large;
|
font-size: x-large;
|
||||||
}
|
}
|
||||||
.wikiedit-form .editor-toolbar,
|
form.fullsize .editor-toolbar,
|
||||||
.wikiedit-form .editor-statusbar {
|
form.fullsize .editor-statusbar {
|
||||||
background-color: #0e1c47;
|
background-color: #0e1c47;
|
||||||
color: #a0ccff !important;
|
color: #a0ccff !important;
|
||||||
border: 0;
|
border: 0;
|
||||||
opacity: 1 !important;
|
opacity: 1 !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .editor-toolbar a,
|
form.fullsize .editor-toolbar a,
|
||||||
.wikiedit-form .editor-statusbar a {
|
form.fullsize .editor-statusbar a {
|
||||||
color: #a0ccff !important;
|
color: #a0ccff !important;
|
||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
.wikiedit-form .editor-toolbar a:hover,
|
form.fullsize .editor-toolbar a:hover,
|
||||||
.wikiedit-form .editor-statusbar a:hover {
|
form.fullsize .editor-statusbar a:hover {
|
||||||
background-color: rgba(160, 204, 255, 0.2);
|
background-color: rgba(160, 204, 255, 0.2);
|
||||||
color: #ffffff !important;
|
color: #ffffff !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .editor-toolbar a.active,
|
form.fullsize .editor-toolbar a.active,
|
||||||
.wikiedit-form .editor-statusbar a.active {
|
form.fullsize .editor-statusbar a.active {
|
||||||
background-color: rgba(160, 204, 255, 0.3);
|
background-color: rgba(160, 204, 255, 0.3);
|
||||||
color: white !important;
|
color: white !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .editor-toolbar a.active:hover,
|
form.fullsize .editor-toolbar a.active:hover,
|
||||||
.wikiedit-form .editor-statusbar a.active:hover {
|
form.fullsize .editor-statusbar a.active:hover {
|
||||||
background-color: rgba(160, 204, 255, 0.2);
|
background-color: rgba(160, 204, 255, 0.2);
|
||||||
color: #ffffff !important;
|
color: #ffffff !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror {
|
form.fullsize .CodeMirror {
|
||||||
font-family: "Consolas", monospace !important;
|
font-family: "Consolas", monospace !important;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
color: #a0ccff;
|
color: #a0ccff;
|
||||||
|
@ -559,28 +559,28 @@ button[disabled=""] {
|
||||||
border-right: 1px solid rgba(160, 204, 255, 0.2);
|
border-right: 1px solid rgba(160, 204, 255, 0.2);
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-link {
|
form.fullsize .CodeMirror .cm-link {
|
||||||
color: #7dffff !important;
|
color: #7dffff !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-url {
|
form.fullsize .CodeMirror .cm-url {
|
||||||
color: #00caca !important;
|
color: #00caca !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-tag {
|
form.fullsize .CodeMirror .cm-tag {
|
||||||
color: #ff7dff !important;
|
color: #ff7dff !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-strong {
|
form.fullsize .CodeMirror .cm-strong {
|
||||||
color: #ffff7d !important;
|
color: #ffff7d !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-em {
|
form.fullsize .CodeMirror .cm-em {
|
||||||
color: #ffbb7d !important;
|
color: #ffbb7d !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-quote {
|
form.fullsize .CodeMirror .cm-quote {
|
||||||
color: #7dff7d !important;
|
color: #7dff7d !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-comment {
|
form.fullsize .CodeMirror .cm-comment {
|
||||||
color: lightgray !important;
|
color: lightgray !important;
|
||||||
}
|
}
|
||||||
.wikiedit-form .CodeMirror .cm-header {
|
form.fullsize .CodeMirror .cm-header {
|
||||||
color: #ffffff !important;
|
color: #ffffff !important;
|
||||||
}
|
}
|
||||||
.mcstatus-grid {
|
.mcstatus-grid {
|
||||||
|
|
|
@ -622,7 +622,7 @@ table {
|
||||||
opacity: 0.3;
|
opacity: 0.3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wikiedit-form {
|
form.fullsize {
|
||||||
|
|
||||||
label {
|
label {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
|
|
Loading…
Reference in a new issue