api login v3
This commit is contained in:
@@ -37,15 +37,17 @@
|
||||
</p>
|
||||
</v-sheet>
|
||||
</div>
|
||||
<!-- bg-primary-lighten text-primary -->
|
||||
<!-- icon="mdi-information-slab-circle-outline" -->
|
||||
<v-alert
|
||||
color="primary"
|
||||
density="compact"
|
||||
type="info"
|
||||
style="width: 100% !important;"
|
||||
class="bg-primary-lighten text-primary mt-4 mb-3 w-100"
|
||||
text="Enter the registered account"
|
||||
:text="alert.message"
|
||||
:type="alert.type"
|
||||
class="mt-4 mb-3 w-100"
|
||||
variant="tonal"
|
||||
>
|
||||
</v-alert>
|
||||
|
||||
<v-text-field
|
||||
class="mt-3"
|
||||
v-model="email"
|
||||
@@ -87,7 +89,10 @@
|
||||
>
|
||||
{{ $t("message.login") }}
|
||||
<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>
|
||||
</v-btn>
|
||||
</div>
|
||||
@@ -111,8 +116,11 @@
|
||||
},
|
||||
computed: {
|
||||
// Akses state dari store
|
||||
count() {
|
||||
return this.$store.state.login.count;
|
||||
loading() {
|
||||
return this.$store.state.login.loading;
|
||||
},
|
||||
alert() {
|
||||
return this.$store.state.login.alert;
|
||||
},
|
||||
email: {
|
||||
get() {
|
||||
@@ -133,6 +141,9 @@
|
||||
},
|
||||
methods: {
|
||||
// Dispatch action ke store
|
||||
login() {
|
||||
this.$store.dispatch("login/login");
|
||||
},
|
||||
increment() {
|
||||
this.$store.dispatch("increment");
|
||||
},
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"mobile-component": MobileComponent,
|
||||
"dekstop-component": DekstopComponent,
|
||||
},
|
||||
mounted() {},
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
|
||||
@@ -27,12 +27,11 @@
|
||||
</v-sheet>
|
||||
</div>
|
||||
<v-alert
|
||||
color="primary"
|
||||
density="compact"
|
||||
type="info"
|
||||
style="width: 100% !important;"
|
||||
class="bg-primary-lighten text-primary mt-4 mb-3 w-100"
|
||||
text="Enter the registered account"
|
||||
:text="alert.message"
|
||||
:type="alert.type"
|
||||
class="mt-4 mb-3 w-100"
|
||||
variant="tonal"
|
||||
>
|
||||
</v-alert>
|
||||
<v-text-field
|
||||
@@ -76,7 +75,7 @@
|
||||
>
|
||||
{{ $t("message.login") }}
|
||||
<template v-slot:loader>
|
||||
<v-progress-linear indeterminate></v-progress-linear>
|
||||
<v-progress-circular indeterminate></v-progress-circular>
|
||||
</template>
|
||||
</v-btn>
|
||||
</div>
|
||||
@@ -96,8 +95,11 @@
|
||||
},
|
||||
computed: {
|
||||
// Akses state dari store
|
||||
count() {
|
||||
return this.$store.state.login.count;
|
||||
loading() {
|
||||
return this.$store.state.login.loading;
|
||||
},
|
||||
alert() {
|
||||
return this.$store.state.login.alert;
|
||||
},
|
||||
email: {
|
||||
get() {
|
||||
@@ -118,6 +120,9 @@
|
||||
},
|
||||
methods: {
|
||||
// Dispatch action ke store
|
||||
login() {
|
||||
this.$store.dispatch("login/login");
|
||||
},
|
||||
increment() {
|
||||
this.$store.dispatch("increment");
|
||||
},
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<script src="../libraries/axios.js"></script>
|
||||
|
||||
<script src="../globalscript/theme.js"></script>
|
||||
<script src="../globalscript/global.js"></script>
|
||||
<!-- loader single file component -->
|
||||
<script src="../libraries/vue3-sfc-loader.js"></script>
|
||||
<script src="./language.js"></script>
|
||||
@@ -36,11 +37,12 @@
|
||||
const { loadModule } = window["vue3-sfc-loader"];
|
||||
|
||||
import login from "./modules/login.js";
|
||||
const store = Vuex.createStore({
|
||||
modules: {
|
||||
login: login,
|
||||
},
|
||||
});
|
||||
import system from "../globalstore/globalstore.js";
|
||||
|
||||
// if (one_token()) {
|
||||
// let usr = JSON.parse(localStorage.getItem("user"));
|
||||
// location.replace("/" + usr.M_UserGroupDashboard);
|
||||
// }
|
||||
const options = {
|
||||
moduleCache: {
|
||||
vue: Vue,
|
||||
@@ -69,7 +71,13 @@
|
||||
fallbackLocale: "en", // Set fallback locale
|
||||
messages, // Set locale messages
|
||||
});
|
||||
|
||||
window.i18n = i18n;
|
||||
const store = Vuex.createStore({
|
||||
modules: {
|
||||
system: system,
|
||||
login: login,
|
||||
},
|
||||
});
|
||||
// Vue App
|
||||
const app = Vue.createApp({
|
||||
data() {
|
||||
|
||||
@@ -9,6 +9,9 @@ var CustomMessages = {
|
||||
forgotPassword: "Forgot password?",
|
||||
placeholderEmail: "Enter your email",
|
||||
placeholderPassword: "Enter your password",
|
||||
msgInfo: 'Enter the registered account',
|
||||
errorQuery: "Error get data",
|
||||
invalid: "Invalid username / password"
|
||||
},
|
||||
},
|
||||
id: {
|
||||
@@ -21,6 +24,9 @@ var CustomMessages = {
|
||||
forgotPassword: "Lupa kata sandi?",
|
||||
placeholderEmail: "Isikan email anda",
|
||||
placeholderPassword: "Isikan kata sandi anda",
|
||||
msgInfo: "Masukkan akun terdaftar",
|
||||
errorQuery: "Gagal mendapatkan data",
|
||||
invalid: "Nama pengguna / kata sandi tidak valid"
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
// 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 = {
|
||||
namespaced: true,
|
||||
state() {
|
||||
@@ -9,7 +11,15 @@ const store = {
|
||||
data: null,
|
||||
email: "",
|
||||
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: {
|
||||
@@ -30,6 +40,12 @@ const store = {
|
||||
},
|
||||
setDialogSuccess(state, data) {
|
||||
state.dialog_success = data;
|
||||
},
|
||||
setLoading(state, data) {
|
||||
state.loading = data;
|
||||
},
|
||||
setAlert(state, data) {
|
||||
state.alert = data;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@@ -39,7 +55,50 @@ const store = {
|
||||
decrement({ commit }) {
|
||||
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 }) {
|
||||
commit('setLoading', true);
|
||||
const params = {
|
||||
email: state.email,
|
||||
password: state.pasword
|
||||
@@ -47,8 +106,16 @@ const store = {
|
||||
|
||||
try {
|
||||
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) {
|
||||
commit('setLoading', false);
|
||||
commit('setError', error);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user