mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
add command user:reset_password
This commit is contained in:
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Repositories\UserRepository;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class UserResetPassword extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'user:reset_password {username} {password} {password_confirmation}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Reset user password, arguments: username password password_comfirmation';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$username = $this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,7 +73,7 @@ class UserRepository extends BaseRepository
|
|||||||
if ($password != $passwordConfirmation) {
|
if ($password != $passwordConfirmation) {
|
||||||
throw new \InvalidArgumentException("password confirmation != password");
|
throw new \InvalidArgumentException("password confirmation != password");
|
||||||
}
|
}
|
||||||
$user = User::query()->where('username', $username)->firstOrFail();
|
$user = User::query()->where('username', $username)->firstOrFail(['id', 'username']);
|
||||||
$secret = mksecret();
|
$secret = mksecret();
|
||||||
$passhash = md5($secret . $password . $secret);
|
$passhash = md5($secret . $password . $secret);
|
||||||
$update = [
|
$update = [
|
||||||
|
|||||||
Reference in New Issue
Block a user