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

success auth

parent e7f4199a
......@@ -1294,6 +1294,14 @@
"integrity": "sha512-6xrbvN0MOBKSJDdonmSSz2OwFSgxRaVtBDes26mj9KIGtDo+g9xosFRSC+i1gQh2oAN/tQ62AI/pGZGQjVOiRg==",
"dev": true
},
"async-validator": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/async-validator/-/async-validator-1.11.0.tgz",
"integrity": "sha512-3ROlrxLee6KB1aEj9eENBLB0pPCPCb+hc+aGify63HBHptq5FnEFNAQOAkhbx7xBlVh5XXi2w+QEecWpOdigpw==",
"requires": {
"babel-runtime": "6.x"
}
},
"atob": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
......@@ -1391,6 +1399,27 @@
"object.omit": "^3.0.0"
}
},
"babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
"integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
},
"dependencies": {
"core-js": {
"version": "2.6.5",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.5.tgz",
"integrity": "sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A=="
},
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg=="
}
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
......@@ -1464,6 +1493,11 @@
"integrity": "sha1-3DQxT05nkxgJP8dgJyUl+UvyXBY=",
"dev": true
},
"batch-processor": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/batch-processor/-/batch-processor-1.0.0.tgz",
"integrity": "sha1-dclcMrdI4IUNEMKxaPa9vpiRrOg="
},
"big.js": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
......@@ -2638,8 +2672,7 @@
"deepmerge": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-2.2.1.tgz",
"integrity": "sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==",
"dev": true
"integrity": "sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA=="
},
"default-gateway": {
"version": "4.2.0",
......@@ -2901,6 +2934,14 @@
"integrity": "sha512-3mtqcAWa4HgG+Djh/oNXlPH0cOH6MmtwxN1nHSaReb9P0Vn51qYPqYwLeoSuAX9loU1wrOBhFbiX3CkeIxPfgg==",
"dev": true
},
"element-resize-detector": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/element-resize-detector/-/element-resize-detector-1.2.0.tgz",
"integrity": "sha512-UmhNB8sIJVZeg56gEjgmMd6p37sCg8j8trVW0LZM7Wzv+kxQ5CnRHcgRKBTB/kFUSn3e7UP59kl2V2U8Du1hmg==",
"requires": {
"batch-processor": "1.0.0"
}
},
"elliptic": {
"version": "6.4.1",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz",
......@@ -3668,8 +3709,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
......@@ -3690,14 +3730,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -3712,20 +3750,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -3842,8 +3877,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
......@@ -3855,7 +3889,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -3870,7 +3903,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -3878,14 +3910,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
......@@ -3904,7 +3934,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -3985,8 +4014,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
......@@ -3998,7 +4026,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -4084,8 +4111,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
......@@ -4121,7 +4147,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -4141,7 +4166,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
......@@ -4185,14 +4209,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
......@@ -5095,6 +5117,26 @@
"integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=",
"dev": true
},
"iview": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/iview/-/iview-3.4.0.tgz",
"integrity": "sha512-MSqro+YxJ91MnxkAd4iR4VK9usEIX2+qE4W5qwnbbFSaVevbc6x+CVSxeg3H8U7XcbP/n9wWBXAQIY3vxniHlw==",
"requires": {
"async-validator": "^1.10.0",
"deepmerge": "^2.2.1",
"element-resize-detector": "^1.2.0",
"js-calendar": "^1.2.3",
"lodash.throttle": "^4.1.1",
"popper.js": "^1.14.6",
"tinycolor2": "^1.4.1",
"v-click-outside-x": "^3.5.6"
}
},
"js-calendar": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/js-calendar/-/js-calendar-1.2.3.tgz",
"integrity": "sha512-dAA1/Zbp4+c5E+ARCVTIuKepXsNLzSYfzvOimiYD4S5eeP9QuplSHLcdhfqFSwyM1o1u6ku6RRRCyaZ0YAjiBw=="
},
"js-levenshtein": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/js-levenshtein/-/js-levenshtein-1.1.6.tgz",
......@@ -5384,6 +5426,11 @@
"integrity": "sha1-0jM6NtnncXyK0vfKyv7HwytERmQ=",
"dev": true
},
"lodash.throttle": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz",
"integrity": "sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ="
},
"lodash.uniq": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",
......@@ -6311,6 +6358,11 @@
"find-up": "^3.0.0"
}
},
"popper.js": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.15.0.tgz",
"integrity": "sha512-w010cY1oCUmI+9KwwlWki+r5jxKfTFDVoadl7MSrIujHU5MJ5OR6HTDj6Xo8aoR/QsA56x8jKjA59qGH4ELtrA=="
},
"portfinder": {
"version": "1.0.20",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.20.tgz",
......@@ -8299,6 +8351,11 @@
"integrity": "sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=",
"dev": true
},
"tinycolor2": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.4.1.tgz",
"integrity": "sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g="
},
"to-arraybuffer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz",
......@@ -8666,6 +8723,11 @@
"integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==",
"dev": true
},
"v-click-outside-x": {
"version": "3.7.1",
"resolved": "https://registry.npmjs.org/v-click-outside-x/-/v-click-outside-x-3.7.1.tgz",
"integrity": "sha512-WmUgmcIXr9clVpm1AYS/FgHtcDicfnfoxgQCNg4O6vfk9GVnxA0vSqO321ogUo0b7czYTidj7fQENvWFMWOkUg=="
},
"v8-compile-cache": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.0.2.tgz",
......
......@@ -21,6 +21,7 @@
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"iview": "^3.4.0",
"validate.js": "^0.12.0",
"vue-router": "^3.0.2",
"vuetify": "^1.5.7",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -16,14 +16,22 @@ if (token) {
import Vue from 'vue';
import Vuetify from 'vuetify';
import iView from 'iview';
import App from './App.vue';
import router from './route';
import store from './store';
import 'iview/dist/styles/iview.css';
// Vue.config.productionTip = false;
Vue.use(Vuetify);
Vue.use(iView);
iView.LoadingBar.config({
height: 3
});
const app = new Vue({
el: '#app',
......
import Vue from 'vue';
import VueRouter from 'vue-router';
import iView from 'iview';
Vue.use(VueRouter);
......@@ -78,6 +79,7 @@ const router = new VueRouter({
})
router.beforeEach((to, from, next) => {
iView.LoadingBar.start();
if(to.matched.some(record => record.meta.requiredUser)) {
if(!localStorage.getItem('access_token')) {
next('/employer/login')
......@@ -89,4 +91,8 @@ router.beforeEach((to, from, next) => {
}
})
router.afterEach(route => {
iView.LoadingBar.finish();
})
export default router
\ No newline at end of file
import Vue from 'vue';
import Vuex from 'vuex';
import iView from 'iview';
Vue.use(Vuex);
......@@ -60,6 +61,7 @@ export default new Vuex.Store({
.then(res => {
commit('setLoading', false)
if (payload.role == 1) {
iView.LoadingBar.finish()
localStorage.setItem('access_token', res.data.token)
commit('setJwt', res.data.token)
dispatch('checkUser')
......@@ -78,9 +80,14 @@ export default new Vuex.Store({
console.log(res)
})
.catch(err => {
iView.LoadingBar.error()
commit('setLoading', false)
if (err.response.data.error === 'invalid_credentials') {
commit('setError', 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง')
if (payload.role === 1) {
commit('setError', 'อีเมลหรือรหัสผ่านไม่ถูกต้อง')
} else {
commit('setError', 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง')
}
setTimeout(() => {
commit('setError', null)
}, 4000);
......@@ -95,6 +102,9 @@ export default new Vuex.Store({
commit('setLoading', true)
axios.post('api/auth/register', payload)
.then(res => {
if (payload.role === 1) {
iView.LoadingBar.finish()
}
commit('setLoading', false)
commit('setSnackbar', {
show: true,
......@@ -106,19 +116,34 @@ export default new Vuex.Store({
resolve(res)
})
.catch(err => {
iView.LoadingBar.error()
commit('setLoading', false)
console.log(err.response)
if (err.response.data == '{"email":["The email has already been taken."]}') {
commit('setError', 'อีเมลล์นี้ถูกใช้งานเเล้ว')
const error = JSON.parse(err.response.data);
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(() => {
commit('setError', null)
}, 4000);
errorMessage = 'ชื่อผู้ใช้นี้ถูกใช้งานเเล้ว'
}
reject(err.response)
})
})
},
logout ({commit}) {
iView.LoadingBar.finish()
localStorage.removeItem('access_token')
commit('setUser', {
name: null,
......
......@@ -112,6 +112,8 @@ export default {
.then(res => {
this.$refs.login.reset()
})
} else {
this.$Loading.error()
}
}
}
......
......@@ -28,6 +28,13 @@
required
></v-text-field>
<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-form>
<v-layout row wrap justify-center class="my-2">
......@@ -76,15 +83,22 @@ export default {
},
methods: {
login () {
this.$store.dispatch('login', this.loginData)
.then(res => {
this.$router.push('/Employer')
})
if (this.$refs.loginEmployer.validate()) {
this.$store.dispatch('login', this.loginData)
.then(res => {
this.$router.push('/Employer')
})
} else {
this.$Loading.error()
}
}
},
computed: {
loading () {
return this.$store.getters.getLoading
},
error () {
return this.$store.getters.getError
}
}
}
......
......@@ -157,6 +157,8 @@ export default {
.then(res => {
this.$refs.register.reset()
})
} else {
this.$Loading.error()
}
}
}
......
......@@ -79,11 +79,19 @@
class="mg-ip"
required
></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-layout>
<v-layout row wrap justify-center>
<v-btn color="cyan darken-4 my-3" dark type="submit">สมัครสมาชิก</v-btn>
<v-btn color="cyan darken-4 my-3" dark type="submit">สมัครสมาชิก</v-btn>
</v-layout>
<v-layout row wrap justify-center>
<span class="body-2 font-weight-medium">มีบัญชีผู้ใช้แล้ว? <router-link to="/employer/login">เข้าสู่ระบบ</router-link></span>
......@@ -143,6 +151,9 @@ export default {
},
loading () {
return this.$store.getters.getLoading
},
error () {
return this.$store.getters.getError
}
},
methods: {
......@@ -150,8 +161,10 @@ export default {
if(this.$refs.registerEmployer.validate()) {
this.$store.dispatch('register', this.registerData)
.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