From e29bac10332ce125b68e88aedd299754462e141d Mon Sep 17 00:00:00 2001 From: xiaomlove <353856593@qq.com> Date: Sat, 8 May 2021 18:27:35 +0800 Subject: [PATCH] add command user:reset_password --- app/Console/Commands/UserResetPassword.php | 54 ++++++++++++++++++++++ app/Repositories/UserRepository.php | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/UserResetPassword.php diff --git a/app/Console/Commands/UserResetPassword.php b/app/Console/Commands/UserResetPassword.php new file mode 100644 index 00000000..ee85ab8f --- /dev/null +++ b/app/Console/Commands/UserResetPassword.php @@ -0,0 +1,54 @@ +argument('username'); + $password = $this->argument('password'); + $passwordConfirmation = $this->argument('password_confirmation'); + $log = "username: $username, password: $password, passwordConfirmation: $passwordConfirmation"; + $this->info($log); + do_log($log); + + $rep = new UserRepository(); + $result = $rep->resetPassword($username, $password, $passwordConfirmation); + $log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true)); + $this->info($log); + do_log($log); + } +} diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 931ba16b..560ef52a 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -73,7 +73,7 @@ class UserRepository extends BaseRepository if ($password != $passwordConfirmation) { throw new \InvalidArgumentException("password confirmation != password"); } - $user = User::query()->where('username', $username)->firstOrFail(); + $user = User::query()->where('username', $username)->firstOrFail(['id', 'username']); $secret = mksecret(); $passhash = md5($secret . $password . $secret); $update = [