Skip to content

Commit

Permalink
add regenerate password
Browse files Browse the repository at this point in the history
  • Loading branch information
shellrean committed May 24, 2024
1 parent ca1409b commit 8c82ee7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/Http/Controllers/Api/v1/PesertaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,27 @@ public function unblock(Request $request)
DB::table("siswa_ujians")->whereIn("peserta_id", $pesertas)->update(['out_ujian_counter' => 0]);
return SendResponse::accept();
}

/**
* @route(path="api/v1/pesertas/regenerate-password", methods={"POST"})
*
* @return \Illuminate\Http\Response
*/
public function regeneratePassword(Request $request)
{
$request->validate([
'peserta_id' => 'required|array'
]);

$pesertaIds = $request->get('peserta_id');
$pesertas = DB::table('pesertas')->whereIn('id', $pesertaIds)->get();

foreach($pesertas as $peserta) {
DB::table('pesertas')->where('id', $peserta->id)->update([
'password' => strtoupper(\Illuminate\Support\Str::random(6))
]);
}

return SendResponse::accept();
}
}
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
Route::post('pesertas/delete-multiple', 'PesertaController@destroyMultiple');
Route::get('pesertas/status-blocked', 'PesertaController@blocked');
Route::delete('pesertas/unblock', 'PesertaController@unblock');
Route::post('pesertas/regenerate-password', 'PesertaController@regeneratePassword');
Route::apiResource('pesertas', 'PesertaController');

Route::get('matpels/all', 'MatpelController@allData');
Expand Down

0 comments on commit 8c82ee7

Please sign in to comment.