From 8cc7ea45f9014c5f4d277ba72c6be30edaa31c54 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 11 Aug 2026 17:56:14 +0800 Subject: [PATCH] fix: login.dspy use injected vars, avoid import errors --- wwwroot/pccs/api/login.dspy | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 wwwroot/pccs/api/login.dspy diff --git a/wwwroot/pccs/api/login.dspy b/wwwroot/pccs/api/login.dspy new file mode 100644 index 0000000..a4260ac --- /dev/null +++ b/wwwroot/pccs/api/login.dspy @@ -0,0 +1,31 @@ +# pccs login — 使用 dspy 注入变量 +import hashlib as _hl, datetime as _dt + +username = params_kw.get('username', '') +password = params_kw.get('password', '') or params_kw.get('passwd', '') + +if not username or not password: + return {'status': 'error', 'message': '请输入用户名和密码'} + +db = DBPools() +async with db.sqlorContext('pccs') as sor: + recs = await sor.R('users', {'username': username}) + if not recs: + return {'status': 'error', 'message': '用户名或密码错误'} + + user = recs[0] + pw_hash = _hl.sha256(password.encode()).hexdigest() + stored_pw = user.password or '' + + if pw_hash != stored_pw: + return {'status': 'error', 'message': '用户名或密码错误'} + + now = _dt.datetime.now().isoformat() + await sor.U('users', {'id': user.id}, {'last_login': now, 'login_fail_count': 0}) + + return { + 'status': 'ok', + 'message': '登录成功', + 'user': {'id': user.id, 'username': user.username, + 'nick_name': user.nick_name or user.username} + }