Commit 7784427b authored by Kittisak Maneewong's avatar Kittisak Maneewong

success auth

parent e7f4199a
This diff is collapsed.
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
"vue-template-compiler": "^2.6.10" "vue-template-compiler": "^2.6.10"
}, },
"dependencies": { "dependencies": {
"iview": "^3.4.0",
"validate.js": "^0.12.0", "validate.js": "^0.12.0",
"vue-router": "^3.0.2", "vue-router": "^3.0.2",
"vuetify": "^1.5.7", "vuetify": "^1.5.7",
......
This diff is collapsed.
This diff is collapsed.
...@@ -16,14 +16,22 @@ if (token) { ...@@ -16,14 +16,22 @@ if (token) {
import Vue from 'vue'; import Vue from 'vue';
import Vuetify from 'vuetify'; import Vuetify from 'vuetify';
import iView from 'iview';
import App from './App.vue'; import App from './App.vue';
import router from './route'; import router from './route';
import store from './store'; import store from './store';
import 'iview/dist/styles/iview.css';
// Vue.config.productionTip = false; // Vue.config.productionTip = false;
Vue.use(Vuetify); Vue.use(Vuetify);
Vue.use(iView);
iView.LoadingBar.config({
height: 3
});
const app = new Vue({ const app = new Vue({
el: '#app', el: '#app',
......
import Vue from 'vue'; import Vue from 'vue';
import VueRouter from 'vue-router'; import VueRouter from 'vue-router';
import iView from 'iview';
Vue.use(VueRouter); Vue.use(VueRouter);
...@@ -78,6 +79,7 @@ const router = new VueRouter({ ...@@ -78,6 +79,7 @@ const router = new VueRouter({
}) })
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
iView.LoadingBar.start();
if(to.matched.some(record => record.meta.requiredUser)) { if(to.matched.some(record => record.meta.requiredUser)) {
if(!localStorage.getItem('access_token')) { if(!localStorage.getItem('access_token')) {
next('/employer/login') next('/employer/login')
...@@ -89,4 +91,8 @@ router.beforeEach((to, from, next) => { ...@@ -89,4 +91,8 @@ router.beforeEach((to, from, next) => {
} }
}) })
router.afterEach(route => {
iView.LoadingBar.finish();
})
export default router export default router
\ No newline at end of file
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import iView from 'iview';
Vue.use(Vuex); Vue.use(Vuex);
...@@ -60,6 +61,7 @@ export default new Vuex.Store({ ...@@ -60,6 +61,7 @@ export default new Vuex.Store({
.then(res => { .then(res => {
commit('setLoading', false) commit('setLoading', false)
if (payload.role == 1) { if (payload.role == 1) {
iView.LoadingBar.finish()
localStorage.setItem('access_token', res.data.token) localStorage.setItem('access_token', res.data.token)
commit('setJwt', res.data.token) commit('setJwt', res.data.token)
dispatch('checkUser') dispatch('checkUser')
...@@ -78,9 +80,14 @@ export default new Vuex.Store({ ...@@ -78,9 +80,14 @@ export default new Vuex.Store({
console.log(res) console.log(res)
}) })
.catch(err => { .catch(err => {
iView.LoadingBar.error()
commit('setLoading', false) commit('setLoading', false)
if (err.response.data.error === 'invalid_credentials') { if (err.response.data.error === 'invalid_credentials') {
if (payload.role === 1) {
commit('setError', 'อีเมลหรือรหัสผ่านไม่ถูกต้อง')
} else {
commit('setError', 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง') commit('setError', 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง')
}
setTimeout(() => { setTimeout(() => {
commit('setError', null) commit('setError', null)
}, 4000); }, 4000);
...@@ -95,6 +102,9 @@ export default new Vuex.Store({ ...@@ -95,6 +102,9 @@ export default new Vuex.Store({
commit('setLoading', true) commit('setLoading', true)
axios.post('api/auth/register', payload) axios.post('api/auth/register', payload)
.then(res => { .then(res => {
if (payload.role === 1) {
iView.LoadingBar.finish()
}
commit('setLoading', false) commit('setLoading', false)
commit('setSnackbar', { commit('setSnackbar', {
show: true, show: true,
...@@ -106,19 +116,34 @@ export default new Vuex.Store({ ...@@ -106,19 +116,34 @@ export default new Vuex.Store({
resolve(res) resolve(res)
}) })
.catch(err => { .catch(err => {
iView.LoadingBar.error()
commit('setLoading', false) commit('setLoading', false)
console.log(err.response) console.log(err.response)
if (err.response.data == '{"email":["The email has already been taken."]}') { const error = JSON.parse(err.response.data);
commit('setError', 'อีเมลล์นี้ถูกใช้งานเเล้ว') if (error.username && error.email) {
commit('setError', 'ชื่อผู้ใช้เเละอีเมลถูกใช้งานเเล้ว')
setTimeout(() => {
commit('setError', null)
}, 4000);
} else if (error.email) {
commit('setError', 'อีเมลนี้ถูกใช้งานเเล้ว')
setTimeout(() => {
commit('setError', null)
}, 4000);
errorMessage = 'อีเมลนี้ถูกใช้งานเเล้ว'
} else if (error.username) {
commit('setError', 'ชื่อผู้ใช้นี้ถูกใช้งานเเล้ว')
setTimeout(() => { setTimeout(() => {
commit('setError', null) commit('setError', null)
}, 4000); }, 4000);
errorMessage = 'ชื่อผู้ใช้นี้ถูกใช้งานเเล้ว'
} }
reject(err.response) reject(err.response)
}) })
}) })
}, },
logout ({commit}) { logout ({commit}) {
iView.LoadingBar.finish()
localStorage.removeItem('access_token') localStorage.removeItem('access_token')
commit('setUser', { commit('setUser', {
name: null, name: null,
......
...@@ -112,6 +112,8 @@ export default { ...@@ -112,6 +112,8 @@ export default {
.then(res => { .then(res => {
this.$refs.login.reset() this.$refs.login.reset()
}) })
} else {
this.$Loading.error()
} }
} }
} }
......
...@@ -28,6 +28,13 @@ ...@@ -28,6 +28,13 @@
required required
></v-text-field> ></v-text-field>
<a href="#" class="body-2 font-weight-medium my-3">ลืมรหัสผ่าน</a> <a href="#" class="body-2 font-weight-medium my-3">ลืมรหัสผ่าน</a>
<p class="text-xs-center"><v-alert
:value="!!error"
color="error"
outline
>
{{ error }}
</v-alert></p>
<v-btn color="cyan darken-4" large dark block type="submit">เข้าสู่ระบบ</v-btn> <v-btn color="cyan darken-4" large dark block type="submit">เข้าสู่ระบบ</v-btn>
</v-form> </v-form>
<v-layout row wrap justify-center class="my-2"> <v-layout row wrap justify-center class="my-2">
...@@ -76,15 +83,22 @@ export default { ...@@ -76,15 +83,22 @@ export default {
}, },
methods: { methods: {
login () { login () {
if (this.$refs.loginEmployer.validate()) {
this.$store.dispatch('login', this.loginData) this.$store.dispatch('login', this.loginData)
.then(res => { .then(res => {
this.$router.push('/Employer') this.$router.push('/Employer')
}) })
} else {
this.$Loading.error()
}
} }
}, },
computed: { computed: {
loading () { loading () {
return this.$store.getters.getLoading return this.$store.getters.getLoading
},
error () {
return this.$store.getters.getError
} }
} }
} }
......
...@@ -157,6 +157,8 @@ export default { ...@@ -157,6 +157,8 @@ export default {
.then(res => { .then(res => {
this.$refs.register.reset() this.$refs.register.reset()
}) })
} else {
this.$Loading.error()
} }
} }
} }
......
...@@ -79,7 +79,15 @@ ...@@ -79,7 +79,15 @@
class="mg-ip" class="mg-ip"
required required
></v-text-field> ></v-text-field>
</v-flex>
<v-flex class="px-3">
<p><v-alert
:value="!!error"
color="error"
outline
>
{{ error }}
</v-alert></p>
</v-flex> </v-flex>
</v-layout> </v-layout>
<v-layout row wrap justify-center> <v-layout row wrap justify-center>
...@@ -143,6 +151,9 @@ export default { ...@@ -143,6 +151,9 @@ export default {
}, },
loading () { loading () {
return this.$store.getters.getLoading return this.$store.getters.getLoading
},
error () {
return this.$store.getters.getError
} }
}, },
methods: { methods: {
...@@ -150,8 +161,10 @@ export default { ...@@ -150,8 +161,10 @@ export default {
if(this.$refs.registerEmployer.validate()) { if(this.$refs.registerEmployer.validate()) {
this.$store.dispatch('register', this.registerData) this.$store.dispatch('register', this.registerData)
.then(res => { .then(res => {
this.$router.push('/login') this.$router.push('/employer/login')
}) })
} else {
this.$Loading.error()
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment