Skip to content

Commit b505113

Browse files
committed
Added basic auth logic for leed scanning
1 parent 67ee3dd commit b505113

File tree

9 files changed

+212
-25
lines changed

9 files changed

+212
-25
lines changed

src/components/Common/QRCamera.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useCameraStore } from '@/stores/camera'
55
import { useProcessRegistrationStore } from '@/stores/processRegistration'
66
import { useProcessCheckInStore } from '@/stores/processCheckIn'
77
import { useProcessDeviceStore } from '@/stores/processDevice'
8+
import { useProcessEventyayCheckInStore } from '@/stores/processEventyayCheckIn'
89
910
const props = defineProps({
1011
qrType: {
@@ -25,7 +26,7 @@ const cameraStore = useCameraStore()
2526
const processRegistrationStore = useProcessRegistrationStore()
2627
const processCheckInStore = useProcessCheckInStore()
2728
const processDeviceStore = useProcessDeviceStore()
28-
29+
const processEventyayCheckIn = useProcessEventyayCheckInStore()
2930
const route = useRoute()
3031
const stationId = route.params.stationId
3132
const scannerType = route.params.scannerType
@@ -40,11 +41,10 @@ async function processQR() {
4041
await processCheckInStore.checkInAttendeeScannerToRoom(stationId, scannerType)
4142
}
4243
if (props.qrType === 'device') {
43-
await processDeviceStore.authDevice(cameraStore.qrCodeValue)
44+
await processDeviceStore.authDevice()
4445
}
4546
if (props.qrType === 'eventyaycheckin') {
46-
console.log(cameraStore.qrCodeValue)
47-
console.log('Check-in')
47+
await processEventyayCheckIn.checkIn()
4848
}
4949
cameraStore.paused = false
5050
}

src/components/Eventyay/EventyayEventSelection.vue

+16-7
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@ const router = useRouter()
1010
function checkIn() {
1111
router.push({ name: 'eventyayevents' })
1212
}
13+
function leadscan() {
14+
router.push({ name: 'eventyayleedlogin' })
15+
}
1316
</script>
1417

1518
<template>
1619
<div
1720
class="-mt-16 grid h-screen w-full grid-cols-1 place-items-center items-center justify-center align-middle"
1821
>
19-
<StandardButton :text="'Lead Scanning'" class="btn-primary mt-6 w-full justify-center" />
20-
<p class="text-xl">OR</p>
21-
<StandardButton
22-
:text="'Check-In'"
23-
class="btn-primary mt-6 w-full justify-center"
24-
@click="checkIn()"
25-
/>
22+
<div class="flex h-1/4 w-1/2 flex-col items-center justify-around">
23+
<StandardButton
24+
:text="'Lead Scanning'"
25+
class="btn-primary h-14 w-full justify-center"
26+
@click="leadscan()"
27+
/>
28+
<p class="text-xl">OR</p>
29+
<StandardButton
30+
:text="'Check-In'"
31+
class="btn-primary h-14 w-full justify-center"
32+
@click="checkIn()"
33+
/>
34+
</div>
2635
</div>
2736
</template>

src/components/Eventyay/EventyayEvents.vue

+12-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ watchEffect(() => {
2626
})
2727
2828
const submitForm = () => {
29+
if (localStorage.getItem('selectedEventSlug') || localStorage.getItem('selectedEventName')) {
30+
localStorage.removeItem('selectedEventSlug')
31+
localStorage.removeItem('selectedEventName')
32+
}
33+
2934
if (selectedEvent.value) {
30-
localStorage.setItem('selectedEvent', selectedEvent.value)
31-
router.push({ name: 'eventyaycheckin' })
35+
const selectedEventData = events.find((event) => event.slug === selectedEvent.value)
36+
if (selectedEventData) {
37+
localStorage.setItem('selectedEventSlug', selectedEventData.slug)
38+
localStorage.setItem('selectedEventName', selectedEventData.name.en)
39+
router.push({ name: 'eventyaycheckin' })
40+
}
3241
} else {
3342
console.error('Please select an event.')
3443
}
@@ -57,7 +66,7 @@ const submitForm = () => {
5766
No events available
5867
<StandardButton
5968
:text="'Refresh'"
60-
class="btn-primary mt-6 w-full justify-center"
69+
class="btn-primary mt-6 w-1/2 justify-center"
6170
@click="fetchEvents(url.value, apiToken.value, organiser.value)"
6271
/>
6372
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<script setup>
2+
import { ref, onMounted } from 'vue'
3+
import { useRouter } from 'vue-router'
4+
import { useLoadingStore } from '@/stores/loading'
5+
import { useAuthStore } from '@/stores/auth'
6+
import { useUserStore } from '@/stores/user'
7+
import { useleedauth } from '@/stores/leedauth'
8+
import StandardButton from '@/components/Common/StandardButton.vue'
9+
10+
const loadingStore = useLoadingStore()
11+
const authStore = useAuthStore()
12+
const userStore = useUserStore()
13+
const leedauth = useleedauth()
14+
const showError = ref(false)
15+
const userId = ref('')
16+
const password = ref('')
17+
const server = ref('')
18+
// router
19+
const router = useRouter()
20+
21+
async function submitLogin() {
22+
const payload = {
23+
email: email.value,
24+
key: password.value
25+
}
26+
console.log(payload)
27+
const response = await leedauth.leedlogin(payload)
28+
console.log(response)
29+
}
30+
loadingStore.contentLoaded()
31+
</script>
32+
33+
<template>
34+
<div class="-mt-16 flex h-screen flex-col justify-center">
35+
<div class="my-auto sm:mx-auto sm:w-full sm:max-w-sm">
36+
<h2 class="text-center">Sign in with your credentials</h2>
37+
<form class="mt-10 space-y-3" @submit.prevent="submitLogin">
38+
<div>
39+
<label for="email">User ID</label>
40+
<div class="mt-2">
41+
<input
42+
id="email"
43+
v-model="email"
44+
name="email"
45+
type="email"
46+
required="true"
47+
class="block w-full"
48+
/>
49+
</div>
50+
</div>
51+
52+
<div>
53+
<label for="password">Password</label>
54+
<div class="mt-2">
55+
<input
56+
id="password"
57+
v-model="password"
58+
name="password"
59+
type="password"
60+
autocomplete="current-password"
61+
required="true"
62+
class="block w-full"
63+
/>
64+
</div>
65+
</div>
66+
67+
<div>
68+
<StandardButton
69+
:type="'submit'"
70+
:text="'Login'"
71+
class="btn-primary mt-6 w-full justify-center"
72+
/>
73+
</div>
74+
75+
<div v-if="showError">
76+
<p class="text-sm text-danger">Wrong credentials or account does not exist</p>
77+
</div>
78+
</form>
79+
</div>
80+
</div>
81+
</template>

src/components/Registration/Device/Device.vue

-8
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,5 @@ async function registerDevice() {
2929
<div v-if="showError">
3030
<p class="text-sm text-danger">Oops! something went wrong</p>
3131
</div>
32-
<div>
33-
<input type="text" id="auth_token" placeholder="Device Key" class="input" />
34-
<StandardButton
35-
:text="'Register Device'"
36-
class="btn-primary mt-6 w-full justify-center"
37-
@click="registerDevice()"
38-
/>
39-
</div>
4032
</div>
4133
</template>

src/router/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CheckInStats from '@/components/CheckIn/CheckInStats.vue'
44
import EventyayEventCheckIn from '@/components/Eventyay/EventyayEventCheckIn.vue'
55
import EventyayEvents from '@/components/Eventyay/EventyayEvents.vue'
66
import EventyayEventSelection from '@/components/Eventyay/EventyayEventSelection.vue'
7+
import EventyayLeedLogin from '@/components/Eventyay/EventyayLeedLogin.vue'
78
import Device from '@/components/Registration/Device/Device.vue'
89
import RegistrationKiosk from '@/components/Registration/Kiosk/KioskOverview.vue'
910
import RegistrationStats from '@/components/Registration/Station/RegistrationStats.vue'
@@ -44,6 +45,11 @@ const router = createRouter({
4445
name: 'eventyayselect',
4546
component: EventyayEventSelection
4647
},
48+
{
49+
path: '/eventyayleedlogin',
50+
name: 'eventyayleedlogin',
51+
component: EventyayLeedLogin
52+
},
4753
{
4854
path: '/panel',
4955
name: 'auth',

src/stores/leedauth.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { mande } from 'mande'
2+
import { defineStore } from 'pinia'
3+
4+
export const useleedauth = defineStore('leedauth', () => {
5+
async function leedlogin(payload) {
6+
try {
7+
console.log('leedlogin')
8+
const url = localStorage.getItem('url')
9+
const organizer = localStorage.getItem('organizer')
10+
const slug = localStorage.getItem('selectedEventSlug')
11+
const apiToken = localStorage.getItem('api_token')
12+
console.log(url, organizer, slug, apiToken, payload)
13+
const headers = {
14+
Authorization: `Device ${apiToken}`,
15+
Accept: 'application/json'
16+
}
17+
const api = mande(url, { headers: headers })
18+
const response = await api.post(`/api/v1/event/${organizer}/${slug}/exhibitors/auth`, payload)
19+
console.log('here', response)
20+
return response
21+
} catch (error) {
22+
console.log(error)
23+
console.log('error')
24+
return 'wt'
25+
}
26+
}
27+
28+
return { leedlogin }
29+
})

src/stores/processDevice.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export const useProcessDeviceStore = defineStore('processDevice', () => {
4141
showError.value = false
4242
}
4343

44-
async function authDevice(val) {
44+
async function authDevice() {
4545
try {
46-
const qrData = JSON.parse(val)
46+
const qrData = JSON.parse(cameraStore.qrCodeValue)
4747
if (qrData.handshake_version > 1) {
4848
message.value = 'Unsupported handshake version'
4949
showErrorMsg()
@@ -60,7 +60,7 @@ export const useProcessDeviceStore = defineStore('processDevice', () => {
6060
software_version: 'x.x'
6161
}
6262
let url = qrData.url
63-
const port = import.meta.env.VITE_LOCAL_PORT || 3000
63+
const port = import.meta.env.VITE_LOCAL_PORT || 8000
6464
if (url.includes('localhost')) {
6565
url = `${url}:${port}` // Add your desired port number here
6666
}

src/stores/processEventyayCheckIn.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { useCameraStore } from '@/stores/camera'
2+
import { defineStore } from 'pinia'
3+
import { computed, ref } from 'vue'
4+
5+
export const useProcessEventyayCheckInStore = defineStore('processEventyayCheckIn', () => {
6+
const cameraStore = useCameraStore()
7+
const message = ref('')
8+
const showSuccess = ref(false)
9+
const showError = ref(false)
10+
function $reset() {
11+
message.value = ''
12+
showSuccess.value = false
13+
showError.value = false
14+
}
15+
16+
const response = computed(() => {
17+
let classType = ''
18+
if (showSuccess.value) {
19+
classType = 'text-success'
20+
}
21+
if (showError.value) {
22+
classType = 'text-danger'
23+
}
24+
return {
25+
message: message.value,
26+
class: classType
27+
}
28+
})
29+
30+
function showErrorMsg() {
31+
showSuccess.value = false
32+
showError.value = true
33+
}
34+
35+
function showSuccessMsg() {
36+
showSuccess.value = true
37+
showError.value = false
38+
}
39+
40+
async function checkIn() {
41+
const qrData = JSON.parse(cameraStore.qrCodeValue)
42+
const event = localStorage.getItem('selectedEventName')
43+
44+
if (qrData.event === event) {
45+
console.log(cameraStore.qrCodeValue)
46+
message.value = 'Check in successful'
47+
showSuccessMsg()
48+
} else {
49+
console.log(qrData.event)
50+
console.log(event)
51+
message.value = 'Invalid Event'
52+
showErrorMsg()
53+
}
54+
}
55+
56+
return {
57+
response,
58+
checkIn,
59+
$reset
60+
}
61+
})

0 commit comments

Comments
 (0)