resetPassword.php 2.6 KB

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