resetPassword.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\command;
  13. use app\common\repositories\system\admin\AdminRepository;
  14. use think\console\Command;
  15. use think\console\Input;
  16. use think\console\input\Argument;
  17. use think\console\Output;
  18. use think\console\input\Option;
  19. class resetPassword extends Command
  20. {
  21. protected function configure()
  22. {
  23. // 指令配置
  24. $this->setName('reset:password')
  25. ->addArgument('root', Argument::OPTIONAL, 'root : admin')
  26. ->addOption('pwd', null, Option::VALUE_REQUIRED, 'pwd : 123456')
  27. ->setDescription('php think reset:password admin --pwd 123456');
  28. }
  29. /**
  30. * 重置管理员密码
  31. * @Author:Qinii
  32. * @Date: 2020/5/15
  33. * @param Input $input
  34. * @param Output $output
  35. * @return int|void|null
  36. */
  37. protected function execute(Input $input, Output $output)
  38. {
  39. $account = $input->getArgument('root');
  40. if ($input->hasOption('pwd')){
  41. $pwd = $input->getOption('pwd');
  42. }
  43. $make = app()->make(AdminRepository::class);
  44. $accountData = $make->accountByAdmin($account);
  45. if(!$accountData) {
  46. $output->warning('管理员账号不存在');
  47. }else{
  48. $pwd_ = $make->passwordEncode($pwd);
  49. $accountData->pwd = $pwd_;
  50. $accountData->save();
  51. $output->info('账号:'.$account.';密码已重置:'.$pwd);
  52. }
  53. }
  54. }