Compare commits
No commits in common. "8bdb293d9d8a6ad27403453539dfe3a2f9c7f43b" and "cd22e15d940ac5f5a1590d54ea49eaf39e1c7ad8" have entirely different histories.
8bdb293d9d
...
cd22e15d94
|
|
@ -1,7 +1,7 @@
|
||||||
export const authAPI = {
|
export const authAPI = {
|
||||||
csrfGenerate: "",
|
// csrfGenerate: "users/auth/csrf/",
|
||||||
login: "auth/token/",
|
login: "users/login/",
|
||||||
refresh: "auth/token/refresh/",
|
refresh: "users/token/refresh/",
|
||||||
logout: "auth/logout/",
|
// logout: "users/auth/logout/",
|
||||||
self: "users/self/",
|
self: "users/self/",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
export const departmentAPI = "dartachalani/department/"
|
|
||||||
export const categoryAPI = "dartachalani/documentcategory/"
|
|
||||||
|
|
@ -12,7 +12,7 @@ export const useAuth = defineStore("auth", {
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
} as LoginPayload,
|
} as LoginPayload,
|
||||||
token: localStorage.getItem("access_token") || (null as null | string),
|
token: null as null | string,
|
||||||
loginError: false,
|
loginError: false,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
@ -23,41 +23,22 @@ export const useAuth = defineStore("auth", {
|
||||||
getLoginError(state) {
|
getLoginError(state) {
|
||||||
return state.loginError;
|
return state.loginError;
|
||||||
},
|
},
|
||||||
isAuthenticated(state){
|
|
||||||
return !!state.token
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async csrfGenerate() {
|
async csrfGenerate() {
|
||||||
|
try {
|
||||||
return;
|
await api.get(authAPI.csrfGenerate);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async login() {
|
async login() {
|
||||||
|
|
||||||
const userStore = useUser();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await api.post(authAPI.login, this.loginDetails);
|
// const response = await api.post(authAPI.login, this.loginDetails);
|
||||||
|
await api.post(authAPI.login, this.loginDetails);
|
||||||
const accessToken = response.data.access;
|
Toast.success("Logged in successfully.");
|
||||||
const refreshToken = response.data.refresh
|
router.push({ name: "dashboard" });
|
||||||
|
|
||||||
if(accessToken){
|
|
||||||
this.token = accessToken;
|
|
||||||
localStorage.setItem("access_token", accessToken);
|
|
||||||
localStorage.setItem("refresh_token", refreshToken);
|
|
||||||
|
|
||||||
api.defaults.headers.common["Authorization"] = `Bearer ${accessToken}`;
|
|
||||||
|
|
||||||
await userStore.fetchUserDetail();
|
|
||||||
Toast.success("Logged in Successfully")
|
|
||||||
router.push({name: "dashboard"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// await api.post(authAPI.login, this.loginDetails);
|
|
||||||
// Toast.success("Logged in successfully.");
|
|
||||||
// router.push({ name: "dashboard" });
|
|
||||||
} catch {
|
} catch {
|
||||||
Toast.error("Unable to login!");
|
Toast.error("Unable to login!");
|
||||||
this.hasLoginError();
|
this.hasLoginError();
|
||||||
|
|
@ -66,40 +47,25 @@ export const useAuth = defineStore("auth", {
|
||||||
async logout() {
|
async logout() {
|
||||||
const userStore = useUser();
|
const userStore = useUser();
|
||||||
try {
|
try {
|
||||||
// await api.post(authAPI.logout);
|
await api.post(authAPI.logout);
|
||||||
userStore.$reset();
|
userStore.$reset();
|
||||||
this.loginDetails.username = "";
|
this.loginDetails.username = "";
|
||||||
this.loginDetails.password = "";
|
this.loginDetails.password = "";
|
||||||
this.token = null;
|
this.token = null;
|
||||||
|
|
||||||
localStorage.removeItem("access_token")
|
|
||||||
localStorage.removeItem("refresh_token")
|
|
||||||
delete api.defaults.headers.common["Authorization"];
|
|
||||||
Toast.success("Logged out successfully.");
|
Toast.success("Logged out successfully.");
|
||||||
router.push({ name: "login" });
|
router.push({ name: "login" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
localStorage.clear()
|
|
||||||
router.push({ name: "login" });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async refreshToken() {
|
async refreshToken() {
|
||||||
try {
|
try {
|
||||||
const refresh = localStorage.getItem("refresh_token");
|
await api.post(authAPI.refresh);
|
||||||
if (!refresh) return false;
|
// if (response.data) {
|
||||||
|
// this.token = response.data.data.access;
|
||||||
const response = await api.post(authAPI.refresh, { refresh: refresh});
|
// }
|
||||||
|
return true;
|
||||||
if (response.data && response.data.access){
|
|
||||||
const newAccess = response.data.access
|
|
||||||
this.token = newAccess
|
|
||||||
localStorage.setItem("access_token", newAccess);
|
|
||||||
api.defaults.headers.common["Authorization"] = `Bearer ${newAccess}`;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} catch {
|
} catch {
|
||||||
this.logout();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ export const useUser = defineStore("user", {
|
||||||
actions: {
|
actions: {
|
||||||
async fetchUserDetail() {
|
async fetchUserDetail() {
|
||||||
try {
|
try {
|
||||||
const response = await api.get(authAPI.self);
|
// const response = await api.get(authAPI.self);
|
||||||
this.user = response.data.data;
|
// this.user = response.data.data;
|
||||||
this.isAuthenticated = true;
|
this.isAuthenticated = true;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error.response.status == 403) {
|
if (error.response.status == 403) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
label="name"
|
label="name"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
placeholder="Select Department"
|
placeholder="Select Department"
|
||||||
:loading="isDepartmentLoading"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
|
|
@ -29,7 +28,7 @@
|
||||||
</label>
|
</label>
|
||||||
<Multiselect
|
<Multiselect
|
||||||
v-model="formData.documentCategory"
|
v-model="formData.documentCategory"
|
||||||
:options="categories"
|
:options="documentCategories"
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
:searchable="true"
|
:searchable="true"
|
||||||
:allow-empty="false"
|
:allow-empty="false"
|
||||||
|
|
@ -37,7 +36,6 @@
|
||||||
label="name"
|
label="name"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
placeholder="Select Category"
|
placeholder="Select Category"
|
||||||
:loading="isCategoryLoading"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
|
|
@ -162,25 +160,15 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, onBeforeMount } from "vue";
|
import { ref, reactive } from "vue";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { createOverlayStore } from "@/stores/OverlayStore";
|
import { createOverlayStore } from "@/stores/OverlayStore";
|
||||||
import Multiselect from "vue-multiselect";
|
import Multiselect from "vue-multiselect";
|
||||||
import { departmentAPI, categoryAPI } from "@/core/endpoints/dartachalani";
|
|
||||||
import { createGenericStore } from "@/stores/GenericStore";
|
|
||||||
|
|
||||||
const ChalaniTowserStore = createOverlayStore("chalani-towser")();
|
const ChalaniTowserStore = createOverlayStore("chalani-towser")();
|
||||||
const { show } = storeToRefs(ChalaniTowserStore);
|
const { show } = storeToRefs(ChalaniTowserStore);
|
||||||
|
|
||||||
const departmentStore = createGenericStore("departments")();
|
|
||||||
const { itemList: departments } = storeToRefs(departmentStore);
|
|
||||||
|
|
||||||
const categoryStore = createGenericStore("document-category")();
|
|
||||||
const {itemList: categories } = storeToRefs(categoryStore);
|
|
||||||
|
|
||||||
const fileInputRef = ref<HTMLInputElement | null>(null);
|
const fileInputRef = ref<HTMLInputElement | null>(null);
|
||||||
const isDepartmentLoading = ref(false);
|
|
||||||
const isCategoryLoading = ref(false);
|
|
||||||
|
|
||||||
const towser = ref({
|
const towser = ref({
|
||||||
title: [{ name: "Chalani", link: "#" }, { name: "Create" }],
|
title: [{ name: "Chalani", link: "#" }, { name: "Create" }],
|
||||||
|
|
@ -210,19 +198,20 @@ const formData = reactive({
|
||||||
attachments: [] as File[],
|
attachments: [] as File[],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const departments = ref([
|
||||||
|
{ id: 1, name: "Administration" },
|
||||||
|
{ id: 2, name: "HR" },
|
||||||
|
]);
|
||||||
|
|
||||||
|
const documentCategories = ref([
|
||||||
|
{ id: 1, name: "Confidential" },
|
||||||
|
{ id: 2, name: "Public" },
|
||||||
|
]);
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
formData.department = null
|
|
||||||
formData.documentCategory = null
|
|
||||||
formData.documentNumber = "";
|
formData.documentNumber = "";
|
||||||
formData.subject = "";
|
formData.subject = "";
|
||||||
formData.body = "";
|
|
||||||
formData.recipientName = "";
|
|
||||||
formData.attachments = [];
|
formData.attachments = [];
|
||||||
formData.recipientContact = "";
|
|
||||||
formData.recipientAddress = "";
|
|
||||||
formData.issuedDate = "";
|
|
||||||
formData.dispatchDate = "";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
|
|
@ -253,16 +242,4 @@ const handleFileUpload = (event: Event) => {
|
||||||
formData.attachments = [...formData.attachments, ...Array.from(target.files)];
|
formData.attachments = [...formData.attachments, ...Array.from(target.files)];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
</script>
|
||||||
onMounted(()=>{
|
|
||||||
departmentStore.fetchList(departmentAPI, {}, isDepartmentLoading);
|
|
||||||
categoryStore.fetchList(categoryAPI, {}, isCategoryLoading);
|
|
||||||
})
|
|
||||||
|
|
||||||
onBeforeMount(()=>{
|
|
||||||
departmentStore.$reset();
|
|
||||||
departmentStore.$dispose();
|
|
||||||
categoryStore.$reset();
|
|
||||||
categoryStore.$dispose();
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, onBeforeMount } from "vue";
|
import { ref, reactive } from "vue";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { createGenericStore } from "@/stores/GenericStore";
|
import { createGenericStore } from "@/stores/GenericStore";
|
||||||
import { createOverlayStore } from "@/stores/OverlayStore";
|
import { createOverlayStore } from "@/stores/OverlayStore";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user