mirror of
https://github.com/tgbot-collection/YYeTsBot.git
synced 2025-11-25 19:37:34 +08:00
未注册账号不会自动注册
This commit is contained in:
@@ -738,42 +738,21 @@ class UserMongoResource(UserResource, Mongo):
|
|||||||
else:
|
else:
|
||||||
return {"status_code": HTTPStatus.FORBIDDEN, "message": "验证码错误", "status": False}
|
return {"status_code": HTTPStatus.FORBIDDEN, "message": "验证码错误", "status": False}
|
||||||
# check user account is locked.
|
# check user account is locked.
|
||||||
|
user = self.db["users"].find_one({"username": username}) or {}
|
||||||
data = self.db["users"].find_one({"username": username}) or {}
|
if user.get("status", {}).get("disable"):
|
||||||
if data.get("status", {}).get("disable"):
|
|
||||||
return {"status_code": HTTPStatus.FORBIDDEN,
|
return {"status_code": HTTPStatus.FORBIDDEN,
|
||||||
"status": False,
|
"status": False,
|
||||||
"message": data.get("status", {}).get("reason")}
|
"message": user.get("status", {}).get("reason")
|
||||||
|
}
|
||||||
returned_value = {"status_code": 0, "message": ""}
|
|
||||||
|
|
||||||
if data:
|
|
||||||
# try to login
|
|
||||||
stored_password = data["password"]
|
|
||||||
if pbkdf2_sha256.verify(password, stored_password):
|
|
||||||
returned_value["status_code"] = HTTPStatus.OK
|
|
||||||
else:
|
|
||||||
returned_value["status_code"] = HTTPStatus.FORBIDDEN
|
|
||||||
returned_value["message"] = "用户名或密码错误"
|
|
||||||
|
|
||||||
|
returned_value = {}
|
||||||
|
if user and pbkdf2_sha256.verify(password, user["password"]):
|
||||||
|
returned_value["status_code"] = HTTPStatus.OK
|
||||||
|
returned_value["username"] = user.get("username")
|
||||||
|
returned_value["group"] = user.get("group", ["user"])
|
||||||
else:
|
else:
|
||||||
if os.getenv("DISABLE_REGISTER"):
|
returned_value = {"status_code": HTTPStatus.FORBIDDEN, "message": "用户名或密码错误"}
|
||||||
return {"status_code": HTTPStatus.BAD_REQUEST, "message": "本站已经暂停注册"}
|
|
||||||
|
|
||||||
# register
|
|
||||||
hash_value = pbkdf2_sha256.hash(password)
|
|
||||||
try:
|
|
||||||
self.db["users"].insert_one(dict(username=username, password=hash_value,
|
|
||||||
date=ts_date(), ip=ip, browser=browser)
|
|
||||||
)
|
|
||||||
returned_value["status_code"] = HTTPStatus.CREATED
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
returned_value["status_code"] = HTTPStatus.INTERNAL_SERVER_ERROR
|
|
||||||
returned_value["message"] = str(e)
|
|
||||||
|
|
||||||
returned_value["username"] = data.get("username")
|
|
||||||
returned_value["group"] = data.get("group", ["user"])
|
|
||||||
return returned_value
|
return returned_value
|
||||||
|
|
||||||
def get_user_info(self, username: str) -> dict:
|
def get_user_info(self, username: str) -> dict:
|
||||||
|
|||||||
Reference in New Issue
Block a user