minimal visual improvements
This commit is contained in:
29
src/app.py
29
src/app.py
@@ -15,12 +15,23 @@ app = FastAPI(
|
|||||||
openapi_url=None # Disable OpenAPI JSON schema
|
openapi_url=None # Disable OpenAPI JSON schema
|
||||||
)
|
)
|
||||||
|
|
||||||
|
STYLES = """
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
"""
|
||||||
|
|
||||||
@app.get("/register", response_class=HTMLResponse)
|
@app.get("/register", response_class=HTMLResponse)
|
||||||
async def register_form():
|
async def register_form():
|
||||||
return """
|
return f"""
|
||||||
<html>
|
<html>
|
||||||
<head><title>Регистрация</title></head>
|
<head><title>Регистрация</title>{STYLES}</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>Регистрация</h2>
|
<h2>Регистрация</h2>
|
||||||
<form action="/register" method="post">
|
<form action="/register" method="post">
|
||||||
@@ -43,9 +54,9 @@ async def register(login: str = Form(...), password: str = Form(...)):
|
|||||||
response.set_cookie("password", password)
|
response.set_cookie("password", password)
|
||||||
return response
|
return response
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
return HTMLResponse("""
|
return HTMLResponse(f"""
|
||||||
<html>
|
<html>
|
||||||
<head><title>Ошибка регистрации</title></head>
|
<head><title>Ошибка регистрации</title>{STYLES}</head>
|
||||||
<body>
|
<body>
|
||||||
<h3>Login уже существует</h3>
|
<h3>Login уже существует</h3>
|
||||||
<a href='/register'>Попробовать снова</a>
|
<a href='/register'>Попробовать снова</a>
|
||||||
@@ -55,9 +66,9 @@ async def register(login: str = Form(...), password: str = Form(...)):
|
|||||||
|
|
||||||
@app.get("/login", response_class=HTMLResponse)
|
@app.get("/login", response_class=HTMLResponse)
|
||||||
async def login_form():
|
async def login_form():
|
||||||
return """
|
return f"""
|
||||||
<html>
|
<html>
|
||||||
<head><title>Вход</title></head>
|
<head><title>Вход</title>{STYLES}</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>Вход</h2>
|
<h2>Вход</h2>
|
||||||
<form action="/login" method="post">
|
<form action="/login" method="post">
|
||||||
@@ -80,9 +91,9 @@ async def login(login: str = Form(...), password: str = Form(...)):
|
|||||||
response.set_cookie("password", password)
|
response.set_cookie("password", password)
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
return HTMLResponse("""
|
return HTMLResponse(f"""
|
||||||
<html>
|
<html>
|
||||||
<head><title>Ошибка входа</title></head>
|
<head><title>Ошибка входа</title>{STYLES}</head>
|
||||||
<body>
|
<body>
|
||||||
<h3>Неверные учетные данные</h3>
|
<h3>Неверные учетные данные</h3>
|
||||||
<a href='/login'>Попробовать снова</a>
|
<a href='/login'>Попробовать снова</a>
|
||||||
@@ -101,7 +112,7 @@ async def welcome(request: Request):
|
|||||||
if user:
|
if user:
|
||||||
return f"""
|
return f"""
|
||||||
<html>
|
<html>
|
||||||
<head><title>Добро пожаловать</title></head>
|
<head><title>Добро пожаловать</title>{STYLES}</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Привет, {login}</h1>
|
<h1>Привет, {login}</h1>
|
||||||
<form action="/logout" method="post" onsubmit="return logoutAlert();">
|
<form action="/logout" method="post" onsubmit="return logoutAlert();">
|
||||||
|
|||||||
Reference in New Issue
Block a user