ResetPassword.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Plan;
  4. use App\Utils\Helper;
  5. use Illuminate\Console\Command;
  6. use App\Models\User;
  7. use Illuminate\Support\Facades\DB;
  8. class ResetPassword extends Command
  9. {
  10. protected $builder;
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'reset:password {email}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '重置用户密码';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. $user = User::where('email', $this->argument('email'))->first();
  40. if (!$user) abort(500, '邮箱不存在');
  41. $password = Helper::guid(false);
  42. $user->password = password_hash($password, PASSWORD_DEFAULT);
  43. $user->password_algo = null;
  44. if (!$user->save()) abort(500, '重置失败');
  45. $this->info("!!!重置成功!!!");
  46. $this->info("新密码为:{$password},请尽快修改密码。");
  47. }
  48. }