diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/actions/auth.ts b/packages/plugins/@nocobase/plugin-auth/src/server/actions/auth.ts index 6957b06bf6..a3962ecbc6 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/actions/auth.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/actions/auth.ts @@ -49,7 +49,8 @@ export default { } else { key = 'email'; } - const user = await ctx.db.getRepository('users').findOne({ + const UserRepo = ctx.db.getRepository('users'); + const user = await UserRepo.findOne({ where: { [key]: currentUser[key], }, @@ -59,8 +60,12 @@ export default { if (!isValid) { ctx.throw(401, ctx.t('The password is incorrect, please re-enter', { ns: namespace })); } - user.password = newPassword; - await user.save(); + await UserRepo.update({ + filterByTk: user.id, + values: { + password: newPassword, + }, + }); ctx.body = currentUser; await next(); }, diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts index ac31803958..f0e129584f 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts @@ -28,7 +28,7 @@ describe('workflow > triggers > collection', () => { beforeEach(async () => { app = await getApp({ - plugins: ['error-handler', 'data-source-main', 'users', 'auth'], + plugins: ['error-handler', 'data-source-main', 'users', 'auth', 'system-settings'], }); db = app.db; @@ -316,6 +316,32 @@ describe('workflow > triggers > collection', () => { const executions = await workflow.getExecutions(); expect(executions.length).toBe(0); }); + + it('password changed in users', async () => { + const workflow = await WorkflowModel.create({ + enabled: true, + sync: true, + type: 'collection', + config: { + mode: 2, + collection: 'users', + changed: ['passwordChangeTz'], + }, + }); + + const res = await (await app.agent().login(1)).resource('auth').changePassword({ + values: { + oldPassword: 'admin123', + newPassword: 'abc123', + confirmPassword: 'abc123', + }, + }); + + expect(res.status).toBe(200); + + const executions = await workflow.getExecutions(); + expect(executions.length).toBe(1); + }); }); describe('config.condition', () => {