Commit 1b75b354 authored by Kittisak Maneewong's avatar Kittisak Maneewong

add configemployer

parent bc039636
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Company; use App\Company;
use App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class CompanyController extends Controller class CompanyController extends Controller
...@@ -12,9 +13,21 @@ class CompanyController extends Controller ...@@ -12,9 +13,21 @@ class CompanyController extends Controller
* *
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function check($id)
{
$exists = Company::where('user_id', $id)->exists();
return response()->json(['exists' => $exists]);
}
public function config($id)
{
$company = User::where('id', $id)->get();
return response()->json(['company' => $company]);
}
public function index() public function index()
{ {
//
} }
/** /**
...@@ -83,7 +96,6 @@ class CompanyController extends Controller ...@@ -83,7 +96,6 @@ class CompanyController extends Controller
*/ */
public function show($id) public function show($id)
{ {
//
} }
/** /**
...@@ -94,7 +106,13 @@ class CompanyController extends Controller ...@@ -94,7 +106,13 @@ class CompanyController extends Controller
*/ */
public function edit($id) public function edit($id)
{ {
// $exists = Company::where('user_id', $id)->exists();
if ($exists) {
$data = Company::where('user_id', $id)->get();
} else {
$data = User::where('id', $id)->get();
}
return response()->json(['check' => $exists, 'data' => $data]);
} }
/** /**
......
This diff is collapsed.
...@@ -3,6 +3,16 @@ window.Vue = require('vue'); ...@@ -3,6 +3,16 @@ window.Vue = require('vue');
window._ = require('lodash'); window._ = require('lodash');
window.axios = require('axios'); window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
window.axios.defaults.baseUrl = 'http://localhost:8000/'; window.axios.defaults.baseUrl = 'http://localhost:8000/';
......
...@@ -27,7 +27,7 @@ export default { ...@@ -27,7 +27,7 @@ export default {
Footer, Footer,
Snackbar Snackbar
}, },
created () { beforeMount () {
this.$store.dispatch('checkUser') this.$store.dispatch('checkUser')
} }
} }
......
...@@ -27,7 +27,7 @@ export default { ...@@ -27,7 +27,7 @@ export default {
Footer, Footer,
Snackbar Snackbar
}, },
created () { beforeMount () {
this.$store.dispatch('checkEmployer') this.$store.dispatch('checkEmployer')
} }
} }
......
...@@ -14,8 +14,10 @@ import LoginEmployer from './views/LoginEmployer.vue'; ...@@ -14,8 +14,10 @@ import LoginEmployer from './views/LoginEmployer.vue';
import PageNotFound from './views/PageNotFound.vue'; import PageNotFound from './views/PageNotFound.vue';
import EditCompany from './views/EditCompany.vue'; import EditCompany from './views/EditCompany.vue';
import RegisterEmployer from './views/RegisterEmployer'; import RegisterEmployer from './views/RegisterEmployer';
import ManagejobEmployer from './views/managejob.vue' import ManagejobEmployer from './views/managejob.vue';
import ConfigCompany from './views/ConfigCompany.vue';
import AddJob from './views/AddJob.vue'; import AddJob from './views/AddJob.vue';
import Axios from 'axios';
const router = new VueRouter({ const router = new VueRouter({
mode: 'history', mode: 'history',
...@@ -28,7 +30,11 @@ const router = new VueRouter({ ...@@ -28,7 +30,11 @@ const router = new VueRouter({
{ {
path: '', path: '',
name: 'Employer', name: 'Employer',
component: Employer component: Employer,
meta: {
loginEmployer: true,
configProfile: true
}
}, },
{ {
path: 'login', path: 'login',
...@@ -43,17 +49,34 @@ const router = new VueRouter({ ...@@ -43,17 +49,34 @@ const router = new VueRouter({
{ {
path: 'managejob', path: 'managejob',
name: 'managejobEmployer', name: 'managejobEmployer',
component: ManagejobEmployer component: ManagejobEmployer,
meta: {
loginEmployer: true,
configProfile: true
}
}, },
{ {
path: 'editcompany', path: 'editcompany',
name: 'editcompany', name: 'editcompany',
component: EditCompany component: EditCompany,
meta: {
loginEmployer: true,
configProfile: true
}
}, },
{ {
path: 'addjob', path: 'addjob',
name: 'addjob', name: 'addjob',
component: AddJob component: AddJob,
meta: {
loginEmployer: true,
configProfile: true
}
},
{
path: 'configcompany',
name: 'configcompany',
component: ConfigCompany
}, },
{ {
path: '*', path: '*',
...@@ -98,6 +121,30 @@ router.beforeEach((to, from, next) => { ...@@ -98,6 +121,30 @@ router.beforeEach((to, from, next) => {
} else { } else {
next() next()
} }
} else if (to.matched.some(record => record.meta.loginEmployer)) {
if(!localStorage.getItem('access_token_employer')) {
next('/employer/login')
} else if (to.matched.some(record => record.meta.configProfile)) {
axios.get('/api/auth/current', {
headers: {
Authorization: `Bearer ${localStorage.getItem('access_token_employer')}`
}
})
.then(res => {
axios.get(`/api/companys/${res.data.user.id}/check`)
.then(res => {
if (res.data.exists) {
next()
} else {
next('/employer/configcompany')
}
})
.catch(err => {next()})
})
.catch(err => {next()})
} else {
next()
}
} else { } else {
next() next()
} }
......
...@@ -196,6 +196,7 @@ export default new Vuex.Store({ ...@@ -196,6 +196,7 @@ export default new Vuex.Store({
} }
}, },
checkEmployer ({commit}) { checkEmployer ({commit}) {
return new Promise((resolve, reject) => {
if (!!localStorage.getItem('access_token_employer')) { if (!!localStorage.getItem('access_token_employer')) {
axios.get('/api/auth/current', { axios.get('/api/auth/current', {
headers: { headers: {
...@@ -203,6 +204,7 @@ export default new Vuex.Store({ ...@@ -203,6 +204,7 @@ export default new Vuex.Store({
} }
}) })
.then(res => { .then(res => {
resolve(res.data.user)
commit('setEmployer', { commit('setEmployer', {
id: res.data.user.id, id: res.data.user.id,
username: res.data.user.username, username: res.data.user.username,
...@@ -222,8 +224,10 @@ export default new Vuex.Store({ ...@@ -222,8 +224,10 @@ export default new Vuex.Store({
}) })
.catch(err => { .catch(err => {
console.log(err.response) console.log(err.response)
reject(err.response)
}) })
} }
})
} }
}, },
getters: { getters: {
......
This diff is collapsed.
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<v-flex sm4 xs12 class="px-3"> <v-flex sm4 xs12 class="px-3">
<label class="font-weight-bold">ชื่อบริษัท <span class="red--text">&nbsp;*</span></label> <label class="font-weight-bold">ชื่อบริษัท <span class="red--text">&nbsp;*</span></label>
<v-text-field <v-text-field
readonly
outline outline
label="ชื่อบริษัท" label="ชื่อบริษัท"
:rules="[rules.required]" :rules="[rules.required]"
...@@ -51,6 +52,7 @@ ...@@ -51,6 +52,7 @@
<v-flex sm4 xs12 class="px-3"> <v-flex sm4 xs12 class="px-3">
<label class="font-weight-bold">อีเมล <span class="red--text">&nbsp;*</span></label> <label class="font-weight-bold">อีเมล <span class="red--text">&nbsp;*</span></label>
<v-text-field <v-text-field
readonly
outline outline
label="อีเมล" label="อีเมล"
v-model="company_data.email" v-model="company_data.email"
...@@ -227,7 +229,7 @@ ...@@ -227,7 +229,7 @@
<span >เพื่อความสะดวกในการเดินทางของผู้สมัครงาน กรุณาระบุสถานีรถไฟฟ้าที่ใกล้กับสถานที่ปฏิบัติงาน (ถ้ามี) หรือระบุสายรถเมล์ที่ผ่านสถานที่ประกอบการ และระบุการเดินทางเพิ่มเติม เพื่อให้เข้าใจในการเดินทางมากยิ่งขึ้น</span> <span >เพื่อความสะดวกในการเดินทางของผู้สมัครงาน กรุณาระบุสถานีรถไฟฟ้าที่ใกล้กับสถานที่ปฏิบัติงาน (ถ้ามี) หรือระบุสายรถเมล์ที่ผ่านสถานที่ประกอบการ และระบุการเดินทางเพิ่มเติม เพื่อให้เข้าใจในการเดินทางมากยิ่งขึ้น</span>
</v-flex> </v-flex>
<v-layout row wrap justify-center class="my-2"> <v-layout row wrap justify-center class="my-2">
<v-btn color="red" dark="" type="submit">บันทึกข้อมูล</v-btn> <v-btn color="red" dark="" type="submit" :loading="loading">บันทึกข้อมูล</v-btn>
</v-layout> </v-layout>
</v-layout> </v-layout>
</v-flex> </v-flex>
...@@ -240,6 +242,7 @@ ...@@ -240,6 +242,7 @@
export default { export default {
data () { data () {
return { return {
loading: false,
status: 'ยังไม่ได้เลือกไฟล์', status: 'ยังไม่ได้เลือกไฟล์',
nameImage: null, nameImage: null,
company_data: { company_data: {
...@@ -264,7 +267,8 @@ export default { ...@@ -264,7 +267,8 @@ export default {
mrt: '', mrt: '',
arl: '', arl: '',
bus: '', bus: '',
another: '' another: '',
check: false
}, },
rules: { rules: {
required: v => !!v || 'จำเป็นต้องกรอก', required: v => !!v || 'จำเป็นต้องกรอก',
...@@ -403,22 +407,25 @@ export default { ...@@ -403,22 +407,25 @@ export default {
} }
}, },
createJob () { createJob () {
this.loading = true
if (this.amphoes.findIndex(x => x.amphoe_code === this.amphoe.amphoe_code) === -1) {this.amphoe = ''} if (this.amphoes.findIndex(x => x.amphoe_code === this.amphoe.amphoe_code) === -1) {this.amphoe = ''}
if (this.tumbons.findIndex(x => x.tumbon_code === this.tumbon.tumbon_code) === -1) {this.tumbon = ''} if (this.tumbons.findIndex(x => x.tumbon_code === this.tumbon.tumbon_code) === -1) {this.tumbon = ''}
if (this.company_data.zip_code === ' ') {this.company_data.zip_code = ''} if (this.company_data.zip_code === ' ') {this.company_data.zip_code = ''}
if (this.$refs.create.validate()) { if (this.$refs.create.validate()) {
this.company_data.user_id = this.$store.getters.getEmployer.id
this.company_data.province = this.province.province this.company_data.province = this.province.province
this.company_data.amphoe = this.amphoe.amphoe this.company_data.amphoe = this.amphoe.amphoe
this.company_data.tumbon = this.tumbon.tumbon this.company_data.tumbon = this.tumbon.tumbon
axios.post('/companys', this.company_data) axios.post('/api/companys', this.company_data)
.then(res => { .then(res => {
console.log(res) this.loading = false
this.$router.push('/employer')
}) })
.catch(err => { .catch(err => {
console.log(err.response) console.log(err.response)
this.loading = false
}) })
} else { } else {
this.loading = false
this.$Loading.error() this.$Loading.error()
} }
}, },
...@@ -484,8 +491,51 @@ export default { ...@@ -484,8 +491,51 @@ export default {
}) })
} }
}, },
mounted() { beforeMount() {
this.showProvinces() this.showProvinces()
this.$store.dispatch('checkEmployer')
.then(res => {
axios.get(`/api/companys/${res.id}/edit`)
.then(res => {
if(res.data.check) {
console.log(res.data)
this.company_data = {
user_id: res.data.data[0].user_id,
imageCompany: res.data.data[0].imageCompany,
company_name: res.data.data[0].company_name,
company_owner: res.data.data[0].company_owner,
phone_no: res.data.data[0].phone_no,
email: res.data.data[0].email,
fax: res.data.data[0].fax,
website: res.data.data[0].website,
addr: res.data.data[0].addr,
province: res.data.data[0].province,
amphoe: res.data.data[0].amphoe,
tumbon: res.data.data[0].tambon,
zip_code: res.data.data[0].zipcode,
about: res.data.data[0].about,
imageMap: res.data.data[0].imageMap,
lat: res.data.data[0].lat,
lng: res.data.data[0].lng,
bts: res.data.data[0].bts,
mrt: res.data.data[0].mrt,
arl: res.data.data[0].arl,
bus: res.data.data[0].bus,
another: res.data.data[0].another,
check: true
}
} else {
this.company_data.user_id = res.data.data[0].id
this.company_data.company_name = res.data.data[0].company_name
this.company_data.email = res.data.data[0].email_employers
this.company_data.phone_no = res.data.data[0].tel
this.company_data.check = false
}
})
.catch(err => {
console.log(err.response)
})
})
} }
} }
</script> </script>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1"> --> <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<meta name="csrf-token" content="{{ csrf_token() }}">
<!-- <meta name="csrf-token" content="{{ csrf_token() }}"> --> <!-- <meta name="csrf-token" content="{{ csrf_token() }}"> -->
<title>CO-OP Search</title> <title>CO-OP Search</title>
......
...@@ -19,6 +19,10 @@ Route::group(['prefix' => 'auth'], function ($router) { ...@@ -19,6 +19,10 @@ Route::group(['prefix' => 'auth'], function ($router) {
Route::get('current', 'AuthController@getAuthenticatedUser'); Route::get('current', 'AuthController@getAuthenticatedUser');
}); });
Route::resource('/companys', 'CompanyController');
Route::get('/companys/{company}/check', 'CompanyController@check')->name('companys.check');
Route::get('/companys/{company}/config', 'CompanyController@config')->name('companys.config');
Route::get('/province','DistrictController@provinces'); Route::get('/province','DistrictController@provinces');
Route::get('/province/{province_code}/amphoe','DistrictController@amphoes'); Route::get('/province/{province_code}/amphoe','DistrictController@amphoes');
Route::get('/province/{province_code}/amphoe/{amphoe_code}/district','DistrictController@districts'); Route::get('/province/{province_code}/amphoe/{amphoe_code}/district','DistrictController@districts');
......
...@@ -12,5 +12,3 @@ ...@@ -12,5 +12,3 @@
*/ */
Route::get('/{any}', 'AppController@index')->where('any', '.*'); Route::get('/{any}', 'AppController@index')->where('any', '.*');
Route::resource('/companys', 'CompanyController');
\ No newline at end of file
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