瀏覽代碼

implementasi token csrf di semua action

andi 2 年之前
父節點
當前提交
19d23a6fe1

+ 29 - 4
actions/banding.js

@@ -1,26 +1,51 @@
 import axios from "../config/axios";
 import { createLog } from "./log";
+import { getCsrf } from "./security";
 
 export const addBanding = async (token, id, data) => {
 	try {
 		const res = await axios.post(`/sanksi/banding/create/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil mengajukan Banding, id: ${id}` });
+		logSuccessAddBanding(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal mengajukan Banding, id: ${id}` });
+		logErrorAddBanding(token, id)
 		return false;
 	}
 };
+const logSuccessAddBanding = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil mengajukan Banding, id: ${id}`, _csrf: _csrf });
+
+}
+const logErrorAddBanding = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal mengajukan Banding, id: ${id}`, _csrf: _csrf });
+
+}
 
 export const addJawabanBanding = async (token, id, data) => {
 	try {
 		const res = await axios.post(`/sanksi/banding/jawaban/create/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil menjawab pengajuan Banding, id: ${id}` });
+		logSuccessAddJawabanBanding(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal menjawab pengajuan Banding, id: ${id}` });
+		logErrorAddJawabanBanding(token, id)
 		return false;
 	}
 };
+const logSuccessAddJawabanBanding = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil menjawab pengajuan Banding, id: ${id}`, _csrf: _csrf });
+
+}
+const logErrorAddJawabanBanding = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal menjawab pengajuan Banding, id: ${id}`, _csrf: _csrf });
+
+}

+ 40 - 6
actions/cabutSanksi.js

@@ -1,38 +1,72 @@
 import axios from "../config/axios";
 import { createLog } from "./log";
+import { getCsrf } from "./security";
 
 export const addCabutSanksi = async (token, id, data) => {
 	try {
 		const res = await axios.post(`/sanksi/cabut-sanksi/create/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil mengajukan pencabutan sanksi, id: ${id}` });
+		logSuccessAddCabutSanksi(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal mengajukan pencabutan sanksi, id: ${id}` });
+		logErrorAddCabutSanksi(token, id)
 		return false;
 	}
 };
 
+const logSuccessAddCabutSanksi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil mengajukan pencabutan sanksi, id: ${id}`, _csrf: _csrf });
+}
+
+const logErrorAddCabutSanksi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal mengajukan pencabutan sanksi, id: ${id}`, _csrf: _csrf });
+}
+
 export const addJawabanCabutSanksi = async (token, id, data) => {
 	try {
 		const res = await axios.post(`/sanksi/cabut-sanksi/jawaban/create/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil menjawab pengajuan pencabutan sanksi, id: ${id}` });
+		logSuccessaddJawabanCabutSanksi(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal menjawab pengajuan pencabutan sanksi, id: ${id}` });
+		logErroraddJawabanCabutSanksi(token, id)
 		return false;
 	}
 };
 
+const logSuccessaddJawabanCabutSanksi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil menjawab pengajuan pencabutan sanksi, id: ${id}`, _csrf: _csrf });
+}
+const logErroraddJawabanCabutSanksi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal menjawab pengajuan pencabutan sanksi, id: ${id}`, _csrf: _csrf });
+}
+
 export const bypassCabutSanksi = async (token, id) => {
 	try {
 		const res = await axios.put(`/sanksi/cabut-sanksi/bypass/${id}`);
-		await createLog(token, { aktivitas: `Berhasil melakukan bypass ke pencabutan sanksi, id: ${id}` });
+		logSuccessBypassCabutSanksi(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal  melakukan bypass ke pencabutan sanksi, id: ${id}` });
+		logErrorBypassCabutSanksi(token, id)
 		return false;
 	}
 };
+const logSuccessBypassCabutSanksi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil melakukan bypass ke pencabutan sanksi, id: ${id}`, _csrf: _csrf });
+}
+const logErrorBypassCabutSanksi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal melakukan bypass ke pencabutan sanksi, id: ${id}`, _csrf: _csrf });
+}

+ 14 - 2
actions/docPerbaikan.js

@@ -1,14 +1,26 @@
 import axios from "../config/axios";
 import { createLog } from "./log";
+import { getCsrf } from "./security";
 
 export const addDocPerbaikan = async (token, id, data) => {
 	try {
 		const res = await axios.post(`/sanksi/perbaikan/add/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil melakukan perbaikan dokumen, id: ${id}` });
+		logSuccessAddDocPerbaikan(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal melakukan perbaikan dokumen, id: ${id}` });
+		logErrorAddDocPerbaikan(token, id)
 		return false;
 	}
 };
+const logSuccessAddDocPerbaikan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil melakukan perbaikan dokumen, id: ${id}`, _csrf: _csrf });
+}
+
+const logErrorAddDocPerbaikan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal melakukan perbaikan dokumen, id: ${id}`, _csrf: _csrf });
+}

+ 26 - 4
actions/keberatan.js

@@ -1,26 +1,48 @@
 import axiosAPI from "../config/axios";
 import { createLog } from "./log";
+import { getCsrf } from "./security";
 
 export const addKeberatan = async (token, id, data) => {
 	try {
 		const res = await axiosAPI.post(`/sanksi/keberatan/create/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil mengajukan keberatan, id: ${id}` });
+		logSuccessAddKeberatan(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal mengajukan keberatan, id: ${id}` });
+		logErrorAddKeberatan(token, id)
 		return false;
 	}
 };
+const logSuccessAddKeberatan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil mengajukan keberatan, id: ${id}`, _csrf: _csrf });
+}
+const logErrorAddKeberatan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal mengajukan keberatan, id: ${id}`, _csrf: _csrf });
+}
 
 export const addJawabanKeberatan = async (token, id, data) => {
 	try {
 		const res = await axiosAPI.post(`/sanksi/keberatan/jawaban/create/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil menjawab pengajuan keberatan, id: ${id}` });
+		logSuccessAddJawabanKeberatan(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal menjawab pengajuan keberatan, id: ${id}` });
+		logErrorAddJawabanKeberatan(token, id)
 		return false;
 	}
 };
+
+const logSuccessAddJawabanKeberatan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil menjawab mengajukan keberatan, id: ${id}`, _csrf: _csrf });
+}
+const logErrorAddJawabanKeberatan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal menjawab mengajukan keberatan, id: ${id}`, _csrf: _csrf });
+}

+ 18 - 10
actions/pelaporan.js

@@ -74,11 +74,16 @@ export const getPelaporanPublic = async ({ number, noHp }) => {
 	}
 };
 
-export const createPelaporan = async (token, data, tokenCsrf) => {
-	const res = await axiosAPI.post(`/laporan/create?_csrf=${tokenCsrf}`, data, { headers: { Authorization: token } });
-	await createLog(token, { aktivitas: "Berhasil Membuat pelaporan" });
+export const createPelaporan = async (token, data, _csrf) => {
+	const res = await axiosAPI.post(`/laporan/create?_csrf=${_csrf}`, data, { headers: { Authorization: token } });
+	logCreatePelaporan(token)
 	return res.data;
 };
+const logCreatePelaporan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil Membuat pelaporan`, _csrf: _csrf });
+}
 
 // export const createLaporanPublic = async (data) => {
 // 	try {
@@ -90,9 +95,9 @@ export const createPelaporan = async (token, data, tokenCsrf) => {
 // 	}
 // };
 
-export const createLaporanPublic = async (token, data) => {
+export const createLaporanPublic = async (token, data, _csrf) => {
 	try {
-		const res = await axiosAPI.post("/public/laporan/create", data, { headers: { Authorization: token } });
+		const res = await axiosAPI.post(`/public/laporan/create?_csrf=${_csrf}`, data, { headers: { Authorization: token } });
 		return res.data;
 	} catch (error) {
 		console.log("error", error.response.data);
@@ -110,18 +115,21 @@ export const createLaporanPublic = async (token, data) => {
 // 	}
 // };
 
-export const updateLaporan = async (token, id, data) => {
+export const updateLaporan = async (token, id, data, _csrf) => {
 	try {
-		const res = await axiosAPI.put(`/laporan/update/${id}`, data, { headers: { Authorization: token } });
-		if (data.aktif === "false") await createLog(token, { aktivitas: `Berhasil menutup laporan, id: ${id}` });
-		await createLog(token, { aktivitas: `Berhasil mengubah data laporan, id: ${id}` });
+		const res = await axiosAPI.put(`/laporan/update/${id}?_csrf=${_csrf}`, data, { headers: { Authorization: token } });
+		if (data.aktif === "false") logUpdateLaporan(token, id);
 		return res.data;
 	} catch (error) {
 		console.log("error", error.response.data);
-		await createLog(token, { aktivitas: `Gagal mengubah data pelaporan, id: ${id}` });
 		return false;
 	}
 };
+const logUpdateLaporan = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil menutup laporan, id: ${id}`, _csrf: _csrf });
+}
 
 export const jumlahLaporan = async (token) => {
 	try {

+ 12 - 3
actions/pemeriksaan.js

@@ -1,8 +1,17 @@
 import axiosAPI from "../config/axios";
 import { createLog } from "./log";
 
-export const insertPemeriksaan = async (token, id, data) => {
-	const res = await axiosAPI.post(`/laporan/evaluasi/add/${id}`, data, { headers: { Authorization: token } });
-	await createLog(token, { aktivitas: `Berhasil menambah evaluasi, id: ${id}` });
+import { getCsrf } from "./security";
+
+export const insertPemeriksaan = async (token, id, data, _csrf) => {
+	const res = await axiosAPI.post(`/laporan/evaluasi/add/${id}?_csrf=${_csrf}`, data, { headers: { Authorization: token } });
+	// await createLog(token, { aktivitas: `Berhasil menambah evaluasi, id: ${id}` });
+	log(token, id)
 	return res.data;
 };
+const log = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil menambah evaluasi, id: ${id}`, _csrf: _csrf });
+
+}

+ 10 - 3
actions/penjadwalan.js

@@ -1,13 +1,20 @@
 import axios from "../config/axios";
 import { createLog } from "./log";
+import { getCsrf } from "./security";
 
-export const updateJadwal = async (token, id, data) => {
+export const updateJadwal = async (token, id, data, _csrf) => {
 	// try {
-	const res = await axios.put(`/laporan/jadwal/update/${id}`, data, { headers: { Authorization: token } });
-	await createLog(token, { aktivitas: `Berhasil menetapkan jadwal, id: ${id}` });
+	const res = await axios.put(`/laporan/jadwal/update/${id}?_csrf=${_csrf}`, data, { headers: { Authorization: token } });
+	logSuccessUpdateJadwal(token, id)
 	return res.data;
 	// } catch (error) {
 	// console.log("error", error);
 	// return false;
 	// }
 };
+const logSuccessUpdateJadwal = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil menetapkan jadwal, id: ${id}`, _csrf: _csrf });
+
+}

+ 4 - 1
actions/public.js

@@ -1,11 +1,14 @@
 import { get, post, del, put } from "../config/request";
 import axiosAPI from "../config/axios";
 import { createLog } from "./log";
+import { getCsrf } from "./security";
 
 
 export const addPesertaPleno = async (token, data) => {
+    const getToken = await getCsrf();
+    const _csrf = getToken.token;
     try {
-        const res = await axiosAPI.post('/public/sanksi/add-peserta-pleno', data, { headers: { Authorization: token } });
+        const res = await axiosAPI.post(`/public/sanksi/add-peserta-pleno?_csrf=${_csrf}`, data, { headers: { Authorization: token } });
         return res.data;
     } catch (error) {
         console.log("error", error.response.data);

+ 50 - 7
actions/sanksi.js

@@ -2,12 +2,19 @@ import axiosAPI from "../config/axios";
 import axios from "../config/axios";
 import { bypassCabutSanksi } from "./cabutSanksi";
 import { createLog } from "./log";
+import { getCsrf } from "./security";
 
 export const createSanksi = async (token, id, data, _csrf) => {
 	const res = await axiosAPI.post(`/sanksi/create/${id}?_csrf=${_csrf}`, data, { headers: { Authorization: token } });
-	await createLog(token, { aktivitas: `Berhasil melakukan penetapan sanksi, id: ${id}` });
+	logCreateSanksi(token, id)
 	return res.data;
 };
+const logCreateSanksi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil melakukan penetapan sanksi, id: ${id}`, _csrf: _csrf });
+
+}
 
 export const getSanksi = async (token, query = {}) => {
 	try {
@@ -61,35 +68,71 @@ export const getOneSanksi = async (token, id, query = {}) => {
 export const addRekomendasiDelegasi = async (token, id, data) => {
 	try {
 		const res = await axiosAPI.post(`/rekomendasi/add/${id}`, data, { headers: { Authorization: token } });
-		await createLog(token, { aktivitas: `Berhasil melakukan Rekomendasi Delegasi, id: ${id}` });
+		logSuccessAddRekomendasiDelegasi(token, id)
 		return res.data;
 	} catch (error) {
 		console.log("error", error);
-		await createLog(token, { aktivitas: `Gagal melakukan Rekomendasi Delegasi, id: ${id}` });
+		logErrorAddRekomendasiDelegasi(token, id)
 		return false;
 	}
 };
+const logSuccessAddRekomendasiDelegasi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil melakukan Rekomendasi Delegasi, id: ${id}`, _csrf: _csrf });
+
+}
+const logErrorAddRekomendasiDelegasi = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Gagal melakukan Rekomendasi Delegasi, id: ${id}`, _csrf: _csrf });
+
+}
 
 export const editTmt = async (token, id, data) => {
 	const res = await axios.put(`sanksi/tmt/update/${id}`, data, { headers: { Authorization: token } });
-	await createLog(token, { aktivitas: `Berhasil perpanjangan sanksi, id: ${id}` });
+	logEditTmt(token, id)
 	return res.data;
 };
+const logEditTmt = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil perpanjangan sanksi, id: ${id}`, _csrf: _csrf });
+
+}
 
 export const update = async (token, id, data) => {
 	const res = await axios.put(`sanksi/update/${id}`, data, { headers: { Authorization: token } });
-	await createLog(token, { aktivitas: `Berhasil Merubah Sanksi, id: ${id}` });
+	logUpdate(token, id)
 	return res.data;
 };
 
+const logUpdate = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil Merubah Sanksi, id: ${id}`, _csrf: _csrf });
+
+}
 export const updatePT = async (token, id, data) => {
 	const res = await axiosAPI.put(`/sanksi/update-pt/${id}`, data, { headers: { Authorization: token } });
-	await createLog(token, { aktivitas: `Berhasil mengubah status sanksi, id: ${id}` });
+	logUpdatePT(token, id)
 	return res.data;
 };
+const logUpdatePT = async (token, id) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil mengubah status sanksi, id: ${id}`, _csrf: _csrf });
+
+}
 
 export const removePesertaPleno = async (token, data) => {
 	const res = await axios.delete(`sanksi/remove-peserta-pleno/`, { headers: { Authorization: token }, data });
-	await createLog(token, { aktivitas: `Berhasil hapus peserta pleno` });
+	logRemovePesertaPleno(token)
 	return res.data;
 };
+const logRemovePesertaPleno = async (token) => {
+	const getToken = await getCsrf();
+	const _csrf = getToken.token;
+	await createLog(token, { aktivitas: `Berhasil hapus peserta pleno`, _csrf: _csrf });
+
+}

+ 2 - 2
actions/user.js

@@ -9,9 +9,9 @@ export const getPublicUser = async () => {
 	}
 };
 
-export const createPublicUser = async (data) => {
+export const createPublicUser = async (data, _csrf) => {
 	try {
-		const response = await axiosAPI.post("/public/user/create", data);
+		const response = await axiosAPI.post(`/public/user/create?_csrf=${_csrf}`, data);
 		return response.data;
 	} catch (error) {
 		if (error.response) return error.response.data;

+ 53 - 4
components/Extras/calendar.view.js

@@ -21,8 +21,11 @@ import { Formik, Form, Field, ErrorMessage } from "formik";
 import * as Yup from "yup";
 import Datetime from "react-datetime";
 import 'moment/locale/id';
+import { getCsrf } from "../../actions/security";
+import { createLog } from "../../actions/log";
 moment.locale('id')
 
+
 const status = [
 	{ value: "Ditindaklanjuti DIKTI", label: "Ditindaklanjuti DIKTI", className: "State-ACT" },
 	{ value: "Delegasi ke LLDIKTI", label: "Delegasi ke LLDIKTI", className: "State-ACT" },
@@ -122,19 +125,30 @@ class Calendar extends Component {
 		info.event.setProp("borderColor", styles.borderColor);
 		this.handleEventCalendar(info);
 	};
+	logSuccessUpdateJadwal = async () => {
+		const { query, token } = this.props;
+		const { id } = query;
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
+		await createLog(token, { aktivitas: `Berhasil menetapkan jadwal, id: ${id}`, _csrf: _csrf });
+
+	}
 
 	handleEventCalendar = async (data) => {
 		const { query, token } = this.props;
 		const { id } = query;
 		const { color, laporan } = this.state;
-
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
 		await toast.promise(
+
 			updateJadwal(token, id, {
 				judul: "No.Laporan " + laporan.data.no_laporan + " - " + data.judul,
 				dari_tanggal: data.dari_tanggal,
 				sampai_tanggal: data.sampai_tanggal,
 				warna: color,
-			}),
+			}, _csrf),
+
 			{
 				pending: "Loading",
 				success: "Success",
@@ -142,6 +156,22 @@ class Calendar extends Component {
 			}
 
 		);
+		// const toastid = toast.loading("Please wait...");
+		// const added = await updateJadwal(token, id, {
+		// 	judul: "No.Laporan " + laporan.data.no_laporan + " - " + data.judul,
+		// 	dari_tanggal: data.dari_tanggal,
+		// 	sampai_tanggal: data.sampai_tanggal,
+		// 	warna: color,
+		// }, _csrf)
+		// if (!added) {
+		// 	toast.update(toastid, { render: "Gagal menetapkan jadwal", type: "error", isLoading: false, autoClose: true, closeButton: true });
+		// } else {
+		// 	toast.update(toastid, { render: "Berhasil menetapkan jadwal", type: "success", isLoading: false, autoClose: true, closeButton: true });
+
+		// 	this.logSuccessUpdateJadwal()
+
+
+		// }
 		Router.push("/app/penjadwalan");
 		const dataLaporan = await getPelaporan(token, { jadwal: true });
 		this.setState({ dataLaporan });
@@ -154,8 +184,25 @@ class Calendar extends Component {
 	};
 
 	handleChangeSelect = (selectedOption) => this.setState({ selectedOption });
+	logUpdateLaporanSuccess = async () => {
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
+		const { token, query } = this.props;
+		const { id } = query;
+		await createLog(token, { aktivitas: `Berhasil mengubah data laporan, id: ${id}`, _csrf: _csrf });
+
+	}
+	logUpdateLaporanError = async () => {
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
+		const { token, query } = this.props;
+		const { id } = query;
+		await createLog(token, { aktivitas: `Berhasil mengubah data laporan, id: ${id}`, _csrf: _csrf });
+	}
 
 	handleSimpan = async (value) => {
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
 		const { token, query } = this.props;
 		const { id } = query;
 		let update = null;
@@ -164,18 +211,20 @@ class Calendar extends Component {
 			const data = { keterangan: value.keterangan };
 			if (value.status.value === this.getStatus()[1].value) {
 				data.change_role = "true";
-				update = await updateLaporan(token, id, data);
+				update = await updateLaporan(token, id, data, _csrf);
 				Router.push("/app/penjadwalan");
 			} else if (value.status.value === this.getStatus()[2].value) {
 				data.aktif = "false";
-				update = await updateLaporan(token, id, data);
+				update = await updateLaporan(token, id, data, _csrf);
 				Router.push("/app/penjadwalan");
 			}
 			if (!update) {
 				toast.update(toastid, { render: "Gagal simpan jadwal", type: "error", isLoading: false, autoClose: true, closeButton: true });
+				this.logUpdateLaporanError()
 
 			} else {
 				toast.update(toastid, { render: "Input jadwal berhasil", type: "success", isLoading: false, autoClose: true, closeButton: true });
+				this.logUpdateLaporanSuccess()
 				Router.push("/app/penjadwalan");
 			}
 			Router.push("/app/penjadwalan");

+ 4 - 2
components/Layout/Header.js

@@ -12,8 +12,8 @@ import * as actions from "../../store/actions/actions";
 import ToggleFullscreen from "../Common/ToggleFullscreen";
 import HeaderSearch from "./HeaderSearch";
 import { ToastContainer, toast } from "react-toastify";
-
 import "react-toastify/dist/ReactToastify.css";
+import { getCsrf } from "../../actions/security";
 
 class Header extends Component {
 	state = {
@@ -56,9 +56,11 @@ class Header extends Component {
 	};
 
 	handleLogout = async (e) => {
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
 		e.preventDefault();
 		await logout();
-		await createLog(this.props.token, { aktivitas: "Berhasil Logout" });
+		await createLog(this.props.token, { aktivitas: "Berhasil Logout", _csrf: _csrf });
 		this.props.tokenNull();
 		this.props.userNull();
 		// if (cek.success) {

+ 5 - 3
components/Main/Login.js

@@ -7,6 +7,7 @@ import { login, getUser } from "@/actions/auth";
 import { createLog } from "@/actions/log";
 import axiosAPI from "@/config/axios";
 import { getPT } from "@/actions/PT";
+import { getCsrf } from "../../actions/security";
 
 class Login extends Component {
   constructor(props) {
@@ -22,7 +23,6 @@ class Login extends Component {
       loading: false,
     };
   }
-
   /**
    * Validate input using onChange event
    * @param  {String} formName The name of the form in the state object
@@ -66,6 +66,8 @@ class Login extends Component {
       console.log(hasError ? "Form has errors. Check!" : "Form Submitted!");
       e.preventDefault();
       if (!hasError) {
+        const getTokenCsrf = await getCsrf();
+        const _csrf = getTokenCsrf.token;
         this.setState({ loading: true });
         const { username, password } = this.state.formLogin;
         const auth = await login(username, password);
@@ -74,11 +76,11 @@ class Login extends Component {
         axiosAPI.defaults.headers.common["Authorization"] = auth.data.token;
         if (auth.data.user.role.id === 2022) {
           Router.push({ pathname: "/pt/pemantauan" });
-          await createLog(auth.data.token, { aktivitas: "Berhasil Login" });
+          await createLog(auth.data.token, { aktivitas: "Berhasil Login", _csrf: _csrf });
           return;
         } else if ([2020, 2021, 2023].includes(auth.data.user.role.id)) {
           Router.push({ pathname: "/app/pemantauan" });
-          await createLog(auth.data.token, { aktivitas: "Berhasil Login" });
+          await createLog(auth.data.token, { aktivitas: "Berhasil Login", _csrf: _csrf });
           return;
         } else {
           this.setState({ error: "Akun tidak ada" });

+ 15 - 6
components/Pelaporan/InputData.js

@@ -11,6 +11,8 @@ import "react-toastify/dist/ReactToastify.css";
 import { Formik, Form, Field, ErrorMessage } from "formik";
 import * as Yup from "yup";
 import { getCsrf } from "../../actions/security";
+import { createLog } from "@/actions/log";
+
 
 let Dropzone = null;
 class DropzoneWrapper extends Component {
@@ -73,9 +75,8 @@ export class InputData extends Component {
 	}
 
 	componentDidMount = async () => {
-		const tokenCsrf = await getCsrf();
 		const pelanggaran = await getPelanggaranPublic();
-		this.setState({ pelanggaran, tokenCsrf });
+		this.setState({ pelanggaran });
 	};
 
 	optionsJenisPelanggaran = (pelanggaran) => {
@@ -131,9 +132,16 @@ export class InputData extends Component {
 			files: [],
 		});
 	};
-
+	createLog = async () => {
+		const { token } = this.props;
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
+		await createLog(token, { aktivitas: "Mengakses halaman Pelaporan", menu: "Pelaporan", _csrf: _csrf });
+	}
 	onSubmit = async (data) => {
 		const { token, query } = this.props;
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
 		const formdata = new FormData();
 		formdata.append("no_laporan", data.no_laporan);
 		formdata.append("pt_id", query.ptId);
@@ -142,13 +150,14 @@ export class InputData extends Component {
 		this.state.files.forEach((e) => {
 			formdata.append("dokumen", e);
 		});
-		const create = createPelaporan(token, formdata, this.state.tokenCsrf.token);
+		const create = createPelaporan(token, formdata, _csrf);
 
 		await toast.promise(create, {
 			pending: "Loading...",
 			success: "Berhasil buat laporan",
 			error: "Gagal buat laporan",
-		});
+		},
+			this.createLog());
 
 		Router.push({
 			pathname: "/app/pelaporan",
@@ -205,7 +214,7 @@ export class InputData extends Component {
 												this.handleChangeSelectMulti(e);
 												form.setFieldValue(
 													field.name,
-													e.map((e) => e.value)
+													e?.map((e) => e.value)
 												);
 											}}
 											options={pelanggaran.data ? this.optionsJenisPelanggaran(pelanggaran) : []}

+ 6 - 2
components/Pemeriksaan/InputEvaluasi.js

@@ -9,6 +9,8 @@ import { Formik, Form, Field, ErrorMessage } from "formik";
 import * as Yup from "yup";
 import { getOneLaporan, updateLaporan } from "@/actions/pelaporan";
 import { connect } from "react-redux";
+import { getCsrf } from "../../actions/security";
+
 
 const selectInstanceId = 1;
 const checkIfFilesAreTooBig = (files) => {
@@ -121,6 +123,8 @@ class InputEvaluasi extends Component {
 	};
 
 	onSubmit = async (data, { resetForm }) => {
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
 		const { token, query } = this.props;
 		const { id } = query;
 		const formdata = new FormData();
@@ -130,7 +134,7 @@ class InputEvaluasi extends Component {
 			formdata.append("dokumen", e);
 		});
 		if (this.state.delegasichecklist == true) {
-			await toast.promise(insertPemeriksaan(token, id, formdata), {
+			await toast.promise(insertPemeriksaan(token, id, formdata, _csrf), {
 				pending: "Loading",
 				success: "Success",
 				error: "Error",
@@ -142,7 +146,7 @@ class InputEvaluasi extends Component {
 			Router.push("/app/pemeriksaan");
 			update = await updateLaporan(token, id, data);
 		} else {
-			await toast.promise(insertPemeriksaan(token, id, formdata), {
+			await toast.promise(insertPemeriksaan(token, id, formdata, _csrf), {
 				pending: "Loading",
 				success: "Success",
 				error: "Error",

+ 1 - 0
components/Sanksi/BeritaAcara.js

@@ -233,6 +233,7 @@ class BeritaAcara extends Component {
     }
     render() {
         const { dataLaporan, dataSuratBA, dataPelanggaran } = this.props
+        console.log(dataLaporan)
         const { descPelanggaran, tanggal, setTanggal, temuanLain } = this.state
         return (
             <div>

+ 4 - 1
pages/app/banding/detail.js

@@ -23,6 +23,7 @@ import "react-datepicker/dist/react-datepicker.css";
 import id from 'date-fns/locale/id';
 import moment from "moment";
 import Datetime from "react-datetime";
+import { getCsrf } from "../../../actions/security";
 
 let Dropzone = null;
 class DropzoneWrapper extends Component {
@@ -95,8 +96,10 @@ class JawabanBanding extends Component {
 
 	componentDidMount = async () => {
 		const { query, token } = this.props;
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
 		const sanksi = await getOneSanksi(token, query.id, { banding: true });
-		await createLog(token, { aktivitas: `Mengakses halaman detail Banding dengan No. Sanksi ${sanksi.data.no_sanksi}`, menu: "Banding" });
+		await createLog(token, { aktivitas: `Mengakses halaman detail Banding dengan No. Sanksi ${sanksi.data.no_sanksi}`, menu: "Banding", _csrf: _csrf });
 		const pt = sanksi.data.laporan.pt;
 		this.setState({ sanksi, pt });
 	};

+ 4 - 1
pages/app/banding/index.js

@@ -7,6 +7,7 @@ import { getSanksi } from "@/actions/sanksi";
 import Loader from "@/components/Common/Loader";
 import { connect } from "react-redux";
 import { createLog } from "@/actions/log";
+import { getCsrf } from "../../../actions/security";
 
 class Banding extends Component {
 	constructor(props) {
@@ -18,7 +19,9 @@ class Banding extends Component {
 
 	componentDidMount = async () => {
 		const { token } = this.props;
-		await createLog(token, { aktivitas: "Mengakses halaman Banding", menu: "Banding" });
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
+		await createLog(token, { aktivitas: "Mengakses halaman Banding", menu: "Banding", _csrf: _csrf });
 		const sanksi = await getSanksi(token, { banding: true });
 		this.setState({ sanksi });
 	};

+ 4 - 1
pages/app/keberatan/detail.js

@@ -23,6 +23,7 @@ import "react-datepicker/dist/react-datepicker.css";
 import id from 'date-fns/locale/id';
 import moment from "moment";
 import Datetime from "react-datetime";
+import { getCsrf } from "../../../actions/security";
 
 
 let Dropzone = null;
@@ -101,7 +102,9 @@ class DetailKeberatan extends Component {
 	componentDidMount = async () => {
 		const { query, token } = this.props;
 		const sanksi = await getOneSanksi(token, query.id);
-		await createLog(token, { aktivitas: `Mengakses halaman detail Keberatan dengan No. Sanksi ${sanksi.data.no_sanksi}`, menu: "Keberatan" });
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
+		await createLog(token, { aktivitas: `Mengakses halaman detail Keberatan dengan No. Sanksi ${sanksi.data.no_sanksi}`, menu: "Keberatan", _csrf: _csrf });
 		const pt = sanksi.data.laporan.pt;
 		this.setState({ sanksi, pt });
 	};

+ 4 - 1
pages/app/keberatan/index.js

@@ -7,6 +7,7 @@ import { getSanksi } from "@/actions/sanksi";
 import { connect } from "react-redux";
 import Loader from "@/components/Common/Loader";
 import { createLog } from "@/actions/log";
+import { getCsrf } from "../../../actions/security";
 
 class Keberatan extends Component {
 	constructor(props) {
@@ -18,7 +19,9 @@ class Keberatan extends Component {
 
 	componentDidMount = async () => {
 		const { token } = this.props;
-		await createLog(token, { aktivitas: "Mengakses halaman Keberatan", menu: "Keberatan" });
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
+		await createLog(token, { aktivitas: "Mengakses halaman Keberatan", menu: "Keberatan", _csrf: _csrf });
 		const sanksi = await getSanksi(token, { keberatan: true });
 		this.setState({ sanksi });
 	};

+ 5 - 1
pages/app/laporan-delegasi/detail.js

@@ -12,6 +12,8 @@ import { connect } from "react-redux";
 import Scrollable from "@/components/Common/Scrollable";
 import Timeline from "@/components/Main/Timeline";
 import { createLog } from "@/actions/log";
+import { getCsrf } from "../../../actions/security";
+
 
 class DetailPelaporan extends Component {
 	constructor(props) {
@@ -28,8 +30,10 @@ class DetailPelaporan extends Component {
 
 	componentDidMount = async () => {
 		const { token, query } = this.props;
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
 		const pelaporan = await getOneLaporan(this.props.token, query.id + "?delegasi=true&?aktif=false");
-		await createLog(token, { aktivitas: `Mengakses halaman detail Laporan Delegasi dengan No. Laporan ${pelaporan.data.no_laporan}`, menu: "Laporan Delegasi" });
+		await createLog(token, { aktivitas: `Mengakses halaman detail Laporan Delegasi dengan No. Laporan ${pelaporan.data.no_laporan}`, menu: "Laporan Delegasi", _csrf: _csrf });
 		const pemantauan = await getLog(this.props.token, query.id + "?delegasi=true&asc=true");
 		pemantauan.data = pemantauan.data.filter((e) => e.action != "CREATE LAPORAN");
 		this.setState({ pelaporan, pemantauan });

+ 5 - 1
pages/app/laporan-delegasi/index.js

@@ -10,6 +10,8 @@ import Loader from "@/components/Common/Loader";
 import Router from "next/router";
 import { createLog } from "@/actions/log";
 import swal from "sweetalert2";
+import { getCsrf } from "../../../actions/security";
+
 
 
 class Pelaporan extends Component {
@@ -24,7 +26,9 @@ class Pelaporan extends Component {
 
 	componentDidMount = async () => {
 		const { token } = this.props;
-		await createLog(token, { aktivitas: "Mengakses halaman Laporan Delegasi", menu: "Laporan Delegasi" });
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
+		await createLog(token, { aktivitas: "Mengakses halaman Laporan Delegasi", menu: "Laporan Delegasi", _csrf: _csrf });
 		const pelaporan = await getPelaporan(this.props.token, { delegasi: true });
 		const graph = await getGraph(this.props.token, { jumlahLaporan: true });
 		this.setState({ pelaporan, graph });

+ 4 - 1
pages/app/pelaporan/detail.js

@@ -9,6 +9,7 @@ import { Row, Col, Card, Button, CardBody } from "reactstrap";
 import Loader from "@/components/Common/Loader";
 import { connect } from "react-redux";
 import { createLog } from "@/actions/log";
+import { getCsrf } from "../../../actions/security";
 
 class DetailPelaporan extends Component {
 	constructor(props) {
@@ -25,7 +26,9 @@ class DetailPelaporan extends Component {
 	componentDidMount = async () => {
 		const { token, query } = this.props;
 		const pelaporan = await getOneLaporan(this.props.token, query.id);
-		await createLog(token, { aktivitas: `Mengakses halaman detail Pelaporan dengan No. Laporan ${pelaporan.data.no_laporan}`, menu: "Pelaporan" });
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
+		await createLog(token, { aktivitas: `Mengakses halaman detail Pelaporan dengan No. Laporan ${pelaporan.data.no_laporan}`, menu: "Pelaporan", _csrf: _csrf });
 		this.setState({ pelaporan });
 	};
 

+ 3 - 3
pages/app/pelaporan/index.js

@@ -26,9 +26,9 @@ class Pelaporan extends Component {
 
 	componentDidMount = async () => {
 		const { token } = this.props;
-		const _csrf = await getCsrf();
-		const tokenCsrf = _csrf.token;
-		await createLog(token, { aktivitas: "Mengakses halaman Pelaporan", menu: "Pelaporan", _csrf: tokenCsrf });
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
+		await createLog(token, { aktivitas: "Mengakses halaman Pelaporan", menu: "Pelaporan", _csrf: _csrf });
 		const pelaporan = await getPelaporan(this.props.token);
 		const graph = await getGraph(this.props.token, {
 			laporanTahun: true,

+ 4 - 1
pages/app/pelaporan/new.js

@@ -9,6 +9,7 @@ import ContentWrapper from "@/components/Layout/ContentWrapper";
 import { Row, Col, Card, CardHeader, CardBody, Button } from "reactstrap";
 import Loader from "@/components/Common/Loader";
 import { createLog } from "@/actions/log";
+import { getCsrf } from "../../../actions/security";
 
 class PelaporanNew extends Component {
 	constructor(props) {
@@ -23,9 +24,11 @@ class PelaporanNew extends Component {
 	};
 
 	componentDidMount = async () => {
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
 		const { query, token } = this.props;
 		const pt = await getOnePT(token, query.ptId);
-		await createLog(token, { aktivitas: `Mengakses halaman Buat Pelaporan untuk ${pt.data.nama}`, menu: "Pelaporan" });
+		await createLog(token, { aktivitas: `Mengakses halaman Buat Pelaporan untuk ${pt.data.nama}`, menu: "Pelaporan", _csrf: _csrf });
 		this.setState({ pt });
 	};
 

+ 5 - 2
pages/app/pelaporan/search.js

@@ -9,6 +9,7 @@ import "react-datetime/css/react-datetime.css";
 import { connect } from "react-redux";
 import Loader from "@/components/Common/Loader";
 import { createLog } from "@/actions/log";
+import { getCsrf } from "../../../actions/security";
 
 var pembina = [];
 const selectInstanceId = 1;
@@ -49,9 +50,11 @@ class Search extends Component {
 	};
 
 	handleClick = async (e, PT_ID, pt_name) => {
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
 		e.preventDefault();
 		const { token } = this.props;
-		await createLog(token, { aktivitas: `Mencari ${pt_name} untuk Pembuatan Laporan`, menu: "Pelaporan" });
+		await createLog(token, { aktivitas: `Mencari ${pt_name} untuk Pembuatan Laporan`, menu: "Pelaporan", _csrf: _csrf });
 		Router.push({
 			pathname: "/app/pelaporan/new",
 			query: { ptId: PT_ID },
@@ -131,7 +134,7 @@ class Search extends Component {
 				<div className="content-heading">
 					<div className="font-color-white">
 						Pelaporan
-						<div className="font-color-white" style={{ fontSize:"12px", marginTop:"3px" }}>Pilih Perguruan Tinggi</div>
+						<div className="font-color-white" style={{ fontSize: "12px", marginTop: "3px" }}>Pilih Perguruan Tinggi</div>
 					</div>
 					<div className="ml-auto">
 						<Link href="/app/pelaporan">

+ 6 - 4
pages/app/sanksi/proses.js

@@ -50,15 +50,12 @@ class ProsesSanksi extends Component {
 		const { query, token } = this.props;
 		const { id } = query;
 		const pelaporan = await getOneLaporan(token, id);
-		const getToken = await getCsrf();
-		const _csrf = getToken.token;
 		const { data: listSanksi } = await getPelanggaranSanksi(token)
 		const getDataSave = await getAutoSave({ id, laporan: true });
 		const autoSaveDataPelanggaran = getDataSave.data?.PenetapanSanksi?.dataPelanggaran;
 		const activeStep = getDataSave.data?.PenetapanSanksi?.activeStep
 		this.setState({ pelaporan, listSanksi, activeStep: activeStep || "1" });
 		this.setState({ dataPelanggaran: autoSaveDataPelanggaran })
-		this.setState({ _csrf })
 	};
 
 
@@ -70,6 +67,8 @@ class ProsesSanksi extends Component {
 		await inputAutoSave({ data: { PenetapanSanksi: { dataSuratBA, dataUpload, dataPelanggaran: data, activeStep } }, token, id, laporan: true })
 	}
 	done = async (e) => {
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
 		const toastid = toast.loading("Please wait...");
 		this.setState({
 			loading: true
@@ -101,7 +100,7 @@ class ProsesSanksi extends Component {
 			// 		formdata.append("berita_acara", e);
 			// 	});
 			// }
-			await createSanksi(token, id, formdata, this.state._csrf);
+			await createSanksi(token, id, formdata, _csrf);
 
 			toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
 			Router.push({
@@ -114,6 +113,9 @@ class ProsesSanksi extends Component {
 
 
 	handleDelegasi = async (data) => {
+
+		const getToken = await getCsrf();
+		const _csrf = getToken.token;
 		const { token, query } = this.props;
 		const { id } = query;
 		let update = null;

+ 4 - 1
pages/app/tuntas/detail.js

@@ -9,6 +9,7 @@ import { Row, Col, Card, Button, CardBody } from "reactstrap";
 import Loader from "@/components/Common/Loader";
 import { connect } from "react-redux";
 import { createLog } from "@/actions/log";
+import { getCsrf } from "../../../actions/security";
 
 class DetailPelaporan extends Component {
 	constructor(props) {
@@ -24,8 +25,10 @@ class DetailPelaporan extends Component {
 
 	componentDidMount = async () => {
 		const { token, query } = this.props;
+		const getTokenCsrf = await getCsrf();
+		const _csrf = getTokenCsrf.token;
 		const pelaporan = await getOneLaporan(this.props.token, query.id + "?aktif=false");
-		await createLog(token, { aktivitas: `Mengakses halaman detail Pelaporan Tuntas dengan No. Laporan ${pelaporan.data.no_laporan}`, menu: "Pelaporan" });
+		await createLog(token, { aktivitas: `Mengakses halaman detail Pelaporan Tuntas dengan No. Laporan ${pelaporan.data.no_laporan}`, menu: "Pelaporan", _csrf: _csrf });
 		this.setState({ pelaporan });
 	};
 

+ 10 - 4
pages/laporan/new/index.js

@@ -37,7 +37,7 @@ import { ToastContainer, toast } from "react-toastify";
 import { Formik, Form, Field, ErrorMessage } from "formik";
 import * as Yup from "yup";
 import swal from "sweetalert2";
-
+import { getCsrf } from "../../../actions/security";
 import "react-toastify/dist/ReactToastify.css";
 
 const checkIfFilesAreTooBig = (files) => {
@@ -211,6 +211,8 @@ class App extends Component {
   };
 
   handleKirim = async (data, { resetForm }) => {
+    const getToken = await getCsrf();
+    const _csrf = getToken.token;
     const formdata = new FormData();
     formdata.append("no_laporan", data.no_laporan);
     formdata.append("pt_id", data.pt_id);
@@ -231,7 +233,7 @@ class App extends Component {
 
     const toastid = toast.loading("Please wait...");
 
-    const success = await createLaporanPublic(formdata);
+    const success = await createLaporanPublic(formdata, _csrf);
     if (!success) {
       swal.fire({
         title: "Data tidak berhasil dikirim",
@@ -249,6 +251,8 @@ class App extends Component {
   };
 
   createLaporan = async (token, kode = "") => {
+    const getToken = await getCsrf();
+    const _csrf = getToken.token;
     const data = this.state.data;
     const formdata = new FormData();
     formdata.append("pt_id", data.pt_id);
@@ -264,7 +268,7 @@ class App extends Component {
     }
 
     this.setState({ loading: true });
-    const success = await createLaporanPublic(token, formdata);
+    const success = await createLaporanPublic(token, formdata, _csrf);
     if (!success) {
       swal.fire({
         title: "Kode verifikasi salah",
@@ -286,6 +290,8 @@ class App extends Component {
   };
 
   createUser = async (data) => {
+    const getToken = await getCsrf();
+    const _csrf = getToken.token;
     const formdata = new FormData();
     formdata.append("no_laporan", data.no_laporan);
     formdata.append("pt_id", data.pt_id);
@@ -295,7 +301,7 @@ class App extends Component {
     if (data.alamat) formdata.append("alamat", data.alamat);
     formdata.append("is_private", data.is_private);
     if (data.foto.length > 0) formdata.append("foto", data.foto[0]);
-    return await createPublicUser(formdata);
+    return await createPublicUser(formdata, _csrf);
   };
 
   render() {