This commit is contained in:
1 parent
c75526aa2e
commit
f34bb39d31
3 files changed
+13
-4
No files matched your search
@@ -1,8 +1,8 @@
|
|||||||
"""Users
|
"""Users
|
||||||
|
|
||||||
Revision ID: 493f3f7529f3
|
Revision ID: 2df7e2c6af43
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2026-08-16 11:22:34.176552
|
Create Date: 2026-08-17 12:42:05.103510
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
@@ -13,7 +13,7 @@ import sqlalchemy as sa
|
|||||||
import sqlmodel
|
import sqlmodel
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision: str = '493f3f7529f3'
|
revision: str = '2df7e2c6af43'
|
||||||
down_revision: Union[str, Sequence[str], None] = None
|
down_revision: Union[str, Sequence[str], None] = None
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
@@ -29,6 +29,7 @@ def upgrade() -> None:
|
|||||||
sa.Column('password', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
sa.Column('password', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
||||||
sa.Column('admin', sa.Boolean(), nullable=False),
|
sa.Column('admin', sa.Boolean(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('internal_username'),
|
||||||
sa.UniqueConstraint('uuid')
|
sa.UniqueConstraint('uuid')
|
||||||
)
|
)
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
@@ -25,6 +25,14 @@ async def register_request_handler(client, userdata, msg, data):
|
|||||||
json.dumps({"success": False, "error": "The user is already registered!"}))
|
json.dumps({"success": False, "error": "The user is already registered!"}))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
statement = select(User).where(User.internal_username == internal_username)
|
||||||
|
user = session.exec(statement).first()
|
||||||
|
|
||||||
|
if user is not None:
|
||||||
|
client.publish(f"loon/register/{uuid}/response",
|
||||||
|
json.dumps({"success": False, "error": f"The {internal_username} is taken!"}))
|
||||||
|
return
|
||||||
|
|
||||||
user = User(uuid=uuid, password=hash_password(password), internal_username=internal_username, admin=False)
|
user = User(uuid=uuid, password=hash_password(password), internal_username=internal_username, admin=False)
|
||||||
session.add(user)
|
session.add(user)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ from sqlmodel import SQLModel, Field
|
|||||||
class User(SQLModel, table=True):
|
class User(SQLModel, table=True):
|
||||||
id: int = Field(default=None, primary_key=True)
|
id: int = Field(default=None, primary_key=True)
|
||||||
uuid: str = Field(unique=True)
|
uuid: str = Field(unique=True)
|
||||||
internal_username: str
|
internal_username: str = Field(unique=True)
|
||||||
password: str
|
password: str
|
||||||
admin: bool = Field(default=False)
|
admin: bool = Field(default=False)
|
||||||
Reference in new issue
Block a user