Switched to other domain

This commit is contained in:
StNicolay 2024-08-16 18:40:42 +03:00
parent aa786de5b4
commit d6ecae08bd
Signed by: StNicolay
GPG Key ID: 9693D04DCD962B0D
4 changed files with 34 additions and 26 deletions

View File

@ -8,11 +8,7 @@ from state import State
if __name__ == "__main__":
dotenv.load_dotenv()
url = os.environ.get("DRIVE_HOST_URL")
if not url:
url = "localhost:3000"
else:
url = url.strip()
app = QApplication(sys.argv)
window = State(url)
window = State()
window.show()
sys.exit(app.exec())

View File

@ -58,7 +58,7 @@ class RegisterWidget(QWidget):
try:
response = RequestClient().client.post(
"http://localhost:3000/users/register",
"/users/register",
data={
"username": username,
"email": email,
@ -79,6 +79,7 @@ class RegisterWidget(QWidget):
self, "Error", f"Registration failed: {response.text}"
)
except httpx.HTTPError as e:
print(e)
QMessageBox.critical(self, "HTTP Error", str(e))
@ -116,12 +117,14 @@ class LoginWidget(QWidget):
password = self.password_input.text()
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
try:
response = RequestClient().client.post(
"http://localhost:3000/users/authorize",
"/users/authorize",
data={"username": username, "password": password},
)
if response.is_success:
@ -129,8 +132,12 @@ class LoginWidget(QWidget):
if access_token:
self.switcher.login(access_token)
else:
QMessageBox.warning(self, "Error", "No access token received")
QMessageBox.warning(
self, "Error", "No access token received"
)
else:
QMessageBox.warning(self, "Error", f"Login failed: {response.text}")
QMessageBox.warning(
self, "Error", f"Login failed: {response.text}"
)
except httpx.HTTPError as e:
QMessageBox.critical(self, "HTTP Error", str(e))

View File

@ -9,9 +9,9 @@ class RequestClient:
def __new__(cls) -> Self:
if cls._client is None:
url = os.environ.get("DRIVE_HOST_URL").strip()
if not url:
url = "localhost:3000"
url = os.environ.get("DRIVE_HOST_URL")
if url is None:
url = "https://drive.stnicolay.ru"
cls._client = httpx.Client(base_url=url)
return super().__new__(cls)

View File

@ -1,20 +1,18 @@
import auth
import file_widgets
import httpx
import keyring
import request_client
import sync
from PyQt6.QtWidgets import QMainWindow, QStackedWidget
from PyQt6.QtWidgets import QMainWindow, QStackedWidget, QMessageBox
class State(QMainWindow):
def __init__(self, url: str):
def __init__(self):
super().__init__()
self.setWindowTitle("Auth App")
self.stack = QStackedWidget()
self.client = httpx.Client(base_url=url)
self.register_widget = auth.RegisterWidget(self)
self.login_widget = auth.LoginWidget(self)
@ -38,15 +36,22 @@ class State(QMainWindow):
self.stack.setCurrentWidget(self.register_widget)
def login(self, token: str):
keyring.set_password("auth_app", "access_token", token)
request_client.RequestClient().set_token(token)
sync.SyncData.sync_all(
# "/home/stnicolay/backups",
# uuid.UUID("0191397f-ae77-7b2a-bed7-9d28ed56a90a"),
)
self.file_widget = file_widgets.MainFileWidget(self)
self.stack.addWidget(self.file_widget)
self.stack.setCurrentWidget(self.file_widget)
try:
keyring.set_password("auth_app", "access_token", token)
request_client.RequestClient().set_token(token)
sync.SyncData.sync_all(
# "/home/stnicolay/backups",
# uuid.UUID("0191397f-ae77-7b2a-bed7-9d28ed56a90a"),
)
self.file_widget = file_widgets.MainFileWidget(self)
self.stack.addWidget(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):
keyring.delete_password("auth_app", "access_token")