api saveLog
This commit is contained in:
parent
146dcb9028
commit
3f5b7356f1
2 changed files with 42 additions and 6 deletions
|
|
@ -1,7 +1,8 @@
|
|||
import env from "./index";
|
||||
const org = `${env.API_URI}/org`;
|
||||
// const log = `${env.API_URI}/log`;
|
||||
const ssoLog = `${env.API_URI}/org/keycloak/log/sso`;
|
||||
|
||||
export default {
|
||||
org,
|
||||
ssoLog,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import screen3 from "@/assets/screen3.png";
|
|||
import screen4 from "@/assets/screen4.png";
|
||||
|
||||
import type { DateCards } from "@/interface/index/Main";
|
||||
import http from "@/plugins/http";
|
||||
|
||||
const $q = useQuasar();
|
||||
|
||||
|
|
@ -109,11 +110,44 @@ async function goPage(sys: string, url: string) {
|
|||
}
|
||||
|
||||
async function logout() {
|
||||
await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY");
|
||||
await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH");
|
||||
$q.dialog({
|
||||
component: CustomComponent,
|
||||
componentProps: {
|
||||
title: `ยืนยันการออกจากระบบ`,
|
||||
message: "ต้องการออกจากระบบใช่หรือไม่?",
|
||||
icon: "info",
|
||||
color: "public",
|
||||
},
|
||||
cancel: true,
|
||||
persistent: true,
|
||||
}).onOk(async () => {
|
||||
await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY");
|
||||
await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH");
|
||||
// ยิง logout เข้าระบบ
|
||||
await postSaveLog("ออกจากระบบ", token.value);
|
||||
window.location.href = `${config.API.URL_SSO}`;
|
||||
});
|
||||
}
|
||||
|
||||
// ยิง logout เข้าระบบ
|
||||
window.location.href = `${config.API.URL_SSO}`;
|
||||
async function postSaveLog(type: string, token: any) {
|
||||
await axios
|
||||
.post(
|
||||
config.API.ssoLog,
|
||||
{ text: type },
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
accept: "application/json",
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((res) => {
|
||||
console.log("res:", res.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error:", err);
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
|
|
@ -138,11 +172,12 @@ onMounted(async () => {
|
|||
withCredentials: true, // Include cookies with the request
|
||||
}
|
||||
)
|
||||
.then((res: any) => {
|
||||
.then(async (res: any) => {
|
||||
if (res.status === 200) {
|
||||
setCookie("BMAHRIS_KEYCLOAK_IDENTITY", res.data.access_token, 1);
|
||||
setCookie("BMAHRIS_KEYCLOAK_REFRESH", res.data.refresh_token, 1);
|
||||
// ยิง log เข้าระบบ
|
||||
await postSaveLog("เข้าสู่ระบบ", res.data.access_token);
|
||||
}
|
||||
})
|
||||
.catch((err: any) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue