Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Time fields’ “Max Time” settings can now be set to an earlier time than “Min Time”, for overnight time ranges. ([#18575](https://github.com/craftcms/cms/pull/18575))
- Newlines in system message bodies are now replaced with `<br>` tags. ([#18058](https://github.com/craftcms/cms/discussions/18058))
- Added the `--to-default` option to `resave` commands. ([#18522](https://github.com/craftcms/cms/pull/18522))
- Added the `--method` option to the `users/remove-2fa` command. ([#18732](https://github.com/craftcms/cms/pull/18732))

### Development
- Added the `heading()`/`h()` and `h1()`…`h6()` Twig functions. ([#18524](https://github.com/craftcms/cms/pull/18524))
Expand Down
32 changes: 25 additions & 7 deletions src/console/controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class UsersController extends Controller
*/
public bool $hard = false;

/**
* @var string|null The name of the two-step verification method you would like to remove for user, e.g. Authenticator App, Recovery Codes. Use "all" to remove all 2FA methods.
* @since 5.9.21
*/
public ?string $method = null;

/**
* @inheritdoc
*/
Expand All @@ -122,6 +128,9 @@ public function options($actionID): array
case 'set-password':
$options[] = 'password';
break;
case 'remove-2fa':
$options[] = 'method';
break;
}

return $options;
Expand Down Expand Up @@ -549,13 +558,22 @@ public function remove2fa(string $user): int
return ExitCode::OK;
}

$methodToRemove = $this->select(
"Which two-step verification method would you like to remove for user “{$user->username}”",
[
'all' => 'all',
...array_combine(array_keys($activeMethods), array_keys($activeMethods)),
],
);
// if method was provided, check if it's in the active methods; if so - use it
if ($this->method) {
if ($this->method !== 'all' && !isset($activeMethods[$this->method])) {
$this->stdout("User “{$user->username}” doesn’t have the “{$this->method}” two-step verification method." . PHP_EOL);
return ExitCode::OK;
}
$methodToRemove = $this->method;
} else {
$methodToRemove = $this->select(
"Which two-step verification method would you like to remove for user “{$user->username}”",
[
'all' => 'all',
...array_combine(array_keys($activeMethods), array_keys($activeMethods)),
],
);
}

if ($methodToRemove === 'all') {
$this->stdout('Removing all two-step verification methods for the user ...' . PHP_EOL);
Expand Down
Loading