mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 12:36:23 +03:00
backend: регистрация переведена на классы
This commit is contained in:
@@ -22,8 +22,8 @@ app.config.update(main_settings)
|
|||||||
db_settings = config_data["db_settings"]
|
db_settings = config_data["db_settings"]
|
||||||
app.config.update(db_settings)
|
app.config.update(db_settings)
|
||||||
|
|
||||||
admin.init_app(app)
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
|
admin.init_app(app)
|
||||||
|
|
||||||
from .admin import ts_admin as ts_admin_blueprint
|
from .admin import ts_admin as ts_admin_blueprint
|
||||||
|
|
||||||
|
|||||||
@@ -8,33 +8,35 @@ main = Blueprint("main", __name__)
|
|||||||
|
|
||||||
|
|
||||||
@main.route("/")
|
@main.route("/")
|
||||||
def index():
|
class Index:
|
||||||
return "Nice!", 200
|
def get(self):
|
||||||
|
return "Nice!", 200
|
||||||
|
|
||||||
|
|
||||||
@main.route("/registration", methods=["POST"])
|
@main.route("/registration")
|
||||||
def registration():
|
class Registration:
|
||||||
data = request.get_json()
|
def post(self):
|
||||||
|
data = request.get_json()
|
||||||
|
|
||||||
tg_id = data.get("tg_id")
|
tg_id = data.get("tg_id")
|
||||||
first_name = data.get("first_name")
|
first_name = data.get("first_name")
|
||||||
last_name = data.get("last_name")
|
last_name = data.get("last_name")
|
||||||
username = data.get("username")
|
username = data.get("username")
|
||||||
|
|
||||||
existed_user = User.query.filter_by(tg_id=tg_id).first()
|
existed_user = User.query.filter_by(tg_id=tg_id).first()
|
||||||
|
|
||||||
if not existed_user:
|
if not existed_user:
|
||||||
new_user = User(
|
new_user = User(
|
||||||
tg_id=tg_id,
|
tg_id=tg_id,
|
||||||
first_name=first_name,
|
first_name=first_name,
|
||||||
last_name=last_name,
|
last_name=last_name,
|
||||||
username=username,
|
username=username,
|
||||||
)
|
)
|
||||||
|
|
||||||
db.session.add(new_user)
|
db.session.add(new_user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return {"created": True, "id": new_user.id}
|
return {"created": True, "id": new_user.id}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return {"created": False, "id": existed_user.id}
|
return {"created": False, "id": existed_user.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user