Resetpassword.php 960 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command\auth;
  4. use app\service\admin\auth\LoginService;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. class Resetpassword extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('reset')
  15. ->addOption('password', 'p', Option::VALUE_OPTIONAL, 'please enter the password you will set.')
  16. ->setDescription('the reset administrator password command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. if ($input->hasOption('password')) {
  21. $password = $input->getOption('password');
  22. $password = $password ?: '123456';
  23. } else {
  24. $password = '123456';
  25. }
  26. LoginService::resetAdministratorPassword($password);
  27. // 指令输出
  28. $output->writeln('password reset success');
  29. }
  30. }