Skip to content

Commit

Permalink
Add password option to make:user command
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuablum committed Oct 24, 2024
1 parent 58b912f commit 5740d06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Console/Commands/MakeUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class MakeUser extends Command
*/
protected $email;

/**
* The user's password.
* @var string
*/
protected $password;

/**
* The user's data.
*
Expand Down Expand Up @@ -172,6 +178,7 @@ protected function createUser()

$user = User::make()
->email($this->email)
->password($this->option('password'))
->data($this->data);

if ($this->super || $this->option('super')) {
Expand Down Expand Up @@ -241,6 +248,7 @@ protected function getOptions()
{
return array_merge(parent::getOptions(), [
['super', '', InputOption::VALUE_NONE, 'Generate a super user with permission to do everything'],
['password', '', InputOption::VALUE_OPTIONAL, 'Generate a user with given password'],
]);
}
}
17 changes: 17 additions & 0 deletions tests/Console/Commands/MakeUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,21 @@ public function it_generates_with_and_without_super_option()
$this->assertTrue($jason->isSuper());
$this->assertFalse($girl->isSuper());
}

#[Test]
public function it_can_make_a_user_with_password_option()
{
$this->withoutMockingConsoleOutput();

$this->assertEmpty(User::all());

$this->artisan('statamic:make:user', ['email' => '[email protected]', '--password' => 'PacManMoonwalk#84'])
->expectsOutputToContain('User created successfully.');

$user = User::all()->first();

$this->assertNotEmpty($user->id());
$this->assertEquals('[email protected]', $user->email());
$this->assertNotEmpty($user->password());
}
}

0 comments on commit 5740d06

Please sign in to comment.