diff --git a/.env b/.env index 5f90d43..bade3bf 100644 --- a/.env +++ b/.env @@ -36,7 +36,14 @@ MAIL_PASSWORD=aggrshtusbqwjbhl MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=menghafalitumudahofficial@gmail.com MAIL_FROM_NAME="${APP_NAME}" - +# MAIL_MAILER=smtp +# MAIL_HOST=sandbox.smtp.mailtrap.io +# MAIL_PORT=2525 +# MAIL_USERNAME=35b7f2172f90cb +# MAIL_PASSWORD=169fb4552c3aea +# MAIL_ENCRYPTION=tls +# MAIL_FROM_ADDRESS="hello@example.com" +# MAIL_FROM_NAME="${APP_NAME}" AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= diff --git a/app/Http/Controllers/API/BacaanSholatController.php b/app/Http/Controllers/API/BacaanSholatController.php new file mode 100644 index 0000000..ec8b207 --- /dev/null +++ b/app/Http/Controllers/API/BacaanSholatController.php @@ -0,0 +1,50 @@ +all(), [ + 'arab' => 'required', + 'latin' => 'required', + 'terjemahan' => 'required', + 'voice_arab' => 'required', + 'voice_terjemahan' => 'required', + ]); + + if($validator->fails()){ + response()->json([ + 'Error' => true, + 'Massage' => $validator->errors() + ]); + } + + $bacaan = BacaanSholat::create([ + 'arab' => $request->arab, + 'latin' => $request->latin, + 'terjemahan' => $request->terjemahan, + 'voice_arab' => $request->voice_arab, + 'voice_terjemahan' => $request->voice_terjemahan, + ]); + + response()->json([ + 'Error' => true, + 'Massage' => $bacaan + ]); + + } + + public function showBacaan(){ + $bacaan = BacaanSholat::all(); + + return response()->json([ + 'Massage' => $bacaan + ]); + } +} diff --git a/app/Http/Controllers/Konten/AmalYaumiController.php b/app/Http/Controllers/Konten/AmalYaumiController.php index fd17f0b..78731ad 100644 --- a/app/Http/Controllers/Konten/AmalYaumiController.php +++ b/app/Http/Controllers/Konten/AmalYaumiController.php @@ -37,7 +37,7 @@ public function createAmal(Request $request){ 'user_id' =>$user, 'hari' => Carbon::now()->toDateString(), 'subuh' =>$request->subuh, - 'zuhur' =>$request->zuhur , + 'zuhur' =>$request->zuhur, 'ashar'=>$request->ashar, 'maghrib'=>$request->maghrib, 'isya'=>$request->isya, diff --git a/app/Http/Controllers/Konten/ArtikelDakwahController.php b/app/Http/Controllers/Konten/ArtikelDakwahController.php index 03b9256..dbb5042 100644 --- a/app/Http/Controllers/Konten/ArtikelDakwahController.php +++ b/app/Http/Controllers/Konten/ArtikelDakwahController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Konten; +use Hashids\Hashids; use Illuminate\Http\Request; use App\Models\ArtikelDakwah; use App\Http\Controllers\Controller; @@ -22,20 +23,24 @@ public function createArtikel(Request $request){ return response()->json([ 'Error' => true, 'Massage' => $validator->errors() - ]); + ], 402); } $uploadedImage = Cloudinary::upload($request->file('gambar')->getRealPath(), [ 'folder' => 'MIM/ArtikelDakwah' ]); - $artikel = ArtikelDakwah::create([ + $artikels = ArtikelDakwah::create([ 'judul' => $request->judul, 'gambar' => $uploadedImage->getSecurePath(), 'deskripsi' => $request->deskripsi, 'author' => $request->author ]); + $hashids = new Hashids('your-secret-salt', 10); + $hashedId = $hashids->encode($artikels->id); + $artikel = $artikels->toArray(); + $artikel['id'] = $hashedId; return response()->json([ 'Massage' => 'artikelCreatedSuccessfully', 'Artikel' => $artikel @@ -43,17 +48,64 @@ public function createArtikel(Request $request){ } public function showArtikel(){ + $artikels = ArtikelDakwah::orderBy('created_at', 'desc')->paginate(8); + $hashids = new Hashids('your-secret-salt', 10); + + $transformedData = $artikels->getCollection()->map(function($article) use ($hashids) { + $array = $article->toArray(); + $encodedId = $hashids->encode($article->id); + if ($encodedId) { + $array['id'] = $encodedId; + } else { + return response()->json([ + 'Data User' => 'Id Tidak Bisa DIHash' + ]); + } + return $array; + })->toArray(); - $artikel = ArtikelDakwah::all(); + $artikels->setCollection(collect($transformedData)); + return response()->json([ + 'Artikel' => $artikels + ]); + + } + + public function showOneArtikel($id){ + $hashids = new Hashids('your-secret-salt', 10); + $artikels = ArtikelDakwah::where('id', $hashids->decode($id))->first(); + + if(!$artikels){ + return response()->json([ + 'Artikel' => null, 'Not Found' + ], 204); + } + $artikel = $artikels->toArray(); + $encodedId = $hashids->encode($artikels->id); + if ($encodedId) { + $artikel['id'] = $encodedId ; + } else { + return response()->json([ + 'Data User' => 'Id Tidak Bisa DIHash' + ]); + } return response()->json([ 'Artikel' => $artikel ]); } public function updateArtikel(Request $request, $id){ - $artikel = ArtikelDakwah::find($id); + $hashids = new Hashids('your-secret-salt', 10); + $artikel = ArtikelDakwah::find($hashids->decode($id)[0]); + if (!$artikel) { + return response()->json([ + 'Error' => true, + 'Message' => 'Artikel tidak ditemukan' + ], 404); + } + $validator = Validator::make($request->all(), [ 'judul' => ['required', 'string'], 'gambar'=>['required', 'mimes:jpeg,jpg,png,svg,webp','max:2048', 'image'], @@ -98,8 +150,8 @@ public function updateArtikel(Request $request, $id){ } public function deleteArtikel($id){ - - ArtikelDakwah::destroy($id); + $hashids = new Hashids('your-secret-salt', 10); + ArtikelDakwah::destroy($hashids->decode($id)); return response()->json([ 'Massage' => 'artikelDeletedSuccessfully', diff --git a/app/Http/Controllers/Konten/InfoKajianController.php b/app/Http/Controllers/Konten/InfoKajianController.php index c4afdae..d94b290 100644 --- a/app/Http/Controllers/Konten/InfoKajianController.php +++ b/app/Http/Controllers/Konten/InfoKajianController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Konten; use Carbon\Carbon; +use Hashids\Hashids; use App\Models\InfoKajian; use Illuminate\Http\Request; use App\Http\Controllers\Controller; @@ -28,7 +29,7 @@ public function createKajian(Request $request){ $uploadedImage = Cloudinary::upload($request->file('gambar')->getRealPath(), [ 'folder' => 'MIM/thumnail_infokajian' ]); - $konten = InfoKajian::create([ + $kontens = InfoKajian::create([ 'judul' => $request->judul, 'gambar' => $uploadedImage->getSecurePath(), 'waktu'=> $request->waktu, @@ -36,6 +37,10 @@ public function createKajian(Request $request){ 'link'=> $request->link ]); + $hashids = new Hashids('your-secret-salt', 10); + $hashedId = $hashids->encode($kontens->id); + $konten = $kontens->toArray(); + $konten['id'] = $hashedId; return response()->json([ 'Massage' => 'ContentCreatedSuccessfully', 'user' => $konten @@ -44,15 +49,61 @@ public function createKajian(Request $request){ public function showKajian(){ - $konten = InfoKajian::all(); + $infoKajian = InfoKajian::orderBy('created_at', 'desc')->paginate(8); + $hashids = new Hashids('your-secret-salt', 10); + + $transformedData = $infoKajian->getCollection()->map(function($infokajians) use ($hashids) { + $array = $infokajians->toArray(); + $encodedId = $hashids->encode($infokajians->id); + if ($encodedId) { + $array['id'] = $encodedId; + } else { + return response()->json([ + 'Data User' => 'Id Tidak Bisa DIHash' + ]); + } + return $array; + })->toArray(); + + $infoKajian->setCollection(collect($transformedData)); + return response()->json([ - 'data' => $konten + 'Artikel' => $infoKajian ]); } - public function updateKajian(Request $request, $id){ + public function showOneKajian($id){ + $hashids = new Hashids('your-secret-salt', 10); + $kontens = InfoKajian::where('id', $hashids->decode($id))->first(); + + if(!$kontens){ + return response()->json([ + 'Kajian' => null, 'Not Found' + ], 204); + } + $konten = $kontens->toArray(); + $encodedId = $hashids->encode($kontens->id); + if ($encodedId) { + $konten['id'] = $encodedId ; + } else { + return response()->json([ + 'Data User' => 'Id Tidak Bisa DIHash' + ]); + } - $konten = InfoKajian::find($id); + return response()->json([ + 'Artikel' => $konten + ]); + } + + public function updateKajian(Request $request, $id){ + $hashids = new Hashids('your-secret-salt', 10); + $konten = InfoKajian::find($hashids->decode($id)[0]); + if (!$konten) { + return response()->json([ + 'message' => 'Kajian tidak ditemukan' + ], 404); + } $validator = Validator::make($request->all(),[ 'judul' => 'required|string', @@ -71,7 +122,7 @@ public function updateKajian(Request $request, $id){ if ($request->hasFile('gambar')) { // Menghapus foto lama jika ada - if ($konten->poto) { + if ($konten->gambar) { $publicId = pathinfo($konten->gambar, PATHINFO_FILENAME); Cloudinary::destroy($publicId); } @@ -98,8 +149,8 @@ public function updateKajian(Request $request, $id){ } public function deleteKajian($id){ - - InfoKajian::destroy($id); + $hashids = new Hashids('your-secret-salt', 10); + InfoKajian::destroy($hashids->decode($id)); return response()->json([ 'Artikel' => 'Kajian Ini Berhasil DiHapus' diff --git a/app/Http/Controllers/Konten/SearchController.php b/app/Http/Controllers/Konten/SearchController.php index cf2051b..7c78d94 100644 --- a/app/Http/Controllers/Konten/SearchController.php +++ b/app/Http/Controllers/Konten/SearchController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers\Konten; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; use App\Http\Controllers\Controller; use App\Models\ArtikelDakwah; use App\Models\InfoKajian; @@ -32,19 +31,39 @@ public function searchKonten(Request $request) 'ArtikelDakwah' => $artikelDakwahResults ]; - return response()->json($results); + return response()->json(["DataSearch" => $results]); } public function searchUser(Request $request){ $query = $request->get('Search'); - $results = User::where('name', 'like', "%{$query}%") - ->orWhere('email', 'like', "%{$query}%") - ->orWhere('tempat_lahir', 'like', "%{$query}%") - ->orWhere('no_telp', 'like', "%{$query}%") - ->get(); + $results = User::where('role', 'user') + ->where(function($q) use ($query) { + $q->where('name', 'like', "%{$query}%") + ->orWhere('email', 'like', "%{$query}%") + ->orWhere('tempat_lahir', 'like', "%{$query}%") + ->orWhere('no_telp', 'like', "%{$query}%"); + })->get(); - return response()->json($results); + + + return response()->json(["DataSearch" => $results]); + } + + public function searchAdmin(Request $request){ + $query = $request->get('Search'); + + $results = User::where('role', 'admin') + ->where(function($q) use ($query) { + $q->where('name', 'like', "%{$query}%") + ->orWhere('email', 'like', "%{$query}%") + ->orWhere('tempat_lahir', 'like', "%{$query}%") + ->orWhere('no_telp', 'like', "%{$query}%"); + })->get(); + + + + return response()->json(["DataSearch" => $results]); } } diff --git a/app/Http/Controllers/LoginSystem/AuthController.php b/app/Http/Controllers/LoginSystem/AuthController.php index 3aae8b3..d7a0e72 100644 --- a/app/Http/Controllers/LoginSystem/AuthController.php +++ b/app/Http/Controllers/LoginSystem/AuthController.php @@ -2,7 +2,9 @@ namespace App\Http\Controllers\LoginSystem; +use Carbon\Carbon; use App\Models\User; +use Hashids\Hashids; use Illuminate\Http\Request; use App\Jobs\SendEmailVerifyJob; use Illuminate\Support\Facades\URL; @@ -38,36 +40,40 @@ public function register(Request $request){ // $uploadedImage = Cloudinary::upload($request->file('img')->getRealPath(), [ // 'folder' => 'MIM/ProfilMIM' // ]); - $users = User::create([ - 'name' => $request->name, //full name - 'tgl_lahir' => $request->tgl_lahir, - 'tempat_lahir' => $request->tempat_lahir, - 'jenkel' => $request->jenkel,//Laki-laki Perempuan - 'alamat' => $request->alamat,//tulis dari user - 'no_telp' => $request->no_telp,// +62 - 'email' => $request->email, - 'pendidikan' => $request->pendidikan,//pendidikan terakhir - 'pekerjaan' => $request->pekerjaan, - 'range_gaji' => $request->range_gaji, - 'status' => $request->status,//status pernikahan sudah menika atau belum - 'jumlah_anak' => $request->jumlah_anak, - 'role' => 'user', - 'password' => Hash::make($request->password), - ]); + + $users = User::create([ + 'name' => $request->name, //full name + 'tgl_lahir' => $request->tgl_lahir, + 'tempat_lahir' => $request->tempat_lahir, + 'jenkel' => $request->jenkel,//Laki-laki Perempuan + 'alamat' => $request->alamat,//tulis dari user + 'no_telp' => $request->no_telp,// +62 + 'email' => $request->email, + 'pendidikan' => $request->pendidikan,//pendidikan terakhir + 'pekerjaan' => $request->pekerjaan, + 'range_gaji' => $request->range_gaji, + 'status' => $request->status,//status pernikahan sudah menikah atau belum + 'jumlah_anak' => $request->jumlah_anak, + 'role' => 'user', + 'password' => Hash::make($request->password), + ]); - $verification = URL::temporarySignedRoute( - 'verification.verify', - now()->addMinutes(60), - ['id' => $users->id, 'hash' => sha1($users->getEmailForVerification())] - ); + $hashids = new Hashids('your-secret-salt', 10); + $hashedId = $hashids->encode($users->id); + $verification = URL::temporarySignedRoute( + 'verification.verify', + now()->addMinutes(5), + ['id' => $hashedId, 'hash' => sha1($users->getEmailForVerification())] + ); + $responseUser = $users->toArray(); + $responseUser['id'] = $hashedId; + $SendEmailVerifyJob = new SendEmailVerifyJob($users, $verification); + dispatch($SendEmailVerifyJob); - $SendEmailVerifyJob = new SendEmailVerifyJob($users, $verification); - dispatch($SendEmailVerifyJob); - - return response()->json([ - 'Massage' => 'userCreatedSuccessfully, Please Check Your Email', - 'user' => $users - ]); + return response()->json([ + 'Massage' => 'userCreatedSuccessfully, Please Check Your Email', + 'user' => $responseUser + ]); } @@ -91,31 +97,34 @@ public function registerAdmin(Request $request){ 'no_telp' => $request->no_telp, 'email' => $request->email, 'role' => 'admin', + 'email_verified_at' => Carbon::now(), 'password' => Hash::make($request->password), ]); - $verification = URL::temporarySignedRoute( - 'verification.verify', - now()->addMinutes(60), - ['id' => $users->id, 'hash' => sha1($users->getEmailForVerification())] - ); + $hashids = new Hashids('your-secret-salt', 10); + $hashedId = $hashids->encode($users->id); + // $verification = URL::temporarySignedRoute( + // 'verification.verify', + // now()->addMinutes(60), + // ['id' => $hashedId, 'hash' => sha1($users->getEmailForVerification())] + // ); - $SendEmailVerifyJob = new SendEmailVerifyJob($users, $verification); - dispatch($SendEmailVerifyJob); + $responseUser = $users->toArray(); + $responseUser['id'] = $hashedId; + // dispatch(new SendEmailVerifyJob($users, $verification)); return response()->json([ - 'Massage' => 'userCreatedSuccessfully, Please Check Your Email', - 'user' => $users + 'Massage' => 'adminCreatedSuccessfully', + 'user' => $responseUser ]); } public function deleteAcc($id){ - $user = User::where('id', $id)->delete(); - - if($user){ - return response()->json([ - 'Massage' => 'userDeleteSuccessfully', - ]); - } + $hashids = new Hashids('your-secret-salt', 10); + User::destroy($hashids->decode($id)); + + return response()->json([ + 'User' => 'Account has been delete' + ]); } } diff --git a/app/Http/Controllers/LoginSystem/AuthMobileController.php b/app/Http/Controllers/LoginSystem/AuthMobileController.php index 7ce7a20..33cb1bc 100644 --- a/app/Http/Controllers/LoginSystem/AuthMobileController.php +++ b/app/Http/Controllers/LoginSystem/AuthMobileController.php @@ -5,6 +5,7 @@ use DateTimeZone; use Carbon\Carbon; use App\Models\User; +use Hashids\Hashids; use App\Jobs\SendOtpJob; use Illuminate\Support\Str; use Illuminate\Http\Request; @@ -59,18 +60,19 @@ public function registerMobile(Request $request){ 'jumlah_anak' => $request->jumlah_anak, 'role' => 'user', 'otp_code' => $verificationOtp, + 'otp_expired' => now()->addMinutes(5), 'password' => Hash::make($request->password), ]); - - $users->otp_expired = now()->addMinutes(1); - $users->save(); - $SendEmailVerifyJob = new SendOtpJob($users, $verificationOtp); - dispatch($SendEmailVerifyJob); - + $hashids = new Hashids('your-secret-salt', 10); + $hashedId = $hashids->encode($users->id); + dispatch(new SendOtpJob($users, $verificationOtp)); + $responseUser = $users->toArray(); + $responseUser['id'] = $hashedId; + return response()->json([ - 'Massage' => 'userCreatedSuccessfully, Please Check Your Email', - 'User' => $users + 'message' => 'User created successfully. Please check your email.', + 'user' => $responseUser ]); } } diff --git a/app/Http/Controllers/LoginSystem/PasswordController.php b/app/Http/Controllers/LoginSystem/PasswordController.php index abfb371..4bcff74 100644 --- a/app/Http/Controllers/LoginSystem/PasswordController.php +++ b/app/Http/Controllers/LoginSystem/PasswordController.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Password; use Illuminate\Auth\Events\PasswordReset; use Illuminate\Support\Facades\Validator; +use Hashids\Hashids; class PasswordController extends Controller { @@ -66,10 +67,11 @@ public function sendResetLink(Request $request) } else if (!$user->email_verified_at) { return response()->json(['message' => 'Email Not Verify'], 404); } else { + $token = Password::getRepository()->create($user); // Kirim email dengan link reset password ke pengguna - $resetLink = '{{ url }}/sendResetLink?token=' . $token; + $resetLink = 'http://mim.muhammadiyahexpo.com/api/resetPassword?token=' . $token; $SendForgotPasswordJob = new SendForgotPasswordJob($user, $resetLink); dispatch($SendForgotPasswordJob); diff --git a/app/Http/Controllers/LoginSystem/VerificationController.php b/app/Http/Controllers/LoginSystem/VerificationController.php index 70f9a6b..3a00eae 100644 --- a/app/Http/Controllers/LoginSystem/VerificationController.php +++ b/app/Http/Controllers/LoginSystem/VerificationController.php @@ -3,35 +3,51 @@ namespace App\Http\Controllers\LoginSystem; use App\Models\User; +use Hashids\Hashids; +use App\Jobs\SendOtpJob; use Illuminate\Http\Request; use App\Jobs\SendEmailVerifyJob; use Illuminate\Support\Facades\URL; use App\Http\Controllers\Controller; -use App\Jobs\SendOtpJob; use Illuminate\Support\Facades\Validator; class VerificationController extends Controller { public function verify(Request $request, $id){ - if(!$request->hasValidSignature()){ + if (!$request->hasValidSignature()) { return [ - 'message' => 'Email verified fails' + 'message' => 'Email verification failed' ]; } - $user = User::find($id); - - if(!$user->email_verified_at){ + + $hashids = new Hashids('your-secret-salt', 10); + $decodedIds = $hashids->decode($id); + if (!count($decodedIds)) { + return view('VerifyEmail.InvalidVerify'); + } + $realId = $decodedIds[0]; + + $user = User::find($realId); + + if (!$user) { + return view('VerifyEmail.InvalidVerify'); + } + + $responseUser = $user->toArray(); + $responseUser['id'] = $id; // We use the original hashed ID + + if (!$user->email_verified_at) { $user->email_verified_at = now(); $user->save(); - + return view('VerifyEmail.SuccessVerify'); - }else if($user->email_verified_at){ + } elseif ($user->email_verified_at) { return view('VerifyEmail.HasVerify'); - }else{ + } else { return view('VerifyEmail.InvalidVerify'); - } + } public function verifyOtp(Request $request){ @@ -94,11 +110,15 @@ public function resendVerification(Request $request){ 'message' => 'Email already verified.' ]); }else{ - $verification = URL::temporarySignedRoute( - 'verification.verify', - now()->addMinutes(60), - ['id' => $users->id, 'hash' => sha1($users->getEmailForVerification())] - ); + $hashids = new Hashids('your-secret-salt', 10); + $hashedId = $hashids->encode($users->id); + $verification = URL::temporarySignedRoute( + 'verification.verify', + now()->addMinutes(60), + ['id' => $hashedId, 'hash' => sha1($users->getEmailForVerification())] + ); + $responseUser = $users->toArray(); + $responseUser['id'] = $hashedId; $SendEmailVerifyJob = new SendEmailVerifyJob($users, $verification); dispatch($SendEmailVerifyJob); @@ -140,7 +160,7 @@ public function resendVerificationOtp(Request $request){ $users->otp_code = $verificationOtp; } while ($checkCode); - $users->otp_expired = now()->addMinutes(1); + $users->otp_expired = now()->addMinutes(5); $users->save(); $SendEmailVerifyJob = new SendOtpJob($users, $verificationOtp); dispatch($SendEmailVerifyJob); diff --git a/app/Http/Controllers/Profil/ProfilController.php b/app/Http/Controllers/Profil/ProfilController.php index bf9a5f4..46cb9c3 100644 --- a/app/Http/Controllers/Profil/ProfilController.php +++ b/app/Http/Controllers/Profil/ProfilController.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use App\Models\User; +use Hashids\Hashids; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; @@ -15,13 +16,21 @@ public function showProfil(){ $users = auth()->user(); $user = $users->id; - $profil = User::where('id', $user)->get(); + $hashids = new Hashids('your-secret-salt', 10); // sesuaikan dengan konfigurasi Anda + $hashedId = $hashids->encode($user); + + $profil = User::where('id', $user)->first(); + + $responseUser = $profil->toArray(); + $responseUser['id'] = $hashedId; return response()->json([ - 'Profil' => $profil + 'Profil' => $responseUser ]); } public function updateProfil(Request $request, $id){ + $hashids = new Hashids('your-secret-salt', 10); + $user = User::find($hashids->decode($id)[0]); $validate = Validator::make($request->all(), [ 'name' => 'required|string|max:255', @@ -43,8 +52,6 @@ public function updateProfil(Request $request, $id){ 'message'=>$validate->errors() ]); } - - $user = User::find($id); if ($request->hasFile('img')) { // Menghapus foto lama jika ada @@ -83,12 +90,51 @@ public function updateProfil(Request $request, $id){ ]); } - public function deleteAcc($id){ + + + public function showAllUser(){ + $users = User::where('role', 'user')->get(); + $hashids = new Hashids('your-secret-salt', 10); + + $usersArray = $users->map(function($user) use ($hashids) { + $array = $user->toArray(); + $encodedId = $hashids->encode($user->id); + if ($encodedId) { + $array['id'] = $encodedId; + } else { + return response()->json([ + 'Data User' => 'Id Tidak Bisa DIHash' + ]); + } + return $array; + })->toArray(); + + return response()->json([ + 'DataUser' => $usersArray + ]); + } + + public function showOneUser($id){ + $hashids = new Hashids('your-secret-salt', 10); + $userShow = User::where('id', $hashids->decode($id))->first(); + + if(!$userShow){ + return response()->json([ + 'Data User' => 'Not Found' + ],404); + } + $responseUser = $userShow->toArray(); + $encodedId = $hashids->encode($userShow->id); + if ($encodedId) { + $responseUser['id'] = $encodedId ; + } else { + return response()->json([ + 'DataUser' => 'Id Tidak Bisa DIHash' + ]); + } - User::destroy($id); - return response()->json([ - 'User' => 'Account has been delete' + 'Profil' => $responseUser ]); } } diff --git a/app/Models/BacaanSholat.php b/app/Models/BacaanSholat.php new file mode 100644 index 0000000..28b2db5 --- /dev/null +++ b/app/Models/BacaanSholat.php @@ -0,0 +1,19 @@ + 'datetime', ]; + public function getHashIdAttribute() { + $hashids = new Hashids('your-secret-salt', 10); // panjang minimum 10 + return $hashids->encode($this->attributes['id']); + } + public function amalyaumi(){ return $this->hasMany(AmalYaumi::class, 'user_id', 'id'); } diff --git a/composer.json b/composer.json index 8ad4ffd..7f9ee49 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "cloudinary-labs/cloudinary-laravel": "^2.0", "cloudinary/cloudinary_php": "^2", "guzzlehttp/guzzle": "^7.2", + "hashids/hashids": "^5.0", "laravel/framework": "^10.0", "laravel/passport": "^11.8", "laravel/sanctum": "^3.2", diff --git a/composer.lock b/composer.lock index 6624323..2460e35 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "431acad5d47983f10c80f9ce2ab33f92", + "content-hash": "1ce3f2efd7746a66c841d98ef11339a4", "packages": [ { "name": "brick/math", @@ -1306,6 +1306,75 @@ ], "time": "2021-10-07T12:57:01+00:00" }, + { + "name": "hashids/hashids", + "version": "5.0.2", + "source": { + "type": "git", + "url": "https://github.com/vinkla/hashids.git", + "reference": "197171016b77ddf14e259e186559152eb3f8cf33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vinkla/hashids/zipball/197171016b77ddf14e259e186559152eb3f8cf33", + "reference": "197171016b77ddf14e259e186559152eb3f8cf33", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-bcmath": "Required to use BC Math arbitrary precision mathematics (*).", + "ext-gmp": "Required to use GNU multiple precision mathematics (*)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Hashids\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Akimov", + "email": "ivan@barreleye.com" + }, + { + "name": "Vincent Klaiber", + "email": "hello@doubledip.se" + } + ], + "description": "Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers", + "homepage": "https://hashids.org/php", + "keywords": [ + "bitly", + "decode", + "encode", + "hash", + "hashid", + "hashids", + "ids", + "obfuscate", + "youtube" + ], + "support": { + "issues": "https://github.com/vinkla/hashids/issues", + "source": "https://github.com/vinkla/hashids/tree/5.0.2" + }, + "time": "2023-02-23T15:00:54+00:00" + }, { "name": "laravel/framework", "version": "v10.3.3", diff --git a/database/migrations/2023_08_25_025627_create_bacaan_sholats_table.php b/database/migrations/2023_08_25_025627_create_bacaan_sholats_table.php new file mode 100644 index 0000000..7a9730c --- /dev/null +++ b/database/migrations/2023_08_25_025627_create_bacaan_sholats_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('arab'); + $table->string('latin'); + $table->string('terjemahan'); + $table->string('voice_arab'); + $table->string('voice_terjemahan'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('bacaan_sholats'); + } +}; diff --git a/routes/api.php b/routes/api.php index f506c17..42288a5 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,6 @@ $baseDir . '/app/Console/Kernel.php', 'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php', + 'App\\Http\\Controllers\\API\\BacaanSholatController' => $baseDir . '/app/Http/Controllers/API/BacaanSholatController.php', 'App\\Http\\Controllers\\Controller' => $baseDir . '/app/Http/Controllers/Controller.php', + 'App\\Http\\Controllers\\Konten\\AmalYaumiController' => $baseDir . '/app/Http/Controllers/Konten/AmalYaumiController.php', + 'App\\Http\\Controllers\\Konten\\ArtikelDakwahController' => $baseDir . '/app/Http/Controllers/Konten/ArtikelDakwahController.php', + 'App\\Http\\Controllers\\Konten\\InfoKajianController' => $baseDir . '/app/Http/Controllers/Konten/InfoKajianController.php', + 'App\\Http\\Controllers\\Konten\\PendataanHafalanController' => $baseDir . '/app/Http/Controllers/Konten/PendataanHafalanController.php', + 'App\\Http\\Controllers\\Konten\\SearchController' => $baseDir . '/app/Http/Controllers/Konten/SearchController.php', 'App\\Http\\Controllers\\LoginSystem\\AuthController' => $baseDir . '/app/Http/Controllers/LoginSystem/AuthController.php', 'App\\Http\\Controllers\\LoginSystem\\AuthMobileController' => $baseDir . '/app/Http/Controllers/LoginSystem/AuthMobileController.php', 'App\\Http\\Controllers\\LoginSystem\\LoginController' => $baseDir . '/app/Http/Controllers/LoginSystem/LoginController.php', 'App\\Http\\Controllers\\LoginSystem\\PasswordController' => $baseDir . '/app/Http/Controllers/LoginSystem/PasswordController.php', 'App\\Http\\Controllers\\LoginSystem\\VerificationController' => $baseDir . '/app/Http/Controllers/LoginSystem/VerificationController.php', + 'App\\Http\\Controllers\\Profil\\ProfilController' => $baseDir . '/app/Http/Controllers/Profil/ProfilController.php', 'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php', 'App\\Http\\Middleware\\Authenticate' => $baseDir . '/app/Http/Middleware/Authenticate.php', 'App\\Http\\Middleware\\EncryptCookies' => $baseDir . '/app/Http/Middleware/EncryptCookies.php', @@ -31,6 +38,11 @@ 'App\\Mail\\SendEmailVerify' => $baseDir . '/app/Mail/SendEmailVerify.php', 'App\\Mail\\SendForgotPassword' => $baseDir . '/app/Mail/SendForgotPassword.php', 'App\\Mail\\SendOtp' => $baseDir . '/app/Mail/SendOtp.php', + 'App\\Models\\AmalYaumi' => $baseDir . '/app/Models/AmalYaumi.php', + 'App\\Models\\ArtikelDakwah' => $baseDir . '/app/Models/ArtikelDakwah.php', + 'App\\Models\\BacaanSholat' => $baseDir . '/app/Models/BacaanSholat.php', + 'App\\Models\\InfoKajian' => $baseDir . '/app/Models/InfoKajian.php', + 'App\\Models\\PendataanHafalan' => $baseDir . '/app/Models/PendataanHafalan.php', 'App\\Models\\User' => $baseDir . '/app/Models/User.php', 'App\\Providers\\AppServiceProvider' => $baseDir . '/app/Providers/AppServiceProvider.php', 'App\\Providers\\AuthServiceProvider' => $baseDir . '/app/Providers/AuthServiceProvider.php', @@ -1670,6 +1682,11 @@ 'Hamcrest\\Type\\IsString' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Type/IsString.php', 'Hamcrest\\Util' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Util.php', 'Hamcrest\\Xml\\HasXPath' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Xml/HasXPath.php', + 'Hashids\\Hashids' => $vendorDir . '/hashids/hashids/src/Hashids.php', + 'Hashids\\HashidsInterface' => $vendorDir . '/hashids/hashids/src/HashidsInterface.php', + 'Hashids\\Math\\BCMath' => $vendorDir . '/hashids/hashids/src/Math/BCMath.php', + 'Hashids\\Math\\Gmp' => $vendorDir . '/hashids/hashids/src/Math/Gmp.php', + 'Hashids\\Math\\MathInterface' => $vendorDir . '/hashids/hashids/src/Math/MathInterface.php', 'Http\\Message\\MessageFactory' => $vendorDir . '/php-http/message-factory/src/MessageFactory.php', 'Http\\Message\\RequestFactory' => $vendorDir . '/php-http/message-factory/src/RequestFactory.php', 'Http\\Message\\ResponseFactory' => $vendorDir . '/php-http/message-factory/src/ResponseFactory.php', diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index e2bf39a..253ece3 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -80,6 +80,7 @@ 'Illuminate\\Support\\' => array($vendorDir . '/laravel/framework/src/Illuminate/Macroable', $vendorDir . '/laravel/framework/src/Illuminate/Collections', $vendorDir . '/laravel/framework/src/Illuminate/Conditionable'), 'Illuminate\\' => array($vendorDir . '/laravel/framework/src/Illuminate'), 'Http\\Message\\' => array($vendorDir . '/php-http/message-factory/src'), + 'Hashids\\' => array($vendorDir . '/hashids/hashids/src'), 'GuzzleHttp\\UriTemplate\\' => array($vendorDir . '/guzzlehttp/uri-template/src'), 'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'), 'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index b326c8d..a6e67b6 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -148,6 +148,7 @@ class ComposerStaticInited975557e14d9eacb99ce35e9923e25c 'H' => array ( 'Http\\Message\\' => 13, + 'Hashids\\' => 8, ), 'G' => array ( @@ -495,6 +496,10 @@ class ComposerStaticInited975557e14d9eacb99ce35e9923e25c array ( 0 => __DIR__ . '/..' . '/php-http/message-factory/src', ), + 'Hashids\\' => + array ( + 0 => __DIR__ . '/..' . '/hashids/hashids/src', + ), 'GuzzleHttp\\UriTemplate\\' => array ( 0 => __DIR__ . '/..' . '/guzzlehttp/uri-template/src', @@ -601,12 +606,19 @@ class ComposerStaticInited975557e14d9eacb99ce35e9923e25c public static $classMap = array ( 'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php', 'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php', + 'App\\Http\\Controllers\\API\\BacaanSholatController' => __DIR__ . '/../..' . '/app/Http/Controllers/API/BacaanSholatController.php', 'App\\Http\\Controllers\\Controller' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php', + 'App\\Http\\Controllers\\Konten\\AmalYaumiController' => __DIR__ . '/../..' . '/app/Http/Controllers/Konten/AmalYaumiController.php', + 'App\\Http\\Controllers\\Konten\\ArtikelDakwahController' => __DIR__ . '/../..' . '/app/Http/Controllers/Konten/ArtikelDakwahController.php', + 'App\\Http\\Controllers\\Konten\\InfoKajianController' => __DIR__ . '/../..' . '/app/Http/Controllers/Konten/InfoKajianController.php', + 'App\\Http\\Controllers\\Konten\\PendataanHafalanController' => __DIR__ . '/../..' . '/app/Http/Controllers/Konten/PendataanHafalanController.php', + 'App\\Http\\Controllers\\Konten\\SearchController' => __DIR__ . '/../..' . '/app/Http/Controllers/Konten/SearchController.php', 'App\\Http\\Controllers\\LoginSystem\\AuthController' => __DIR__ . '/../..' . '/app/Http/Controllers/LoginSystem/AuthController.php', 'App\\Http\\Controllers\\LoginSystem\\AuthMobileController' => __DIR__ . '/../..' . '/app/Http/Controllers/LoginSystem/AuthMobileController.php', 'App\\Http\\Controllers\\LoginSystem\\LoginController' => __DIR__ . '/../..' . '/app/Http/Controllers/LoginSystem/LoginController.php', 'App\\Http\\Controllers\\LoginSystem\\PasswordController' => __DIR__ . '/../..' . '/app/Http/Controllers/LoginSystem/PasswordController.php', 'App\\Http\\Controllers\\LoginSystem\\VerificationController' => __DIR__ . '/../..' . '/app/Http/Controllers/LoginSystem/VerificationController.php', + 'App\\Http\\Controllers\\Profil\\ProfilController' => __DIR__ . '/../..' . '/app/Http/Controllers/Profil/ProfilController.php', 'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php', 'App\\Http\\Middleware\\Authenticate' => __DIR__ . '/../..' . '/app/Http/Middleware/Authenticate.php', 'App\\Http\\Middleware\\EncryptCookies' => __DIR__ . '/../..' . '/app/Http/Middleware/EncryptCookies.php', @@ -624,6 +636,11 @@ class ComposerStaticInited975557e14d9eacb99ce35e9923e25c 'App\\Mail\\SendEmailVerify' => __DIR__ . '/../..' . '/app/Mail/SendEmailVerify.php', 'App\\Mail\\SendForgotPassword' => __DIR__ . '/../..' . '/app/Mail/SendForgotPassword.php', 'App\\Mail\\SendOtp' => __DIR__ . '/../..' . '/app/Mail/SendOtp.php', + 'App\\Models\\AmalYaumi' => __DIR__ . '/../..' . '/app/Models/AmalYaumi.php', + 'App\\Models\\ArtikelDakwah' => __DIR__ . '/../..' . '/app/Models/ArtikelDakwah.php', + 'App\\Models\\BacaanSholat' => __DIR__ . '/../..' . '/app/Models/BacaanSholat.php', + 'App\\Models\\InfoKajian' => __DIR__ . '/../..' . '/app/Models/InfoKajian.php', + 'App\\Models\\PendataanHafalan' => __DIR__ . '/../..' . '/app/Models/PendataanHafalan.php', 'App\\Models\\User' => __DIR__ . '/../..' . '/app/Models/User.php', 'App\\Providers\\AppServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AppServiceProvider.php', 'App\\Providers\\AuthServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AuthServiceProvider.php', @@ -2263,6 +2280,11 @@ class ComposerStaticInited975557e14d9eacb99ce35e9923e25c 'Hamcrest\\Type\\IsString' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Type/IsString.php', 'Hamcrest\\Util' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Util.php', 'Hamcrest\\Xml\\HasXPath' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Xml/HasXPath.php', + 'Hashids\\Hashids' => __DIR__ . '/..' . '/hashids/hashids/src/Hashids.php', + 'Hashids\\HashidsInterface' => __DIR__ . '/..' . '/hashids/hashids/src/HashidsInterface.php', + 'Hashids\\Math\\BCMath' => __DIR__ . '/..' . '/hashids/hashids/src/Math/BCMath.php', + 'Hashids\\Math\\Gmp' => __DIR__ . '/..' . '/hashids/hashids/src/Math/Gmp.php', + 'Hashids\\Math\\MathInterface' => __DIR__ . '/..' . '/hashids/hashids/src/Math/MathInterface.php', 'Http\\Message\\MessageFactory' => __DIR__ . '/..' . '/php-http/message-factory/src/MessageFactory.php', 'Http\\Message\\RequestFactory' => __DIR__ . '/..' . '/php-http/message-factory/src/RequestFactory.php', 'Http\\Message\\ResponseFactory' => __DIR__ . '/..' . '/php-http/message-factory/src/ResponseFactory.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index c371ec0..606c3e1 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1550,6 +1550,78 @@ }, "install-path": "../hamcrest/hamcrest-php" }, + { + "name": "hashids/hashids", + "version": "5.0.2", + "version_normalized": "5.0.2.0", + "source": { + "type": "git", + "url": "https://github.com/vinkla/hashids.git", + "reference": "197171016b77ddf14e259e186559152eb3f8cf33" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vinkla/hashids/zipball/197171016b77ddf14e259e186559152eb3f8cf33", + "reference": "197171016b77ddf14e259e186559152eb3f8cf33", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-bcmath": "Required to use BC Math arbitrary precision mathematics (*).", + "ext-gmp": "Required to use GNU multiple precision mathematics (*)." + }, + "time": "2023-02-23T15:00:54+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Hashids\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ivan Akimov", + "email": "ivan@barreleye.com" + }, + { + "name": "Vincent Klaiber", + "email": "hello@doubledip.se" + } + ], + "description": "Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers", + "homepage": "https://hashids.org/php", + "keywords": [ + "bitly", + "decode", + "encode", + "hash", + "hashid", + "hashids", + "ids", + "obfuscate", + "youtube" + ], + "support": { + "issues": "https://github.com/vinkla/hashids/issues", + "source": "https://github.com/vinkla/hashids/tree/5.0.2" + }, + "install-path": "../hashids/hashids" + }, { "name": "laravel/framework", "version": "v10.3.3", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 63ca20c..1601d67 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'laravel/laravel', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '93f239212aeb45843152ad75bd4e099e9fafab02', + 'reference' => '7575bdcd9aa9880308751d928698c1c5a06fb60d', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -202,6 +202,15 @@ 'aliases' => array(), 'dev_requirement' => true, ), + 'hashids/hashids' => array( + 'pretty_version' => '5.0.2', + 'version' => '5.0.2.0', + 'reference' => '197171016b77ddf14e259e186559152eb3f8cf33', + 'type' => 'library', + 'install_path' => __DIR__ . '/../hashids/hashids', + 'aliases' => array(), + 'dev_requirement' => false, + ), 'illuminate/auth' => array( 'dev_requirement' => false, 'replaced' => array( @@ -418,7 +427,7 @@ 'laravel/laravel' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '93f239212aeb45843152ad75bd4e099e9fafab02', + 'reference' => '7575bdcd9aa9880308751d928698c1c5a06fb60d', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/vendor/hashids/hashids/LICENSE b/vendor/hashids/hashids/LICENSE new file mode 100644 index 0000000..e490b94 --- /dev/null +++ b/vendor/hashids/hashids/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Ivan Akimov + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/hashids/hashids/composer.json b/vendor/hashids/hashids/composer.json new file mode 100644 index 0000000..c12537d --- /dev/null +++ b/vendor/hashids/hashids/composer.json @@ -0,0 +1,58 @@ +{ + "name": "hashids/hashids", + "description": "Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers", + "license": "MIT", + "keywords": [ + "bitly", + "decode", + "encode", + "hash", + "hashid", + "hashids", + "ids", + "obfuscate", + "youtube" + ], + "authors": [ + { + "name": "Ivan Akimov", + "email": "ivan@barreleye.com" + }, + { + "name": "Vincent Klaiber", + "email": "hello@doubledip.se" + } + ], + "homepage": "https://hashids.org/php", + "require": { + "php": "^8.1", + "ext-mbstring": "*" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-bcmath": "Required to use BC Math arbitrary precision mathematics (*).", + "ext-gmp": "Required to use GNU multiple precision mathematics (*)." + }, + "minimum-stability": "dev", + "prefer-stable": true, + "autoload": { + "psr-4": { + "Hashids\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Hashids\\Tests\\": "tests/" + } + }, + "config": { + "preferred-install": "dist" + }, + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + } +} diff --git a/vendor/hashids/hashids/src/Hashids.php b/vendor/hashids/hashids/src/Hashids.php new file mode 100644 index 0000000..ac4ab4c --- /dev/null +++ b/vendor/hashids/hashids/src/Hashids.php @@ -0,0 +1,308 @@ +salt = mb_convert_encoding($salt, 'UTF-8', mb_detect_encoding($salt)); + $this->minHashLength = $minHashLength; + $alphabet = mb_convert_encoding($alphabet, 'UTF-8', mb_detect_encoding($alphabet)); + $this->alphabet = implode('', array_unique($this->multiByteSplit($alphabet))); + $this->math = $this->getMathExtension(); + + if (mb_strlen($this->alphabet) < 16) { + throw new InvalidArgumentException('The Hashids alphabet must contain at least 16 unique characters.'); + } + + if (false !== mb_strpos($this->alphabet, ' ')) { + throw new InvalidArgumentException('The Hashids alphabet can\'t contain spaces.'); + } + + $alphabetArray = $this->multiByteSplit($this->alphabet); + $sepsArray = $this->multiByteSplit($this->seps); + $this->seps = implode('', array_intersect($sepsArray, $alphabetArray)); + $this->alphabet = implode('', array_diff($alphabetArray, $sepsArray)); + $this->seps = $this->shuffle($this->seps, $this->salt); + + if (!$this->seps || (mb_strlen($this->alphabet) / mb_strlen($this->seps)) > self::SEP_DIV) { + $sepsLength = (int) ceil(mb_strlen($this->alphabet) / self::SEP_DIV); + + if ($sepsLength > mb_strlen($this->seps)) { + $diff = $sepsLength - mb_strlen($this->seps); + $this->seps .= mb_substr($this->alphabet, 0, $diff); + $this->alphabet = mb_substr($this->alphabet, $diff); + } + } + + $this->alphabet = $this->shuffle($this->alphabet, $this->salt); + $guardCount = (int) ceil(mb_strlen($this->alphabet) / self::GUARD_DIV); + + if (mb_strlen($this->alphabet) < 3) { + $this->guards = mb_substr($this->seps, 0, $guardCount); + $this->seps = mb_substr($this->seps, $guardCount); + } else { + $this->guards = mb_substr($this->alphabet, 0, $guardCount); + $this->alphabet = mb_substr($this->alphabet, $guardCount); + } + } + + public function encode(...$numbers): string + { + $ret = ''; + + if (1 === count($numbers) && is_array($numbers[0])) { + $numbers = $numbers[0]; + } + + if (!$numbers) { + return $ret; + } + + foreach ($numbers as $number) { + $isNumber = ctype_digit((string) $number); + + if (!$isNumber) { + return $ret; + } + } + + $alphabet = $this->alphabet; + $numbersSize = count($numbers); + $numbersHashInt = 0; + + foreach ($numbers as $i => $number) { + $numbersHashInt += $this->math->intval($this->math->mod($number, $i + 100)); + } + + $lottery = $ret = mb_substr($alphabet, $numbersHashInt % mb_strlen($alphabet), 1); + foreach ($numbers as $i => $number) { + $alphabet = $this->shuffle($alphabet, mb_substr($lottery . $this->salt . $alphabet, 0, mb_strlen($alphabet))); + $ret .= $last = $this->hash($number, $alphabet); + + if ($i + 1 < $numbersSize) { + $number %= (mb_ord($last, 'UTF-8') + $i); + $sepsIndex = $this->math->intval($this->math->mod($number, mb_strlen($this->seps))); + $ret .= mb_substr($this->seps, $sepsIndex, 1); + } + } + + if (mb_strlen($ret) < $this->minHashLength) { + $guardIndex = ($numbersHashInt + mb_ord(mb_substr($ret, 0, 1), 'UTF-8')) % mb_strlen($this->guards); + + $guard = mb_substr($this->guards, $guardIndex, 1); + $ret = $guard . $ret; + + if (mb_strlen($ret) < $this->minHashLength) { + $guardIndex = ($numbersHashInt + mb_ord(mb_substr($ret, 2, 1), 'UTF-8')) % mb_strlen($this->guards); + $guard = mb_substr($this->guards, $guardIndex, 1); + + $ret .= $guard; + } + } + + $halfLength = (int) (mb_strlen($alphabet) / 2); + while (mb_strlen($ret) < $this->minHashLength) { + $alphabet = $this->shuffle($alphabet, $alphabet); + $ret = mb_substr($alphabet, $halfLength) . $ret . mb_substr($alphabet, 0, $halfLength); + + $excess = mb_strlen($ret) - $this->minHashLength; + if ($excess > 0) { + $ret = mb_substr($ret, (int) ($excess / 2), $this->minHashLength); + } + } + + return $ret; + } + + public function decode(string $hash): array + { + $ret = []; + + if (!($hash = trim($hash))) { + return $ret; + } + + $alphabet = $this->alphabet; + + $hashBreakdown = str_replace($this->multiByteSplit($this->guards), ' ', $hash); + $hashArray = explode(' ', $hashBreakdown); + + $i = 3 === count($hashArray) || 2 === count($hashArray) ? 1 : 0; + + $hashBreakdown = $hashArray[$i]; + + if ('' !== $hashBreakdown) { + $lottery = mb_substr($hashBreakdown, 0, 1); + $hashBreakdown = mb_substr($hashBreakdown, 1); + + $hashBreakdown = str_replace($this->multiByteSplit($this->seps), ' ', $hashBreakdown); + $hashArray = explode(' ', $hashBreakdown); + + foreach ($hashArray as $subHash) { + $alphabet = $this->shuffle($alphabet, mb_substr($lottery . $this->salt . $alphabet, 0, mb_strlen($alphabet))); + $result = $this->unhash($subHash, $alphabet); + if ($this->math->greaterThan($result, PHP_INT_MAX)) { + $ret[] = $this->math->strval($result); + } else { + $ret[] = $this->math->intval($result); + } + } + + if ($this->encode($ret) !== $hash) { + $ret = []; + } + } + + return $ret; + } + + public function encodeHex(string $str): string + { + if (!ctype_xdigit($str)) { + return ''; + } + + $numbers = trim(chunk_split($str, 12, ' ')); + $numbers = explode(' ', $numbers); + + foreach ($numbers as $i => $number) { + $numbers[$i] = hexdec('1' . $number); + } + + return $this->encode(...$numbers); + } + + public function decodeHex(string $hash): string + { + $ret = ''; + $numbers = $this->decode($hash); + + foreach ($numbers as $number) { + $ret .= mb_substr(dechex($number), 1); + } + + return $ret; + } + + /** Shuffle alphabet by given salt. */ + protected function shuffle(string $alphabet, string $salt): string + { + $key = $alphabet . ' ' . $salt; + + if (isset($this->shuffledAlphabets[$key])) { + return $this->shuffledAlphabets[$key]; + } + + $saltLength = mb_strlen($salt); + $saltArray = $this->multiByteSplit($salt); + if (!$saltLength) { + return $alphabet; + } + $alphabetArray = $this->multiByteSplit($alphabet); + for ($i = mb_strlen($alphabet) - 1, $v = 0, $p = 0; $i > 0; $i--, $v++) { + $v %= $saltLength; + $p += $int = mb_ord($saltArray[$v], 'UTF-8'); + $j = ($int + $v + $p) % $i; + + $temp = $alphabetArray[$j]; + $alphabetArray[$j] = $alphabetArray[$i]; + $alphabetArray[$i] = $temp; + } + $alphabet = implode('', $alphabetArray); + $this->shuffledAlphabets[$key] = $alphabet; + + return $alphabet; + } + + /** Hash given input value. */ + protected function hash(string $input, string $alphabet): string + { + $hash = ''; + $alphabetLength = mb_strlen($alphabet); + + do { + $hash = mb_substr($alphabet, $this->math->intval($this->math->mod($input, $alphabetLength)), 1) . $hash; + + $input = $this->math->divide($input, $alphabetLength); + } while ($this->math->greaterThan($input, 0)); + + return $hash; + } + + /** Unhash given input value. */ + protected function unhash(string $input, string $alphabet): int|string + { + $number = 0; + $inputLength = mb_strlen($input); + + if ($inputLength && $alphabet) { + $alphabetLength = mb_strlen($alphabet); + $inputChars = $this->multiByteSplit($input); + + foreach ($inputChars as $char) { + $position = mb_strpos($alphabet, $char); + $number = $this->math->multiply($number, $alphabetLength); + $number = $this->math->add($number, $position); + } + } + + return $number; + } + + /** + * Get BC Math or GMP extension. + * @throws \RuntimeException + */ + protected function getMathExtension(): MathInterface + { + if (extension_loaded('gmp')) { + return new Gmp(); + } + + if (extension_loaded('bcmath')) { + return new BCMath(); + } + + throw new RuntimeException('Missing math extension for Hashids, install either bcmath or gmp.'); + } + + /** + * Replace simple use of $this->multiByteSplit with multi byte string. + * @return array + */ + protected function multiByteSplit(string $string): array + { + return preg_split('/(?!^)(?=.)/u', $string) ?: []; + } +} diff --git a/vendor/hashids/hashids/src/HashidsInterface.php b/vendor/hashids/hashids/src/HashidsInterface.php new file mode 100644 index 0000000..b255eee --- /dev/null +++ b/vendor/hashids/hashids/src/HashidsInterface.php @@ -0,0 +1,33 @@ + ...$numbers + */ + public function encode(...$numbers): string; + + /** + * Decode a hash to the original parameter values. + * @return array|array{} + */ + public function decode(string $hash): array; + + /** Encode hexadecimal values and generate a hash string. */ + public function encodeHex(string $str): string; + + /** Decode a hexadecimal hash. */ + public function decodeHex(string $hash): string; +} diff --git a/vendor/hashids/hashids/src/Math/BCMath.php b/vendor/hashids/hashids/src/Math/BCMath.php new file mode 100644 index 0000000..537bf7a --- /dev/null +++ b/vendor/hashids/hashids/src/Math/BCMath.php @@ -0,0 +1,55 @@ + 0; + } + + public function intval($a) + { + return intval($a); + } + + public function strval($a) + { + return $a; + } + + public function get($a) + { + return $a; + } +} diff --git a/vendor/hashids/hashids/src/Math/Gmp.php b/vendor/hashids/hashids/src/Math/Gmp.php new file mode 100644 index 0000000..509f0ed --- /dev/null +++ b/vendor/hashids/hashids/src/Math/Gmp.php @@ -0,0 +1,55 @@ + 0; + } + + public function intval($a) + { + return gmp_intval($a); + } + + public function strval($a) + { + return gmp_strval($a); + } + + public function get($a) + { + return gmp_init($a); + } +} diff --git a/vendor/hashids/hashids/src/Math/MathInterface.php b/vendor/hashids/hashids/src/Math/MathInterface.php new file mode 100644 index 0000000..493fa80 --- /dev/null +++ b/vendor/hashids/hashids/src/Math/MathInterface.php @@ -0,0 +1,76 @@ +