2019-10-23 10:45:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Admin;
|
|
|
|
|
2019-11-29 20:28:34 +00:00
|
|
|
use App\Console\Commands\Traits\AskForPassword;
|
2019-10-23 10:45:57 +00:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Contracts\Hashing\Hasher as Hash;
|
|
|
|
|
|
|
|
class ChangePasswordCommand extends Command
|
|
|
|
{
|
2019-11-29 20:28:34 +00:00
|
|
|
use AskForPassword;
|
|
|
|
|
2019-10-23 10:45:57 +00:00
|
|
|
protected $name = 'koel:admin:change-password';
|
|
|
|
protected $description = "Change the default admin's password";
|
|
|
|
|
|
|
|
private $hash;
|
|
|
|
|
|
|
|
public function __construct(Hash $hash)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->hash = $hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle(): void
|
|
|
|
{
|
2019-10-23 13:51:37 +00:00
|
|
|
/** @var User|null $user */
|
2019-10-23 10:45:57 +00:00
|
|
|
$user = User::where('is_admin', true)->first();
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
$this->error('An admin account cannot be found. Have you set up Koel yet?');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->comment("Changing the default admin's password (ID: {$user->id}, email: {$user->email})");
|
|
|
|
|
2019-11-29 20:28:34 +00:00
|
|
|
$user->password = $this->hash->make($this->askForPassword());
|
2019-10-23 10:45:57 +00:00
|
|
|
$user->save();
|
|
|
|
|
2019-11-29 20:28:34 +00:00
|
|
|
$this->comment('Alrighty, your new password has been saved. Enjoy! 👌');
|
2019-10-23 10:45:57 +00:00
|
|
|
}
|
|
|
|
}
|