mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 08:33:53 +08:00
update:为安全考虑,绑定设备功能未处理之前,只限制一个账号注册
This commit is contained in:
+21
-20
@@ -1,26 +1,27 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en" style="height: 100%;">
|
<html lang="en" style="height: 100%;">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8"/>
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" href="/favicon.ico"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<title>智控台</title>
|
<title>智控台</title>
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
#app {
|
|
||||||
height: 100%;
|
#app {
|
||||||
width: 100%;
|
height: 100%;
|
||||||
}
|
width: 100%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script type="module" src="/src/main.js"></script>
|
<script type="module" src="/src/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
+2
-2
@@ -105,7 +105,7 @@ def check_password(password):
|
|||||||
:return: 如果密码满足条件,则返回True;否则返回False。
|
:return: 如果密码满足条件,则返回True;否则返回False。
|
||||||
"""
|
"""
|
||||||
# 检查密码长度
|
# 检查密码长度
|
||||||
if len(password) < 10:
|
if len(password) < 8:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 检查是否包含英文字符和数字
|
# 检查是否包含英文字符和数字
|
||||||
@@ -116,7 +116,7 @@ def check_password(password):
|
|||||||
if "xiaozhi" in password:
|
if "xiaozhi" in password:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if "123456" in password:
|
if "1234" in password:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 如果满足所有条件,则返回True
|
# 如果满足所有条件,则返回True
|
||||||
|
|||||||
+20
-4
@@ -1,9 +1,11 @@
|
|||||||
import logging
|
import logging
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
import datetime
|
import datetime
|
||||||
|
from core.utils.util import check_password
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RegisterHandler:
|
class RegisterHandler:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
@@ -15,18 +17,32 @@ class RegisterHandler:
|
|||||||
username = data.get('username')
|
username = data.get('username')
|
||||||
password = data.get('password')
|
password = data.get('password')
|
||||||
|
|
||||||
|
if not check_password(password):
|
||||||
|
return web.json_response({
|
||||||
|
'success': False,
|
||||||
|
'message': '密码必须包含大小写字母、数字且长度至少8位'
|
||||||
|
})
|
||||||
|
|
||||||
if not username or not password:
|
if not username or not password:
|
||||||
logger.warning(f"Registration attempt with empty credentials from {request.remote}")
|
logger.warning(f"Registration attempt with empty credentials from {request.remote}")
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
'success': False,
|
'success': False,
|
||||||
'message': '用户名和密码不能为空'
|
'message': '用户名和密码不能为空'
|
||||||
})
|
})
|
||||||
|
|
||||||
users = self.config.get('users', {})
|
users = self.config.get('users', {})
|
||||||
|
# 由于现在所有用户都能看到所有设备,从安全角度上考虑,只允许注册一个用户
|
||||||
|
# 未来绑定设备功能完成后,再放开任意注册
|
||||||
|
if len(users) >= 1:
|
||||||
|
return web.json_response({
|
||||||
|
'success': False,
|
||||||
|
'message': '系统已经初始化过了,如果忘记了密码,请直接删除“.secrets.yaml”文件,删除后重启本服务'
|
||||||
|
})
|
||||||
|
|
||||||
if username in users:
|
if username in users:
|
||||||
logger.warning(f"Registration attempt with existing username {username} from {request.remote}")
|
logger.warning(f"Registration attempt with existing username {username} from {request.remote}")
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
'success': False,
|
'success': False,
|
||||||
'message': '用户名已存在'
|
'message': '用户名已存在'
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -39,13 +55,13 @@ class RegisterHandler:
|
|||||||
|
|
||||||
logger.info(f"Successfully registered new user {username} from {request.remote}")
|
logger.info(f"Successfully registered new user {username} from {request.remote}")
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
'success': True,
|
'success': True,
|
||||||
'message': '注册成功'
|
'message': '注册成功'
|
||||||
})
|
})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Registration error: {str(e)}", exc_info=True)
|
logger.error(f"Registration error: {str(e)}", exc_info=True)
|
||||||
return web.json_response({
|
return web.json_response({
|
||||||
'success': False,
|
'success': False,
|
||||||
'message': '注册失败,请稍后重试'
|
'message': '注册失败,请稍后重试'
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user