pccs/wwwroot/api/a1b2c3d4e5.dspy

16 lines
927 B
Plaintext

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': '请输入用户名和密码'}
pw_encoded = password_encode(password)
db = DBPools()
async with db.sqlorContext('pccs') as sor:
recs = await sor.sqlExe("SELECT id,username,password,nick_name FROM users WHERE username=${un}$", {'un': username})
if not recs:
return {'status': 'error', 'message': '用户名或密码错误'}
user = recs[0]
if pw_encoded != (user.password or ''):
return {'status': 'error', 'message': '用户名或密码错误'}
await sor.sqlExe("UPDATE users SET last_login=NOW(),login_fail_count=0 WHERE id=${id}$", {'id': user.id})
return {'status': 'ok', 'message': '登录成功', 'user': {'id': user.id, 'username': user.username, 'nick_name': user.nick_name or user.username}}