- wms_account 新增 is_custom_password(TINYINT(1) NOT NULL DEFAULT 0),同步模型与迁移 20261025135000;开发库、生产库均已执行 - user.getAccountInfo 返回 is_custom_password,仍不返回 password_hash/salt/last_login_ip - 新增 user.updateUsername:仅改当前账号,服务端重名校验并排除自己,重名返回 409,更新后清理用户缓存 - 新增 user.changePassword:is_custom_password=0 时旧密码可不传,修改后置 1;再次修改必须校验旧密码;已排除操作日志避免明文密码落库 - 单测覆盖 getAccountInfo/updateUsername/changePassword,20 通过;同步 AI_METHOD_ROUTING Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
115 lines
4.1 KiB
JavaScript
115 lines
4.1 KiB
JavaScript
'use strict';
|
||
|
||
const MainService = require('../main');
|
||
|
||
class userService extends MainService {
|
||
constructor(ctx) {
|
||
super(ctx);
|
||
const _noNeedLogin = 'login,loginByCode,register,getLoginWechatCode';
|
||
const _noNeedRight = '*';
|
||
const _noNeedLog = 'info,getAccountInfo,changePassword,getBindWechatCode,getLoginWechatCode';
|
||
const _noNeedAuth = '*';
|
||
// info:微信登录态中间层(_noNeedBind),未绑定真实用户也可访问
|
||
const _noNeedBind = 'info';
|
||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth, _noNeedBind);
|
||
}
|
||
async login(data) {
|
||
const { service } = this;
|
||
const { username, password } = data;
|
||
const result = await service.systems.auth.user.login(username, password);
|
||
if (result.code) {
|
||
return this.success('登录成功', result);
|
||
}
|
||
return this.fail('登录失败:' + result.message, result);
|
||
|
||
}
|
||
async loginByCode(data) {
|
||
const { service } = this;
|
||
const code = typeof data?.code === 'string' ? data.code.trim() : '';
|
||
if (!code) {
|
||
return this.fail('1111登录失败:缺少登录码 code', {
|
||
success: false,
|
||
data: null,
|
||
code: 0,
|
||
message: '缺少登录码 code',
|
||
});
|
||
}
|
||
const result = await service.systems.auth.user.loginByYe4sCode(code);
|
||
if (result.code) {
|
||
return this.success('登录成功', result);
|
||
}
|
||
return this.fail('登录失败:' + result.message, result);
|
||
}
|
||
async getBindWechatCode(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.getBindWechatCode(data);
|
||
if (result.code) {
|
||
return this.success('获取绑定微信码成功', result);
|
||
}
|
||
return this.fail('获取绑定微信码失败:' + result.message, result);
|
||
}
|
||
async getLoginWechatCode(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.getLoginWechatCode(data);
|
||
if (result.code) {
|
||
return this.success('获取微信登录码成功', result);
|
||
}
|
||
return this.fail('获取微信登录码失败:' + result.message, result);
|
||
}
|
||
async unbindWechat(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.unbindWechat(data);
|
||
if (result.code) {
|
||
return this.success('解绑成功', result);
|
||
}
|
||
return this.fail('解绑失败:' + result.message, result);
|
||
}
|
||
async logout() {
|
||
return this.success('登出成功');
|
||
}
|
||
async info(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.info(data);
|
||
return this.success('获取成功' + JSON.stringify(data), result);
|
||
}
|
||
// 获取当前登录账号的账号级信息(仅 wms_account,不含敏感字段)
|
||
async getAccountInfo(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.getAccountInfo(data);
|
||
if (result.code === 200) {
|
||
return this.success(result.message || '获取账号信息成功', result);
|
||
}
|
||
return this.fail(result.message || '获取账号信息失败', result);
|
||
}
|
||
// 修改当前账号用户名(服务端校验重名,排除自己)
|
||
async updateUsername(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.updateUsername(data);
|
||
if (result.code === 200) {
|
||
return this.success(result.message || '用户名修改成功', result);
|
||
}
|
||
return this.fail(result.message || '用户名修改失败', result);
|
||
}
|
||
// 修改当前账号密码(首次自定义密码可不传旧密码)
|
||
async changePassword(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.changePassword(data);
|
||
if (result.code === 200) {
|
||
return this.success(result.message || '密码修改成功', result);
|
||
}
|
||
return this.fail(result.message || '密码修改失败', result);
|
||
}
|
||
async changeRole(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.changeRole(data);
|
||
return this.success('获取成功', result, 200);
|
||
}
|
||
// 注册
|
||
async register(data) {
|
||
const { service } = this;
|
||
const result = await service.systems.auth.user.register(data);
|
||
return this.success(result);
|
||
}
|
||
}
|
||
module.exports = userService;
|