Skip to content

Commit

Permalink
feat: add PwUser and PwPass
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Apr 16, 2023
1 parent 66229d4 commit 4d0c53a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
39 changes: 39 additions & 0 deletions App/Commands/PwPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace RockShell;

use ProcessWire\WireRandom;
use Symfony\Component\Console\Input\InputOption;

class PwPass extends Command
{

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

public function handle()
{
if (!$user = $this->option('user')) {
$users = [];
foreach ($this->wire()->users as $u) $users[] = $u->name;
$user = $this->choice("Select user", $users);
}

$rand = new WireRandom();
$pass = $rand->alphanumeric(0, [
'maxLength' => 20,
'minLength' => 12,
]);
$pass = $this->ask("Enter Password", $pass);

$user = $this->wire()->users->get("name=$user");
$user->setAndSave('pass', $pass);

$this->success("Password set for user " . $user->name . ".");
return self::SUCCESS;
}
}
21 changes: 21 additions & 0 deletions App/Commands/PwUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace RockShell;

class PwUsers extends Command
{

public function config()
{
$this
->setDescription("List all users");
}

public function handle()
{
foreach ($this->wire()->users as $u) {
$this->write("{$u->name} ($u)");
}
return self::SUCCESS;
}
}

0 comments on commit 4d0c53a

Please sign in to comment.