- 新增 user.getAccountInfo:仅查询当前登录账号的 wms_account 信息 - 白名单返回 id/username/real_name/phone/email/status/last_login_at/created_at/updated_at,排除 password_hash、salt、last_login_ip - 未登录返回 401,账号不存在返回 404;不接收账号ID,避免越权查询 - 同步 methods/system.json(0.3.304 → 0.3.305)、变更记录、AI_METHOD_ROUTING 与方法文档库表 - 新增单测 test/app/service/systemMethods/user.getAccountInfo.test.js(5 通过) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
97 lines
3.3 KiB
JavaScript
97 lines
3.3 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,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 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;
|