init commit
This commit is contained in:
163
client/.gitignore
vendored
Normal file
163
client/.gitignore
vendored
Normal file
@ -0,0 +1,163 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
*.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# PyCharm
|
||||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
# Flet
|
||||
storage/
|
||||
2
client/poetry.toml
Normal file
2
client/poetry.toml
Normal file
@ -0,0 +1,2 @@
|
||||
[virtualenvs]
|
||||
in-project = true
|
||||
36
client/pyproject.toml
Normal file
36
client/pyproject.toml
Normal file
@ -0,0 +1,36 @@
|
||||
[project]
|
||||
name = "sonoma-app-client"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
requires-python = ">=3.12"
|
||||
authors = [
|
||||
{ name = "SaddyDEAD", email = "saddydead@sonoma.su" }
|
||||
]
|
||||
dependencies = [
|
||||
"flet==0.28.3",
|
||||
"cryptography",
|
||||
"httpx (>=0.28.1,<0.29.0)"
|
||||
]
|
||||
|
||||
[tool.flet]
|
||||
org = "su.sonoma"
|
||||
|
||||
product = "SApp"
|
||||
|
||||
company = "Sonoma"
|
||||
|
||||
copyright = "Copyright (C) 2025 by Sonoma Org."
|
||||
|
||||
[tool.flet.app]
|
||||
path = "src"
|
||||
|
||||
[tool.uv]
|
||||
dev-dependencies = [
|
||||
"flet[all]==0.28.3",
|
||||
]
|
||||
|
||||
[tool.poetry]
|
||||
package-mode = false
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
flet = {extras = ["all"], version = "0.28.3"}
|
||||
BIN
client/src/assets/sonoma.png
Normal file
BIN
client/src/assets/sonoma.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
28
client/src/auth/login.py
Normal file
28
client/src/auth/login.py
Normal file
@ -0,0 +1,28 @@
|
||||
from cryptography.fernet import Fernet
|
||||
import os
|
||||
import httpx
|
||||
|
||||
KEY_FILE = ".key"
|
||||
REMEMBER_FILE = ".auth_data"
|
||||
|
||||
def generate_key():
|
||||
if not os.path.exists(KEY_FILE):
|
||||
key = Fernet.generate_key()
|
||||
with open(KEY_FILE, "wb") as f:
|
||||
f.write(key)
|
||||
|
||||
|
||||
async def load_fernet():
|
||||
with open(KEY_FILE, "rb") as f:
|
||||
key = f.read()
|
||||
return Fernet(key)
|
||||
|
||||
|
||||
async def login(name: str, password: str):
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.post(f'http://127.0.0.1:7535/login?name={name}&password={password}')
|
||||
|
||||
if r.is_success:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
102
client/src/main.py
Normal file
102
client/src/main.py
Normal file
@ -0,0 +1,102 @@
|
||||
import flet as ft
|
||||
from auth.login import *
|
||||
|
||||
USERNAME = "admin"
|
||||
PASSWORD = "1234"
|
||||
|
||||
|
||||
def generate_key():
|
||||
if not os.path.exists(KEY_FILE):
|
||||
key = Fernet.generate_key()
|
||||
with open(KEY_FILE, "wb") as f:
|
||||
f.write(key)
|
||||
|
||||
|
||||
async def load_fernet():
|
||||
with open(KEY_FILE, "rb") as f:
|
||||
key = f.read()
|
||||
return Fernet(key)
|
||||
|
||||
|
||||
async def main(page: ft.Page):
|
||||
generate_key()
|
||||
fernet = await load_fernet()
|
||||
|
||||
page.title = "SClient"
|
||||
page.window_width = 400
|
||||
page.window_height = 300
|
||||
page.vertical_alignment = ft.MainAxisAlignment.CENTER
|
||||
|
||||
login_input = ft.TextField(label="Логин", autofocus=True)
|
||||
password_input = ft.TextField(label="Пароль", password=True, can_reveal_password=True)
|
||||
remember_checkbox = ft.Checkbox(label="Запомнить меня")
|
||||
status_text = ft.Text(color=ft.Colors.RED)
|
||||
|
||||
if os.path.exists(REMEMBER_FILE):
|
||||
try:
|
||||
with open(REMEMBER_FILE, "rb") as f:
|
||||
lines = f.readlines()
|
||||
if len(lines) == 2:
|
||||
saved_login = lines[0].decode().strip()
|
||||
encrypted_pw = lines[1].strip()
|
||||
decrypted_pw = fernet.decrypt(encrypted_pw).decode()
|
||||
|
||||
login_input.value = saved_login
|
||||
password_input.value = decrypted_pw
|
||||
remember_checkbox.value = True
|
||||
except Exception as e:
|
||||
print(f"[ОШИБКА] Не удалось прочитать данные: {e}")
|
||||
|
||||
async def login_click(e):
|
||||
if await login(login_input.value, password_input.value):
|
||||
if remember_checkbox.value:
|
||||
encrypted_pw = fernet.encrypt(password_input.value.encode())
|
||||
with open(REMEMBER_FILE, "wb") as f:
|
||||
f.write(f"{login_input.value}\n".encode())
|
||||
f.write(encrypted_pw)
|
||||
else:
|
||||
if os.path.exists(REMEMBER_FILE):
|
||||
os.remove(REMEMBER_FILE)
|
||||
|
||||
page.clean()
|
||||
page.add(
|
||||
ft.Column(
|
||||
[
|
||||
ft.Text(f"Добро пожаловать, {USERNAME}!", size=24),
|
||||
ft.ElevatedButton("Выйти", on_click=lambda e: page.go("/"))
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.CENTER,
|
||||
horizontal_alignment=ft.CrossAxisAlignment.CENTER
|
||||
)
|
||||
)
|
||||
else:
|
||||
status_text.value = "Неверный логин или пароль"
|
||||
page.update()
|
||||
|
||||
page.add(
|
||||
ft.Container(
|
||||
content=ft.Column(
|
||||
controls=[
|
||||
ft.Image(
|
||||
src="sonoma.png",
|
||||
width=50,
|
||||
height=50,
|
||||
fit=ft.ImageFit.CONTAIN
|
||||
),
|
||||
ft.Text("SClient", size=24, weight=ft.FontWeight.BOLD),
|
||||
login_input,
|
||||
password_input,
|
||||
remember_checkbox,
|
||||
ft.ElevatedButton("Войти", on_click=login_click),
|
||||
status_text
|
||||
],
|
||||
width=300,
|
||||
alignment=ft.MainAxisAlignment.CENTER,
|
||||
horizontal_alignment=ft.CrossAxisAlignment.CENTER
|
||||
),
|
||||
alignment=ft.alignment.center,
|
||||
expand=True
|
||||
)
|
||||
)
|
||||
|
||||
ft.app(main)
|
||||
Reference in New Issue
Block a user