-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathreset.ts
More file actions
58 lines (44 loc) · 1.73 KB
/
reset.ts
File metadata and controls
58 lines (44 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import {Args} from '@oclif/core';
import {AmCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {t} from '../../../i18n/index.js';
/**
* Command to reset an Account Manager user password.
*/
export default class UserReset extends AmCommand<typeof UserReset> {
static args = {
login: Args.string({
description: 'User login (email)',
required: true,
}),
};
static description = t('commands.user.reset.description', 'Reset an Account Manager user password');
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %> user@example.com',
'<%= config.bin %> <%= command.id %> user@example.com --json',
];
async run(): Promise<void> {
// Prevent password reset in safe mode
this.assertDestructiveOperationAllowed('reset user password');
const {login} = this.args;
this.log(t('commands.user.reset.fetching', 'Fetching user {{login}}...', {login}));
const user = await this.accountManagerClient.findUserByLogin(login);
if (!user) {
this.error(t('commands.user.reset.notFound', 'User {{login}} not found', {login}));
}
if (!user.id) {
this.error(t('commands.user.reset.noId', 'User does not have an ID'));
}
this.log(t('commands.user.reset.resetting', 'Resetting password for user {{login}}...', {login}));
await this.accountManagerClient.resetUser(user.id);
if (this.jsonEnabled()) {
return;
}
this.log(t('commands.user.reset.success', 'Password reset for user {{login}} completed successfully.', {login}));
}
}