mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
tglogin progress
This commit is contained in:
parent
7fd241e1fd
commit
d6ac988a9c
6 changed files with 57 additions and 27 deletions
|
@ -1,13 +1,13 @@
|
|||
import os
|
||||
from .web import create_app
|
||||
from .web.blueprints import home, wikiview
|
||||
from .web.blueprints import home, wikiview, tglogin
|
||||
|
||||
|
||||
class TestConfig:
|
||||
DB_PATH = os.environ["DB_PATH"]
|
||||
|
||||
|
||||
app = create_app(TestConfig, [home, wikiview])
|
||||
app = create_app(TestConfig, [home, wikiview, tglogin])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -2,5 +2,6 @@ from .helloworld import bp as helloworld
|
|||
from .testing import bp as testing
|
||||
from .home import bp as home
|
||||
from .wikiview import bp as wikiview
|
||||
from .tglogin import bp as tglogin
|
||||
|
||||
__all__ = ["helloworld", "testing", "home", "wikiview"]
|
||||
__all__ = ["helloworld", "testing", "home", "wikiview", "tglogin"]
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import flask as f
|
||||
from .. import Royalprint
|
||||
|
||||
|
||||
bp = Royalprint("helloworld", __name__, url_prefix="/helloworld")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def helloworld():
|
||||
return "Hello world!"
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
import flask as f
|
||||
from .. import Royalprint
|
||||
from ...database.tables import Royal
|
||||
|
||||
|
||||
bp = Royalprint("testing", __name__, url_prefix="/testing", required_tables={Royal})
|
||||
|
||||
|
||||
@bp.route("/listroyals")
|
||||
def listroyals():
|
||||
from ..alchemyhandler import alchemy, alchemy_session
|
||||
royals = alchemy_session.query(alchemy.Royal).all()
|
||||
return f'<body><script type="text/plain" style="display: block;">{repr(royals)}</script></body>'
|
35
royalnet/web/blueprints/tglogin/__init__.py
Normal file
35
royalnet/web/blueprints/tglogin/__init__.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import flask as f
|
||||
import hashlib
|
||||
import hmac
|
||||
from ... import Royalprint
|
||||
from ....database.tables import Royal, Telegram
|
||||
|
||||
|
||||
bp = Royalprint("tglogin", __name__, url_prefix="/login/telegram", required_tables={Royal, Telegram},
|
||||
template_folder="templates")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def tglogin_index():
|
||||
return f.render_template("tglogin_index.html")
|
||||
|
||||
|
||||
@bp.route("/done")
|
||||
def tglogin_done():
|
||||
from ...alchemyhandler import alchemy, alchemy_session
|
||||
data_check_string = ""
|
||||
for field in f.request.args:
|
||||
if field == "hash":
|
||||
continue
|
||||
data_check_string += f"{field}={f.request.args['field']}\n"
|
||||
data_check_string.rstrip("\n")
|
||||
secret_key = hashlib.sha256(f.current_app.config["TG_AK"])
|
||||
hex_data = hmac.new(key=secret_key, msg=data_check_string, digestmod="sha256").hexdigest()
|
||||
if hex_data != f.request.args["hash"]:
|
||||
return "Invalid authentication", 403
|
||||
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
|
||||
royal_user = tg_user.royal
|
||||
f.session["royal_id"] = royal_user.id
|
||||
return f.redirect(f.url_for("/"))
|
18
royalnet/web/blueprints/tglogin/templates/tglogin_index.html
Normal file
18
royalnet/web/blueprints/tglogin/templates/tglogin_index.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}
|
||||
Login with Telegram
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="doublebox">
|
||||
<div class="top">
|
||||
<span class="left">
|
||||
Telegram login
|
||||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
<script async src="https://telegram.org/js/telegram-widget.js?6" data-telegram-login="royalgamesbot" data-size="large" data-auth-url="{{ url_for("tglogin.tglogin_done") }}" data-request-access="write"></script>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in a new issue