Skip to content

Commit

Permalink
Merge pull request #38 from Mala1180/feature/login-popup
Browse files Browse the repository at this point in the history
add popup for login
  • Loading branch information
paga16-hash authored Feb 1, 2024
2 parents a306973 + 3bb4ea5 commit 8a03f95
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
6 changes: 3 additions & 3 deletions alarm/db/alarm-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ db.securityRule.insert([
value: 'email@gmail.com'
}
],
from: new Date("2020-01-01T03:00:00.000Z"),
to: new Date("2030-01-01T01:00:00.000Z"),
from: new Date("2020-01-01T01:00:00.000Z"),
to: new Date("2030-01-01T05:00:00.000Z"),
__v: 0
},
{
Expand All @@ -92,7 +92,7 @@ db.securityRule.insert([
}
],
from: new Date("2020-01-01T01:00:00.000Z"),
to: new Date("2030-01-01T01:00:00.000Z"),
to: new Date("2030-01-01T05:00:00.000Z"),
__v: 0
}
])
Expand Down
6 changes: 3 additions & 3 deletions alarm/src/routes/securityRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ securityRuleRouter.route('/exceedings').post((req: Request, res: Response): void
.then((): void => {
res.status(HttpStatusCode.CREATED).send({ success: 'Exceeding rule created' })
})
.catch((err): void => {
console.log(err)
.catch((): void => {
res.send({ error: 'Exceeding rule not created' })
})
})
Expand All @@ -81,7 +80,8 @@ securityRuleRouter.route('/intrusions').post((req: Request, res: Response): void
.then((): void => {
res.status(HttpStatusCode.CREATED).send({ success: 'Intrusion rule created' })
})
.catch((): void => {
.catch((err): void => {
console.log(err)
res.send({ error: 'Intrusion rule not created' })
})
})
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/devices/DeviceBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const $q = useQuasar()
const updateSensor = async (sensor: Sensor) => {
await RequestHelper.put(`http://${monitoringHost}:${monitoringPort}/devices/sensors`, {
code: sensor.deviceId.code,
isCapturing: sensor.isCapturing,
ipAddress: sensor.ipAddress,
intervalMillis: sensor.intervalMillis,
measures: sensor.measures.map((m: Measure) => {
Expand All @@ -41,6 +42,7 @@ const updateSensor = async (sensor: Sensor) => {
const updateCamera = async (camera: Camera) => {
await RequestHelper.put(`http://${monitoringHost}:${monitoringPort}/devices/cameras`, {
code: camera.deviceId.code,
isCapturing: camera.isCapturing,
ipAddress: camera.ipAddress,
resolution: {
width: parseInt(camera.resolution.width.toString()),
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/devices/UpdateDevicePopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const resolutionFactory: ResolutionFactory = new ResolutionFactoryImpl()
const measures: ref<Measure[]> = ref([])
if (device.deviceId.type == DeviceType.SENSOR) {
measures.value = (device as Sensor).measures
}
const options = ref([
{
label: 'Temperature',
Expand All @@ -39,6 +43,7 @@ const updateDevice = () => {
if (device.deviceId.type == DeviceType.SENSOR) {
const updatedSensor: Sensor = deviceFactory.createSensor(
deviceIdFactory.createSensorId(device.deviceId.code),
device.isCapturing,
device.ipAddress,
(device as Sensor).intervalMillis,
measures.value
Expand All @@ -47,6 +52,7 @@ const updateDevice = () => {
} else if (device.deviceId.type == DeviceType.CAMERA) {
const updatedCamera: Camera = deviceFactory.createCamera(
deviceIdFactory.createCameraId(device.deviceId.code),
device.isCapturing,
device.ipAddress,
resolutionFactory.createResolution(
(device as Camera).resolution.width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ const getSensorCodes = async () => {
const optionsContacts: ref<{ label: string; value: string }> = ref([])
const getContacts = async () => {
await RequestHelper.get(`http://${authHost}:${authPort}/users/aaaaaaaaaaaaaaaaaaaaaaaa`) //to put the id of the user taken from the pinia storage
console.log('TOKEN')
console.log(useUserStore().userId)
await RequestHelper.get(`http://${authHost}:${authPort}/users/${useUserStore().userId}`)
.then((res: any) => {
optionsContacts.value = []
for (let i = 0; i < res.data.contacts.length; i++) {
Expand Down Expand Up @@ -133,7 +135,7 @@ const addNewSecurityRule = () => {
useUserStore().userId,
toRaw(contacts.value).map((c: { label: string; value: string }) => {
return {
type: toRaw(c).label,
type: toRaw(c).label.split(':')[0],
value: toRaw(c).value
}
}),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/RequestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const alarmPort: string = import.meta.env.VITE_ALARM_PORT || '4002'

export default class RequestHelper {
static getHeaders(): Headers {
return { headers: { Authorization: `Bearer apikey-dev` } } //${userStore().accessToken}
return { headers: { Authorization: `Bearer ${userStore().accessToken}` } }
}

static async get(url: string, params?: any): Promise<AxiosResponse> {
Expand Down
31 changes: 18 additions & 13 deletions frontend/src/views/LoginView.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
<script setup lang="ts">
import { ref } from 'vue'
import RequestHelper, { authHost, authPort } from '@/utils/RequestHelper'
import { type AxiosResponse, HttpStatusCode as AxiosHttpStatusCode } from 'axios'
import router from '@/router'
import { useUserStore } from '@/stores/user'
import { useQuasar } from 'quasar'
import { popNegative } from '@/scripts/Popups'
const username = ref('')
const password = ref('')
const userStore = useUserStore()
const $q = useQuasar()
const login = async () => {
const res: AxiosResponse = await RequestHelper.post(`http://${authHost}:${authPort}/login`, {
const login = () => {
RequestHelper.post(`http://${authHost}:${authPort}/login`, {
username: username.value,
password: password.value
})
if (res.status !== AxiosHttpStatusCode.Ok) {
console.log(`Login failed with status code ${res.status} and message ${res.data.message}`)
return
}
userStore.username = username.value
userStore.userId = res.data.userId
userStore.accessToken = res.data.accessToken
userStore.refreshToken = res.data.refreshToken
userStore.isLoggedIn = true
router.push('/home')
.then((res: any) => {
userStore.username = username.value
userStore.userId = res.data.userId
userStore.accessToken = res.data.accessToken
userStore.refreshToken = res.data.refreshToken
userStore.isLoggedIn = true
router.push('/home')
})
.catch(() => {
popNegative($q, 'Login failed')
username.value = ''
password.value = ''
})
}
</script>

Expand Down

0 comments on commit 8a03f95

Please sign in to comment.