fix: login.dspy use injected vars, avoid import errors
This commit is contained in:
parent
79d91d4ffd
commit
8cc7ea45f9
31
wwwroot/pccs/api/login.dspy
Normal file
31
wwwroot/pccs/api/login.dspy
Normal file
@ -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}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user