56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\UserDosen;
|
|
use App\Models\UserStaff;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class ResetUserPassword extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'app:reset-password {nip} {password} {--type=dosen}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Reset password for a specific user by NIP';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$nip = $this->argument('nip');
|
|
$password = $this->argument('password');
|
|
$type = $this->option('type');
|
|
|
|
if ($type === 'dosen') {
|
|
$user = UserDosen::where('nip', $nip)->first();
|
|
$modelName = 'Dosen';
|
|
} else {
|
|
$user = UserStaff::where('nip', $nip)->first();
|
|
$modelName = 'Staff';
|
|
}
|
|
|
|
if (!$user) {
|
|
$this->error("User {$modelName} dengan NIP {$nip} tidak ditemukan");
|
|
return 1;
|
|
}
|
|
|
|
$user->update(['password' => Hash::make($password)]);
|
|
|
|
$this->info("✓ Password untuk {$user->nama} (NIP: {$nip}) berhasil di-reset");
|
|
$this->info(" Gunakan password baru: {$password}");
|
|
|
|
return 0;
|
|
}
|
|
}
|