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

add configemployer

parent bc039636
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Company;
use App\User;
use Illuminate\Http\Request;
class CompanyController extends Controller
......@@ -12,9 +13,21 @@ class CompanyController extends Controller
*
* @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()
{
//
}
/**
......@@ -83,7 +96,6 @@ class CompanyController extends Controller
*/
public function show($id)
{
//
}
/**
......@@ -94,7 +106,13 @@ class CompanyController extends Controller
*/
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');
window._ = require('lodash');
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/';
......
......@@ -27,7 +27,7 @@ export default {
Footer,
Snackbar
},
created () {
beforeMount () {
this.$store.dispatch('checkUser')
}
}
......
......@@ -27,7 +27,7 @@ export default {
Footer,
Snackbar
},
created () {
beforeMount () {
this.$store.dispatch('checkEmployer')
}
}
......
......@@ -14,8 +14,10 @@ import LoginEmployer from './views/LoginEmployer.vue';
import PageNotFound from './views/PageNotFound.vue';
import EditCompany from './views/EditCompany.vue';
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 Axios from 'axios';
const router = new VueRouter({
mode: 'history',
......@@ -28,7 +30,11 @@ const router = new VueRouter({
{
path: '',
name: 'Employer',
component: Employer
component: Employer,
meta: {
loginEmployer: true,
configProfile: true
}
},
{
path: 'login',
......@@ -43,17 +49,34 @@ const router = new VueRouter({
{
path: 'managejob',
name: 'managejobEmployer',
component: ManagejobEmployer
component: ManagejobEmployer,
meta: {
loginEmployer: true,
configProfile: true
}
},
{
path: 'editcompany',
name: 'editcompany',
component: EditCompany
component: EditCompany,
meta: {
loginEmployer: true,
configProfile: true
}
},
{
path: 'addjob',
name: 'addjob',
component: AddJob
component: AddJob,
meta: {
loginEmployer: true,
configProfile: true
}
},
{
path: 'configcompany',
name: 'configcompany',
component: ConfigCompany
},
{
path: '*',
......@@ -98,6 +121,30 @@ router.beforeEach((to, from, next) => {
} else {
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 {
next()
}
......
......@@ -196,34 +196,38 @@ export default new Vuex.Store({
}
},
checkEmployer ({commit}) {
if (!!localStorage.getItem('access_token_employer')) {
axios.get('/api/auth/current', {
headers: {
Authorization: `Bearer ${localStorage.getItem('access_token_employer')}`
}
})
.then(res => {
commit('setEmployer', {
id: res.data.user.id,
username: res.data.user.username,
company_name: res.data.user.company_name,
email: res.data.user.email_employers
return new Promise((resolve, reject) => {
if (!!localStorage.getItem('access_token_employer')) {
axios.get('/api/auth/current', {
headers: {
Authorization: `Bearer ${localStorage.getItem('access_token_employer')}`
}
})
.then(res => {
resolve(res.data.user)
commit('setEmployer', {
id: res.data.user.id,
username: res.data.user.username,
company_name: res.data.user.company_name,
email: res.data.user.email_employers
})
// commit('setTime', res.headers.date)
const a = res.headers.date.split(',')[1].split(' ')
const date = a[1] + ' ' + a[2] + ' ' +a[3]
const b = res.headers.date.split(',')[1].split(' ')[4].split(':')
const time = ((b[0]*1 + 7) % 24) +':'+b[1]+':'+b[2]
commit('setTime', {
date: date,
time: time
})
console.log(res)
})
// commit('setTime', res.headers.date)
const a = res.headers.date.split(',')[1].split(' ')
const date = a[1] + ' ' + a[2] + ' ' +a[3]
const b = res.headers.date.split(',')[1].split(' ')[4].split(':')
const time = ((b[0]*1 + 7) % 24) +':'+b[1]+':'+b[2]
commit('setTime', {
date: date,
time: time
.catch(err => {
console.log(err.response)
reject(err.response)
})
console.log(res)
})
.catch(err => {
console.log(err.response)
})
}
}
})
}
},
getters: {
......
This diff is collapsed.
......@@ -25,6 +25,7 @@
<v-flex sm4 xs12 class="px-3">
<label class="font-weight-bold">ชื่อบริษัท <span class="red--text">&nbsp;*</span></label>
<v-text-field
readonly
outline
label="ชื่อบริษัท"
:rules="[rules.required]"
......@@ -51,6 +52,7 @@
<v-flex sm4 xs12 class="px-3">
<label class="font-weight-bold">อีเมล <span class="red--text">&nbsp;*</span></label>
<v-text-field
readonly
outline
label="อีเมล"
v-model="company_data.email"
......@@ -227,7 +229,7 @@
<span >เพื่อความสะดวกในการเดินทางของผู้สมัครงาน กรุณาระบุสถานีรถไฟฟ้าที่ใกล้กับสถานที่ปฏิบัติงาน (ถ้ามี) หรือระบุสายรถเมล์ที่ผ่านสถานที่ประกอบการ และระบุการเดินทางเพิ่มเติม เพื่อให้เข้าใจในการเดินทางมากยิ่งขึ้น</span>
</v-flex>
<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-flex>
......@@ -240,6 +242,7 @@
export default {
data () {
return {
loading: false,
status: 'ยังไม่ได้เลือกไฟล์',
nameImage: null,
company_data: {
......@@ -264,7 +267,8 @@ export default {
mrt: '',
arl: '',
bus: '',
another: ''
another: '',
check: false
},
rules: {
required: v => !!v || 'จำเป็นต้องกรอก',
......@@ -403,22 +407,25 @@ export default {
}
},
createJob () {
this.loading = true
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.company_data.zip_code === ' ') {this.company_data.zip_code = ''}
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.amphoe = this.amphoe.amphoe
this.company_data.tumbon = this.tumbon.tumbon
axios.post('/companys', this.company_data)
axios.post('/api/companys', this.company_data)
.then(res => {
console.log(res)
this.loading = false
this.$router.push('/employer')
})
.catch(err => {
console.log(err.response)
this.loading = false
})
} else {
this.loading = false
this.$Loading.error()
}
},
......@@ -484,8 +491,51 @@ export default {
})
}
},
mounted() {
beforeMount() {
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>
......
......@@ -4,6 +4,7 @@
<meta charset="utf-8">
<!-- <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="csrf-token" content="{{ csrf_token() }}">
<!-- <meta name="csrf-token" content="{{ csrf_token() }}"> -->
<title>CO-OP Search</title>
......
......@@ -19,6 +19,10 @@ Route::group(['prefix' => 'auth'], function ($router) {
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/{province_code}/amphoe','DistrictController@amphoes');
Route::get('/province/{province_code}/amphoe/{amphoe_code}/district','DistrictController@districts');
......
......@@ -12,5 +12,3 @@
*/
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