api login v3

This commit is contained in:
Sas Andy
2024-08-14 08:22:51 +07:00
parent f8ff853818
commit 83c805b4a7
6 changed files with 123 additions and 25 deletions

View File

@@ -37,15 +37,17 @@
</p> </p>
</v-sheet> </v-sheet>
</div> </div>
<!-- bg-primary-lighten text-primary -->
<!-- icon="mdi-information-slab-circle-outline" -->
<v-alert <v-alert
color="primary"
density="compact" density="compact"
type="info" :text="alert.message"
style="width: 100% !important;" :type="alert.type"
class="bg-primary-lighten text-primary mt-4 mb-3 w-100" class="mt-4 mb-3 w-100"
text="Enter the registered account" variant="tonal"
> >
</v-alert> </v-alert>
<v-text-field <v-text-field
class="mt-3" class="mt-3"
v-model="email" v-model="email"
@@ -87,7 +89,10 @@
> >
{{ $t("message.login") }} {{ $t("message.login") }}
<template v-slot:loader> <template v-slot:loader>
<v-progress-linear indeterminate></v-progress-linear> <!-- <v-progress-linear indeterminate></v-progress-linear> -->
<v-progress-circular
indeterminate
></v-progress-circular>
</template> </template>
</v-btn> </v-btn>
</div> </div>
@@ -111,8 +116,11 @@
}, },
computed: { computed: {
// Akses state dari store // Akses state dari store
count() { loading() {
return this.$store.state.login.count; return this.$store.state.login.loading;
},
alert() {
return this.$store.state.login.alert;
}, },
email: { email: {
get() { get() {
@@ -133,6 +141,9 @@
}, },
methods: { methods: {
// Dispatch action ke store // Dispatch action ke store
login() {
this.$store.dispatch("login/login");
},
increment() { increment() {
this.$store.dispatch("increment"); this.$store.dispatch("increment");
}, },

View File

@@ -18,6 +18,7 @@
"mobile-component": MobileComponent, "mobile-component": MobileComponent,
"dekstop-component": DekstopComponent, "dekstop-component": DekstopComponent,
}, },
mounted() {},
data() { data() {
return { return {
visible: false, visible: false,

View File

@@ -27,12 +27,11 @@
</v-sheet> </v-sheet>
</div> </div>
<v-alert <v-alert
color="primary"
density="compact" density="compact"
type="info" :text="alert.message"
style="width: 100% !important;" :type="alert.type"
class="bg-primary-lighten text-primary mt-4 mb-3 w-100" class="mt-4 mb-3 w-100"
text="Enter the registered account" variant="tonal"
> >
</v-alert> </v-alert>
<v-text-field <v-text-field
@@ -76,7 +75,7 @@
> >
{{ $t("message.login") }} {{ $t("message.login") }}
<template v-slot:loader> <template v-slot:loader>
<v-progress-linear indeterminate></v-progress-linear> <v-progress-circular indeterminate></v-progress-circular>
</template> </template>
</v-btn> </v-btn>
</div> </div>
@@ -96,8 +95,11 @@
}, },
computed: { computed: {
// Akses state dari store // Akses state dari store
count() { loading() {
return this.$store.state.login.count; return this.$store.state.login.loading;
},
alert() {
return this.$store.state.login.alert;
}, },
email: { email: {
get() { get() {
@@ -118,6 +120,9 @@
}, },
methods: { methods: {
// Dispatch action ke store // Dispatch action ke store
login() {
this.$store.dispatch("login/login");
},
increment() { increment() {
this.$store.dispatch("increment"); this.$store.dispatch("increment");
}, },

View File

@@ -28,6 +28,7 @@
<script src="../libraries/axios.js"></script> <script src="../libraries/axios.js"></script>
<script src="../globalscript/theme.js"></script> <script src="../globalscript/theme.js"></script>
<script src="../globalscript/global.js"></script>
<!-- loader single file component --> <!-- loader single file component -->
<script src="../libraries/vue3-sfc-loader.js"></script> <script src="../libraries/vue3-sfc-loader.js"></script>
<script src="./language.js"></script> <script src="./language.js"></script>
@@ -36,11 +37,12 @@
const { loadModule } = window["vue3-sfc-loader"]; const { loadModule } = window["vue3-sfc-loader"];
import login from "./modules/login.js"; import login from "./modules/login.js";
const store = Vuex.createStore({ import system from "../globalstore/globalstore.js";
modules: {
login: login, // if (one_token()) {
}, // let usr = JSON.parse(localStorage.getItem("user"));
}); // location.replace("/" + usr.M_UserGroupDashboard);
// }
const options = { const options = {
moduleCache: { moduleCache: {
vue: Vue, vue: Vue,
@@ -69,7 +71,13 @@
fallbackLocale: "en", // Set fallback locale fallbackLocale: "en", // Set fallback locale
messages, // Set locale messages messages, // Set locale messages
}); });
window.i18n = i18n;
const store = Vuex.createStore({
modules: {
system: system,
login: login,
},
});
// Vue App // Vue App
const app = Vue.createApp({ const app = Vue.createApp({
data() { data() {

View File

@@ -9,6 +9,9 @@ var CustomMessages = {
forgotPassword: "Forgot password?", forgotPassword: "Forgot password?",
placeholderEmail: "Enter your email", placeholderEmail: "Enter your email",
placeholderPassword: "Enter your password", placeholderPassword: "Enter your password",
msgInfo: 'Enter the registered account',
errorQuery: "Error get data",
invalid: "Invalid username / password"
}, },
}, },
id: { id: {
@@ -21,6 +24,9 @@ var CustomMessages = {
forgotPassword: "Lupa kata sandi?", forgotPassword: "Lupa kata sandi?",
placeholderEmail: "Isikan email anda", placeholderEmail: "Isikan email anda",
placeholderPassword: "Isikan kata sandi anda", placeholderPassword: "Isikan kata sandi anda",
msgInfo: "Masukkan akun terdaftar",
errorQuery: "Gagal mendapatkan data",
invalid: "Nama pengguna / kata sandi tidak valid"
}, },
}, },
}; };

View File

@@ -1,6 +1,8 @@
// const URL = "/westone-api/v1/system/auth"; // const URL = "/westone-api/v1/system/auth";
const URL = "https://devcpone.aplikasi.web.id/one-api/v1/system/auth/";
const URL = "https://devcpone.aplikasi.web.id/westone-api/v1/system/auth/";
const store = { const store = {
namespaced: true, namespaced: true,
state() { state() {
@@ -9,7 +11,15 @@ const store = {
data: null, data: null,
email: "", email: "",
password: "", password: "",
dialog_success: false dialog_success: false,
loading: false,
errorMessage: "",
iin: window.i18n.global.t('message.login'),
alert: {
show: false,
type: 'info',
message: window.i18n.global.t('message.msgInfo')
}
}; };
}, },
mutations: { mutations: {
@@ -30,6 +40,12 @@ const store = {
}, },
setDialogSuccess(state, data) { setDialogSuccess(state, data) {
state.dialog_success = data; state.dialog_success = data;
},
setLoading(state, data) {
state.loading = data;
},
setAlert(state, data) {
state.alert = data;
} }
}, },
actions: { actions: {
@@ -39,7 +55,50 @@ const store = {
decrement({ commit }) { decrement({ commit }) {
commit('decrement'); commit('decrement');
}, },
async login({ state, commit }) {
commit('setLoading', true);
let alert = {
show: false,
type: 'info',
message: window.i18n.global.t('message.msgInfo')
}
let params = {
username: state.email,
password: state.password
};
console.log(params);
try {
const response = await axios.post(URL + '/login', params);
console.log(response.data)
if (response.data.status != 'OK') {
commit('setLoading', false);
if (response.data.message !== 'Invalid') {
alert.message = window.i18n.global.t('message.errorQuery');
} else {
alert.message = window.i18n.global.t('message.invalid');
}
alert.type = "error"
} else {
commit('setLoading', false);
commit('setData', response.data.data);
localStorage.setItem("token", response.data.data.token)
localStorage.setItem('user', JSON.stringify(response.data.data.user))
//console.log(localStorage.getItem("token"))
// if (data.user.is_courier === 'Y' && window.innerWidth < 600)
// window.location = "/one-ui/test/vuex/one-courier-mobile/";
// else
// window.location = "/" + response.data.data.user.M_UserGroupDashboard;
}
commit('setAlert', alert)
} catch (error) {
console.log(error)
commit('setLoading', false);
}
},
async loginState({ state, commit }) { async loginState({ state, commit }) {
commit('setLoading', true);
const params = { const params = {
email: state.email, email: state.email,
password: state.pasword password: state.pasword
@@ -47,8 +106,16 @@ const store = {
try { try {
const response = await axios.post(URL + '/login', params); const response = await axios.post(URL + '/login', params);
commit('setData', response.data); if (response.status != 'OK') {
commit('setLoading', false);
} else {
commit('setLoading', false);
commit('setData', response.data);
}
} catch (error) { } catch (error) {
commit('setLoading', false);
commit('setError', error); commit('setError', error);
} }
}, },