Compare commits
2 Commits
409f13b584
...
d6ecae08bd
Author | SHA1 | Date | |
---|---|---|---|
d6ecae08bd | |||
aa786de5b4 |
@ -8,11 +8,7 @@ from state import State
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
url = os.environ.get("DRIVE_HOST_URL")
|
url = os.environ.get("DRIVE_HOST_URL")
|
||||||
if not url:
|
|
||||||
url = "localhost:3000"
|
|
||||||
else:
|
|
||||||
url = url.strip()
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
window = State(url)
|
window = State()
|
||||||
window.show()
|
window.show()
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
|
@ -58,7 +58,7 @@ class RegisterWidget(QWidget):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response = RequestClient().client.post(
|
response = RequestClient().client.post(
|
||||||
"http://localhost:3000/users/register",
|
"/users/register",
|
||||||
data={
|
data={
|
||||||
"username": username,
|
"username": username,
|
||||||
"email": email,
|
"email": email,
|
||||||
@ -79,6 +79,7 @@ class RegisterWidget(QWidget):
|
|||||||
self, "Error", f"Registration failed: {response.text}"
|
self, "Error", f"Registration failed: {response.text}"
|
||||||
)
|
)
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
|
print(e)
|
||||||
QMessageBox.critical(self, "HTTP Error", str(e))
|
QMessageBox.critical(self, "HTTP Error", str(e))
|
||||||
|
|
||||||
|
|
||||||
@ -116,12 +117,14 @@ class LoginWidget(QWidget):
|
|||||||
password = self.password_input.text()
|
password = self.password_input.text()
|
||||||
|
|
||||||
if not username or not password:
|
if not username or not password:
|
||||||
QMessageBox.warning(self, "Input Error", "Email and Password are required")
|
QMessageBox.warning(
|
||||||
|
self, "Input Error", "Email and Password are required"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = RequestClient().client.post(
|
response = RequestClient().client.post(
|
||||||
"http://localhost:3000/users/authorize",
|
"/users/authorize",
|
||||||
data={"username": username, "password": password},
|
data={"username": username, "password": password},
|
||||||
)
|
)
|
||||||
if response.is_success:
|
if response.is_success:
|
||||||
@ -129,8 +132,12 @@ class LoginWidget(QWidget):
|
|||||||
if access_token:
|
if access_token:
|
||||||
self.switcher.login(access_token)
|
self.switcher.login(access_token)
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning(self, "Error", "No access token received")
|
QMessageBox.warning(
|
||||||
|
self, "Error", "No access token received"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning(self, "Error", f"Login failed: {response.text}")
|
QMessageBox.warning(
|
||||||
|
self, "Error", f"Login failed: {response.text}"
|
||||||
|
)
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
QMessageBox.critical(self, "HTTP Error", str(e))
|
QMessageBox.critical(self, "HTTP Error", str(e))
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import os
|
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Protocol, Self
|
from typing import Protocol, Self
|
||||||
|
|
||||||
import create_folder_widget
|
import create_folder_widget
|
||||||
import sync
|
import sync
|
||||||
import httpx
|
|
||||||
import pydantic
|
import pydantic
|
||||||
import state
|
import state
|
||||||
import user
|
import user
|
||||||
@ -26,7 +24,6 @@ from PyQt6.QtWidgets import (
|
|||||||
QListWidget,
|
QListWidget,
|
||||||
QListWidgetItem,
|
QListWidgetItem,
|
||||||
QMenu,
|
QMenu,
|
||||||
QMessageBox,
|
|
||||||
QPushButton,
|
QPushButton,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QWidget,
|
QWidget,
|
||||||
@ -129,7 +126,7 @@ class FileListWidget(QListWidget):
|
|||||||
item = self.current_response().items()[row]
|
item = self.current_response().items()[row]
|
||||||
item.double_click(self)
|
item.double_click(self)
|
||||||
|
|
||||||
def current_response(self) -> ListResponse:
|
def current_response(self) -> ResponseProtocol:
|
||||||
if not self.responses:
|
if not self.responses:
|
||||||
self.update_response()
|
self.update_response()
|
||||||
return self.responses[-1]
|
return self.responses[-1]
|
||||||
@ -154,28 +151,10 @@ class FileListWidget(QListWidget):
|
|||||||
self.upload_file(file_path)
|
self.upload_file(file_path)
|
||||||
|
|
||||||
def upload_file(self, file_path):
|
def upload_file(self, file_path):
|
||||||
file_name = os.path.basename(file_path)
|
response = self.current_response()
|
||||||
try:
|
if not isinstance(response, ListResponse):
|
||||||
with open(file_path, "rb") as f:
|
return
|
||||||
files = {"file": (file_name, f)}
|
File.create(file_path, response.folder_id)
|
||||||
response = RequestClient().client.post(
|
|
||||||
"http://localhost:3000/files",
|
|
||||||
files=files,
|
|
||||||
params={
|
|
||||||
"parent_folder": self.current_response().folder_id,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if response.is_success:
|
|
||||||
QMessageBox.information(
|
|
||||||
self, "Success", "File uploaded successfully"
|
|
||||||
)
|
|
||||||
self.update_response()
|
|
||||||
else:
|
|
||||||
QMessageBox.warning(
|
|
||||||
self, "Error", f"Upload failed: {response.text}"
|
|
||||||
)
|
|
||||||
except httpx.HTTPError as e:
|
|
||||||
QMessageBox.critical(self, "HTTP Error", str(e))
|
|
||||||
|
|
||||||
def add_item(self, item: DisplayProtocol):
|
def add_item(self, item: DisplayProtocol):
|
||||||
widget = QListWidgetItem(item.name())
|
widget = QListWidgetItem(item.name())
|
||||||
|
@ -9,9 +9,9 @@ class RequestClient:
|
|||||||
|
|
||||||
def __new__(cls) -> Self:
|
def __new__(cls) -> Self:
|
||||||
if cls._client is None:
|
if cls._client is None:
|
||||||
url = os.environ.get("DRIVE_HOST_URL").strip()
|
url = os.environ.get("DRIVE_HOST_URL")
|
||||||
if not url:
|
if url is None:
|
||||||
url = "localhost:3000"
|
url = "https://drive.stnicolay.ru"
|
||||||
cls._client = httpx.Client(base_url=url)
|
cls._client = httpx.Client(base_url=url)
|
||||||
return super().__new__(cls)
|
return super().__new__(cls)
|
||||||
|
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
import auth
|
import auth
|
||||||
import file_widgets
|
import file_widgets
|
||||||
import httpx
|
|
||||||
import keyring
|
import keyring
|
||||||
import request_client
|
import request_client
|
||||||
import sync
|
import sync
|
||||||
from PyQt6.QtWidgets import QMainWindow, QStackedWidget
|
from PyQt6.QtWidgets import QMainWindow, QStackedWidget, QMessageBox
|
||||||
|
|
||||||
|
|
||||||
class State(QMainWindow):
|
class State(QMainWindow):
|
||||||
def __init__(self, url: str):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.setWindowTitle("Auth App")
|
self.setWindowTitle("Auth App")
|
||||||
|
|
||||||
self.stack = QStackedWidget()
|
self.stack = QStackedWidget()
|
||||||
self.client = httpx.Client(base_url=url)
|
|
||||||
self.register_widget = auth.RegisterWidget(self)
|
self.register_widget = auth.RegisterWidget(self)
|
||||||
self.login_widget = auth.LoginWidget(self)
|
self.login_widget = auth.LoginWidget(self)
|
||||||
|
|
||||||
@ -38,6 +36,7 @@ class State(QMainWindow):
|
|||||||
self.stack.setCurrentWidget(self.register_widget)
|
self.stack.setCurrentWidget(self.register_widget)
|
||||||
|
|
||||||
def login(self, token: str):
|
def login(self, token: str):
|
||||||
|
try:
|
||||||
keyring.set_password("auth_app", "access_token", token)
|
keyring.set_password("auth_app", "access_token", token)
|
||||||
request_client.RequestClient().set_token(token)
|
request_client.RequestClient().set_token(token)
|
||||||
sync.SyncData.sync_all(
|
sync.SyncData.sync_all(
|
||||||
@ -47,6 +46,12 @@ class State(QMainWindow):
|
|||||||
self.file_widget = file_widgets.MainFileWidget(self)
|
self.file_widget = file_widgets.MainFileWidget(self)
|
||||||
self.stack.addWidget(self.file_widget)
|
self.stack.addWidget(self.file_widget)
|
||||||
self.stack.setCurrentWidget(self.file_widget)
|
self.stack.setCurrentWidget(self.file_widget)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
keyring.delete_password("auth_app", "access_token")
|
||||||
|
QMessageBox.information(
|
||||||
|
None, "Error logging in", "Error logging in"
|
||||||
|
)
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
keyring.delete_password("auth_app", "access_token")
|
keyring.delete_password("auth_app", "access_token")
|
||||||
|
Reference in New Issue
Block a user