Skip to content

Commit

Permalink
feat: add user rename commands
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed May 23, 2023
1 parent 57859f5 commit 6babc7e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion App/Commands/PwUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function config()
public function handle()
{
foreach ($this->wire()->users as $u) {
$this->write("{$u->name} ($u)");
$this->write(" {$u->name} [$u]");
}
return self::SUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions App/Commands/PwPass.php → App/Commands/UserPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use ProcessWire\WireRandom;
use Symfony\Component\Console\Input\InputOption;

class PwPass extends Command
class UserPass extends Command
{

public function config()
{
$this
->setDescription("Reset passwort of a user")
->setDescription("Reset password of a user")
->addOption("user", "u", InputOption::VALUE_OPTIONAL, "username");
}

Expand Down
40 changes: 40 additions & 0 deletions App/Commands/UserRename.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace RockShell;

use Symfony\Component\Console\Input\InputOption;

class UserRename extends Command
{

public function config()
{
$this
->setDescription("Rename a user")
->addOption("user", "u", InputOption::VALUE_OPTIONAL, "name of existing user")
->addOption("name", "r", InputOption::VALUE_OPTIONAL, "new username");
}

public function handle()
{
$users = [];
foreach ($this->wire()->users as $u) $users[] = $u->name;

if (!$user = $this->option('user')) {
$user = $this->choice("Select user", $users);
}

$name = $this->option('name');
$name = $this->wire()->sanitizer->pageName($name);
while (!$name or in_array($name, $users)) {
$name = $this->ask("Enter new username");
$name = $this->wire()->sanitizer->pageName($name);
}

$user = $this->wire()->users->get("name=$user");
$this->success("User {$user->name} renamed to $name");
$user->setAndSave('name', $name);

return self::SUCCESS;
}
}

0 comments on commit 6babc7e

Please sign in to comment.