This commit is contained in:
1 parent
42e2fbcdb5
commit
a603566235
4 files changed
+61
-13
No files matched your search
@@ -8,10 +8,17 @@ from loon.web.users.models import User
|
||||
|
||||
|
||||
async def change_password_handler(client, userdata, msg, data):
|
||||
if msg.topic != "loon/register/change_password":
|
||||
prefix = "loon/auth/register/"
|
||||
|
||||
if not msg.topic.startswith(prefix):
|
||||
return
|
||||
|
||||
rest = msg.topic[len(prefix):]
|
||||
uuid, _, subtopic = rest.partition("/")
|
||||
|
||||
if not uuid or subtopic != "change_password":
|
||||
return
|
||||
|
||||
uuid = data["uuid"]
|
||||
password = data["password"]
|
||||
|
||||
with Session(engine) as session:
|
||||
@@ -19,7 +26,7 @@ async def change_password_handler(client, userdata, msg, data):
|
||||
user = session.exec(statement).first()
|
||||
|
||||
if user is None:
|
||||
client.publish(f"loon/register/{uuid}/response",
|
||||
client.publish(f"loon/auth/register/{uuid}/response",
|
||||
json.dumps({"success": False, "error": "The user is not registered!"}))
|
||||
return
|
||||
|
||||
@@ -32,9 +39,9 @@ async def change_password_handler(client, userdata, msg, data):
|
||||
session.commit()
|
||||
except IntegrityError:
|
||||
session.rollback()
|
||||
client.publish(f"loon/register/{uuid}/response",
|
||||
client.publish(f"loon/auth/register/{uuid}/response",
|
||||
json.dumps({"success": False, "error": "The user is not registered!"}))
|
||||
|
||||
return
|
||||
|
||||
client.publish(f"loon/register/{uuid}/response", json.dumps({"success": True, "error": None}))
|
||||
client.publish(f"loon/auth/register/{uuid}/response", json.dumps({"success": True, "error": None}))
|
||||
@@ -8,10 +8,17 @@ from loon.web.users.models import User
|
||||
|
||||
|
||||
async def register_request_handler(client, userdata, msg, data):
|
||||
if msg.topic != "loon/register/request":
|
||||
prefix = "loon/auth/register/"
|
||||
|
||||
if not msg.topic.startswith(prefix):
|
||||
return
|
||||
|
||||
rest = msg.topic[len(prefix):]
|
||||
uuid, _, subtopic = rest.partition("/")
|
||||
|
||||
if not uuid or subtopic != "request":
|
||||
return
|
||||
|
||||
uuid = data["uuid"]
|
||||
password = data["password"]
|
||||
internal_username = data["internalUsername"]
|
||||
|
||||
@@ -20,7 +27,7 @@ async def register_request_handler(client, userdata, msg, data):
|
||||
user = session.exec(statement).first()
|
||||
|
||||
if user is not None:
|
||||
client.publish(f"loon/register/{uuid}/response",
|
||||
client.publish(f"loon/auth/register/{uuid}/response",
|
||||
json.dumps({"success": False, "error": "The user is already registered!"}))
|
||||
return
|
||||
|
||||
@@ -28,7 +35,7 @@ async def register_request_handler(client, userdata, msg, data):
|
||||
user = session.exec(statement).first()
|
||||
|
||||
if user is not None:
|
||||
client.publish(f"loon/register/{uuid}/response",
|
||||
client.publish(f"loon/auth/register/{uuid}/response",
|
||||
json.dumps({"success": False, "error": f"The {internal_username} is taken!"}))
|
||||
return
|
||||
|
||||
@@ -38,9 +45,9 @@ async def register_request_handler(client, userdata, msg, data):
|
||||
session.commit()
|
||||
except IntegrityError:
|
||||
session.rollback()
|
||||
client.publish(f"loon/register/{uuid}/response",
|
||||
client.publish(f"loon/auth/register/{uuid}/response",
|
||||
json.dumps({"success": False, "error": "The user is already registered!"}))
|
||||
|
||||
return
|
||||
|
||||
client.publish(f"loon/register/{uuid}/response", json.dumps({"success": True, "error": None}))
|
||||
client.publish(f"loon/auth/register/{uuid}/response", json.dumps({"success": True, "error": None}))
|
||||
@@ -0,0 +1,32 @@
|
||||
import json
|
||||
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from loon.web.db import engine
|
||||
from loon.web.users.models import User
|
||||
|
||||
|
||||
async def show_username_handler(client, userdata, msg, data):
|
||||
prefix = "loon/auth/show_username/"
|
||||
|
||||
if not msg.topic.startswith(prefix):
|
||||
return
|
||||
|
||||
rest = msg.topic[len(prefix):]
|
||||
uuid, _, subtopic = rest.partition("/")
|
||||
|
||||
if not uuid or subtopic:
|
||||
return
|
||||
|
||||
with Session(engine) as session:
|
||||
user = session.exec(select(User).where(User.uuid == uuid)).first()
|
||||
|
||||
if user is None:
|
||||
client.publish(f"loon/auth/show_username/{uuid}/response",
|
||||
json.dumps({"success": False, "error": "The user is not registered!"}))
|
||||
return
|
||||
|
||||
internal_username = user.internal_username
|
||||
|
||||
client.publish(f"loon/auth/show_username/{uuid}/response",
|
||||
json.dumps({"success": True, "error": None, "internalUsername": internal_username}))
|
||||
Reference in new issue
Block a user