This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Импорт изменений для стабильной версии 0.1.0 (#150)
* Updating Python to version 3.10 (#122) also updated uvicorn, fastapi, jinja2, websockets * Переход на python 3.10 (замена If-Else на Match-Case) и переделка системы генерации ошибок (#123) * Изменения для выполнения тикетов #98 #50 (#124) * Исправления в системе тестирования кода, закрытие тикетов #125 #126 #101 #100 (#127) * Добавлена панель администратора (#129) * Добавление дополнительной абстракции для работы с бд #128 (#136) * Реализация единой точки обработки конфигурационного файла (#137) * Разделение кода протокола и контроллера #139 (#141) * Небольшие правки кода перед переносов в мастер и релизом версии 0.1.0 (#143) Co-authored-by: NekrodNIK <60639354+NekrodNIK@users.noreply.github.com>
- Loading branch information
1 parent
f7c714d
commit 59bd6ed
Showing
69 changed files
with
5,266 additions
and
2,337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
""" | ||
Copyright (c) 2020 - present NekrodNIK, Stepan Skriabin, rus-ai and other. | ||
Look at the file AUTHORS.md(located at the root of the project) to get the | ||
full list. | ||
This file is part of Morelia Server. | ||
Morelia Server is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Morelia Server is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with Morelia Server. If not, see <https://www.gnu.org/licenses/>. | ||
""" | ||
from fastapi import Depends | ||
from fastapi.applications import FastAPI | ||
from fastapi.requests import Request | ||
from fastapi.templating import Jinja2Templates | ||
from pathlib import Path | ||
from starlette.responses import RedirectResponse | ||
|
||
from mod.db.dbhandler import DBHandler | ||
from mod.config import DATABASE | ||
from . import login | ||
from . import logs | ||
from . import control as manage | ||
|
||
app = FastAPI() | ||
|
||
templates = Jinja2Templates(Path(__file__).parent / "templates") | ||
|
||
app.include_router(login.router) | ||
app.include_router(logs.router) | ||
app.include_router(manage.router) | ||
|
||
db_connect = DBHandler(DATABASE.get('URI')) | ||
|
||
|
||
@app.exception_handler(login.NotAuthenticatedException) | ||
def not_login_exception_handler(request: Request, | ||
exc: login.NotAuthenticatedException): | ||
return RedirectResponse(url="/admin/login") | ||
|
||
|
||
@app.get("/login") | ||
def login_admin(request: Request): | ||
return templates.TemplateResponse("login.html", { | ||
"request": request | ||
}) | ||
|
||
|
||
@app.get("/") | ||
def index_admin(request: Request, | ||
user=Depends(login.login_manager)): | ||
return templates.TemplateResponse("index_admin.html", { | ||
"request": request | ||
}) | ||
|
||
|
||
@app.get("/status") | ||
def status_admin(request: Request, | ||
user=Depends(login.login_manager)): | ||
dbquery = db_connect.get_table_count() | ||
return templates.TemplateResponse("status_admin.html", | ||
{"request": request, | ||
"Messages_count": dbquery.message_count, | ||
"Flows_count": dbquery.flow_count, | ||
"Users_count": dbquery.user_count | ||
}) | ||
|
||
|
||
# TODO Полностью доделать(на данный момент управление сервером не работает) | ||
# после того, как будут сделаны методы работы с бд | ||
@app.get("/manage") | ||
def manage_admin(request: Request, | ||
user=Depends(login.login_manager)): | ||
dbquery = db_connect.get_all_user() | ||
return templates.TemplateResponse("manage_admin.html", { | ||
"request": request, | ||
"users": dbquery.count() | ||
}) | ||
|
||
|
||
@app.get("/logs") | ||
def manage_logs(request: Request, | ||
user=Depends(login.login_manager)): | ||
return templates.TemplateResponse("logs_admin.html", { | ||
"request": request | ||
}) |
Oops, something went wrong.