|
@@ -5,6 +5,7 @@ Organization model - represents a client company.
|
|
|
from sqlalchemy import Boolean, String
|
|
from sqlalchemy import Boolean, String
|
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
|
|
|
|
|
|
+from app.core.encryption import decrypt_password, encrypt_password
|
|
|
from app.models.base import Base
|
|
from app.models.base import Base
|
|
|
|
|
|
|
|
|
|
|
|
@@ -27,6 +28,12 @@ class Organization(Base):
|
|
|
wifi_enabled: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
wifi_enabled: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
|
ble_enabled: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
ble_enabled: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
|
|
|
|
|
|
|
|
+ # WiFi credentials (encrypted)
|
|
|
|
|
+ wifi_ssid: Mapped[str | None] = mapped_column(String(100))
|
|
|
|
|
+ _wifi_password_encrypted: Mapped[str | None] = mapped_column(
|
|
|
|
|
+ "wifi_password_encrypted", String(500)
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
# Status: pending, active, suspended, deleted
|
|
# Status: pending, active, suspended, deleted
|
|
|
status: Mapped[str] = mapped_column(
|
|
status: Mapped[str] = mapped_column(
|
|
|
String(20), default="pending", nullable=False
|
|
String(20), default="pending", nullable=False
|
|
@@ -43,5 +50,20 @@ class Organization(Base):
|
|
|
"Device", back_populates="organization"
|
|
"Device", back_populates="organization"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ @property
|
|
|
|
|
+ def wifi_password(self) -> str | None:
|
|
|
|
|
+ """Decrypt WiFi password for viewing by admin."""
|
|
|
|
|
+ if not self._wifi_password_encrypted:
|
|
|
|
|
+ return None
|
|
|
|
|
+ return decrypt_password(self._wifi_password_encrypted)
|
|
|
|
|
+
|
|
|
|
|
+ @wifi_password.setter
|
|
|
|
|
+ def wifi_password(self, plain_password: str | None) -> None:
|
|
|
|
|
+ """Encrypt WiFi password before storing."""
|
|
|
|
|
+ if plain_password is None:
|
|
|
|
|
+ self._wifi_password_encrypted = None
|
|
|
|
|
+ else:
|
|
|
|
|
+ self._wifi_password_encrypted = encrypt_password(plain_password)
|
|
|
|
|
+
|
|
|
def __repr__(self) -> str:
|
|
def __repr__(self) -> str:
|
|
|
return f"<Organization {self.id}: {self.name}>"
|
|
return f"<Organization {self.id}: {self.name}>"
|