Fix things

This commit is contained in:
2026-01-02 16:17:49 +01:00
parent 3399b5925e
commit 0cc827e1ce
5 changed files with 68 additions and 26 deletions

View File

@@ -2,11 +2,17 @@ from board_mate.auth import *
from flask import jsonify, request
from pydantic import StrictStr
from src.models.AuthData import AuthData
class AuthController:
def __init__(self, app):
_auth_data : AuthData = None
def __init__(self, app, auth_data, host):
self._register_routes(app)
self.config = Configuration(host="https://192.168.15.120:8000")
self.config = Configuration(host=host)
self.auth_data = auth_data
self.config.verify_ssl = False
def _register_routes(self, app):
@@ -30,5 +36,5 @@ class AuthController:
return jsonify({"success" : response.success, "message" : response.message , "data" : response.data}), 200
except Exception as e:
print(f"Exception when calling AuthAPI->login: {e}")
return jsonify({"success" : response.success, "message" : response.message , "data" : response.data}), 500
return jsonify({"success" : False, "message" : e , "data" : null}), 500

View File

@@ -2,11 +2,17 @@ from board_mate.client import Configuration, ApiClient, ClientApi, ClientDto, Ap
from flask import jsonify, request
from pydantic import StrictStr
from src.models.AuthData import AuthData
class ClientController:
def __init__(self, app):
_auth_data : AuthData = None
def __init__(self, app, auth_data, host):
self._register_routes(app)
self.config = Configuration(host="https://192.168.15.120:8000")
self.config = Configuration(host=host)
self.auth_data = auth_data
self.config.verify_ssl = False
def _register_routes(self, app):

View File

@@ -1,7 +1,9 @@
import json
from board_mate.message import Configuration
from flask import jsonify, request
from src.models.AuthData import AuthData
from src.services.mqtt_service import MQTTService
@@ -9,10 +11,12 @@ class MessageController:
_mqtt_service : MQTTService = None
_client_id : MQTTService = None
_auth_data : AuthData = None
def __init__(self, client_id : str, service : MQTTService):
self._mqtt_service = service
self.client_id = client_id
def __init__(self, app, auth_data : AuthData, host : str):
self._register_routes(app)
self.config = Configuration(host=host)
self.auth_data = auth_data
def _register_routes(self, app):
app.add_url_rule("/message/send", view_func=self.send, methods=['POST'])
@@ -23,7 +27,7 @@ class MessageController:
msg = req["message"]
payload = json.dumps({"content" : msg})
print(payload)
self._mqtt_service.publish(f"/chat/${self.client_id}/message", payload)
self._mqtt_service.publish(f"/chat/${self.auth_data.get_client_id()}/message", payload)
return jsonify({"success" : True, "message": "An error occurred"}), 500
except Exception as e:
print(e)

View File

@@ -0,0 +1,19 @@
class AuthData:
_token : str
_client_id : str
def __init__(self):
pass
def get_token(self):
return self._token
def set_token(self, token:str):
self._token = token
def get_client_id(self):
return self._client_id
def set_client_id(self, client_id:str):
self._client_id = client_id