validate( [ 'email' => ['required', 'email'], 'password' => ['required', 'min:8'], ], [ 'email.required' => 'Alamat email wajib diisi.', 'email.email' => 'Alamat email harus berformat valid.', 'password.required' => 'Password wajib diisi.', 'password.min' => 'Password harus memiliki panjang minimal 8 karakter.', ] ); if (Auth::attempt($credentials)) { if (Auth::user()->status == 'Finished') { $request->session()->regenerate(); if (ucwords(Auth::user()->role) == 'Admin') { return redirect()->intended('admin'); } else { return redirect()->intended('user'); } } else if(Auth::user()->status == 'Rejected'){ Session::flash('message', 'Akun ditolak karena tidak memenuhi persyaratan'); return redirect()->back(); } else { Session::flash('message', 'Akun tidak ditemukan atau sedang dalam pengajuan'); return redirect()->back(); } }else{ return redirect() ->back() ->withErrors($credentials) ->onlyInput('email'); } } /** * Log the user out (Invalidate the token). * * @return \Illuminate\Http\JsonResponse */ public function logout(Request $request) { Auth::logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); return redirect()->route('login'); } public function register(Request $request) { $nama_depan = $request->get('nama-depan'); $nama_belakang = $request->get('nama-belakang'); $tanggal_lahir = $request->get('tanggal-lahir'); $new_password = $request->get('new-password'); $nik = $request->get('nik'); $email = $request->get('email'); $nohp = $request->get('nohp'); $alamat = $request->get('alamat'); $foto_ktp = ''; $foto_wajah = ''; $persentase_kemiripan = '0%'; $gender = $request->get('gender'); $kode_kelurahan = $request->get('kode-kelurahan'); $ktpBase64 = $request->request->get('ktp'); $wajahBase64 = $request->request->get('wajah'); $validatedData['email_verified_at'] = now(); if ($ktpBase64 && $wajahBase64) { // Konversi string Base64 ke file gambar $ktpFile = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $ktpBase64)); $wajahFile = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $wajahBase64)); $foto_ktp = 'Foto-KTP-' . $nama_depan . '-' . $nama_belakang . '.jpg'; $foto_wajah = 'Foto-Wajah-' . $nama_depan . '-' . $nama_belakang . '.jpg'; file_put_contents(public_path('storage/foto-ktp/' . $foto_ktp), $ktpFile); file_put_contents(public_path('storage/foto-wajah/' . $foto_wajah), $wajahFile); } //OCR try { $fotoKTP = public_path('storage/foto-ktp/' . $foto_ktp); $image = Image::make($fotoKTP); $image->greyscale(); // Convert to grayscale $image->contrast(10); // Increase contrast, adjust the value as needed $preprocessedfotoKTP = public_path('storage/preprocessed/preprocessed_image.jpg'); $image->save($preprocessedfotoKTP); $result = (new TesseractOCR($preprocessedfotoKTP))->run(); // (5) Normalize $lines = explode("\n", $result); $namaOCR = ''; $nikOCR = ''; $nikInputan = $nik; $namaInputan = $nama_depan . ' ' . $nama_belakang; foreach ($lines as $line) { // Mencari NIK if (strpos($line, $nikInputan) !== false) { $nikOCR = preg_replace('/[^0-9]/', '', $line); } // Mencari nama if (strpos($line, $namaInputan) !== false) { $namaOCR = trim(substr($line, strpos($line, ':') + 1)); } } //Selesai $persentase_kemiripan = (similar_text($nikInputan, $nikOCR, $percent) + similar_text($namaOCR, $namaOCR, $percent)) / 2; // $status = 'Progress'; // if (similar_text($nikInputan, $nikOCR, $percent) >= 70 && similar_text($namaOCR, $namaOCR, $percent) >= 70) { // $status = 'Progress'; // } else { // $status = 'Progress'; // } } catch (\Exception $e) { // $status = 'Progress'; } //OCR //Deteksi wajah belum $password = Hash::make($new_password); $result = User::create([ 'id' => Uuid::uuid4(), 'nama_depan' => $nama_depan, 'nama_belakang' => $nama_belakang, 'tanggal_lahir' => $tanggal_lahir, 'email' => $email, 'email_verified_at' => now(), 'password' => $password, 'nohp' => $nohp, 'nik' => $nik, 'alamat' => $alamat, 'foto_ktp' => $foto_ktp, 'foto_wajah' => $foto_wajah, 'foto_profil' => null, 'persentase_kemiripan' => $persentase_kemiripan, 'gender' => $gender, 'kode_kelurahan' => $kode_kelurahan, 'remember_token' => Str::random(10), ]); if ($result) { return response()->json([ 'status' => true, 'message' => 'Akun anda sudah terdaftar dan butuh verifikasi hingga maksimal 1 hari kerja', ]); } else { return response()->json([ 'status' => false, 'message' => 'Akun anda gagal terdaftar. Coba lagi! ' + $result, ]); } } public function accountStatus($email) { $result = User::where('email', $email)->get(); if ($result->isNotEmpty()) { return response()->json([ 'status' => true, 'message' => $result, ]); } else { return response()->json([ 'status' => false, 'message' => $result, ]); } } public function searchProvince() { $data = Province::where('name', 'LIKE', '%' . strtoupper(request('q')) . '%')->paginate(10); return response()->json($data); } public function searchCity($code) { $data = City::where('province_code', $code) ->where('name', 'LIKE', '%' . strtoupper(request('q')) . '%') ->paginate(10); return response()->json($data); } public function searchDistrict($code) { $data = District::where('city_code', $code) ->where('name', 'LIKE', '%' . strtoupper(request('q')) . '%') ->paginate(10); return response()->json($data); } public function searchVillage($code) { $data = Village::where('district_code', $code) ->where('name', 'LIKE', '%' . strtoupper(request('q')) . '%') ->paginate(10); return response()->json($data); } public function sendVerificationCode(Request $request) { $email = $request->get('email'); $code = $request->get('code'); $verificationEmail = [ 'code' => $code, 'email' => $email, ]; try { Mail::to($email)->send(new verificationMail($verificationEmail)); return response()->json([ 'message' => 'Kode verifikasi berhasil dikirim ke email. Silahkan cek di email anda.', 'status' => true, ]); } catch (\Exception $e) { return response()->json([ 'message' => 'Kode verifikasi gagal dikirim ke email. ' . $e, 'status' => false, ]); } } public function getOcr() { //OCR // dd(phpinfo()); try { $fotoKTP = public_path('storage/foto-ktp/ktp.jpg'); $image = Image::make($fotoKTP); $image->greyscale(); // Convert to grayscale $image->contrast(10); // Increase contrast, adjust the value as needed $preprocessedfotoKTP = public_path('storage/preprocessed/preprocessed_image.jpg'); $image->save($preprocessedfotoKTP); $result = (new TesseractOCR($preprocessedfotoKTP))->run(); // (5) Normalize $lines = explode("\n", $result); $nikOCR = ''; $namaOCR = ''; $nikInputan = '3471140209790001'; $namaInputan = 'RIYANTO. SE'; foreach ($lines as $line) { // Mencari NIK if (strpos($line, $nikInputan) !== false) { $nikOCR = preg_replace('/[^0-9]/', '', $line); } // Mencari nama if (strpos($line, $namaInputan) !== false) { $namaOCR = trim(substr($line, strpos($line, ':') + 1)); } } //Selesai $persentase_kemiripan = (similar_text($nikInputan, $nikOCR, $percent) + similar_text($namaOCR, $namaOCR, $percent)) / 2; // $status = 'Progress'; dd([$persentase_kemiripan, $lines]); // if (similar_text($nikInputan, $nikOCR, $percent) >= 70 && similar_text($namaOCR, $namaOCR, $percent) >= 70) { // $status = 'Progress'; // } else { // $status = 'Progress'; // } } catch (\Exception $e) { // $status = 'Progress'; dd($e); } //OCR } }