Files
tools-legacy/public/capture/app.js
T

156 lines
5.0 KiB
JavaScript
Raw Normal View History

2021-12-08 14:35:55 +01:00
var app = new Vue({
el: '#app',
data: {
step: 0,
phone: '',
domain: { code: 'uc', name: 'UNICAL' },
2021-12-08 14:35:55 +01:00
errorMessage: '',
2022-01-26 11:14:22 +01:00
version: '',
2021-12-08 14:35:55 +01:00
otp: '',
busy: {
2022-01-26 11:14:22 +01:00
login: false,
capture: false,
2021-12-08 14:35:55 +01:00
},
user: {
phone: '',
username: '',
roles: []
},
staff: {
reference: ''
},
fingerDetails: {
'right-thumb': { },
'right-index-finger': { }
},
socket: null
},
created: function () {
var userStr = localStorage.getItem("user");
if (userStr) {
this.user = JSON.parse(userStr);
this.step = 1;
}
this.socket = io();
this.socket.on("connect", () => { })
this.socket.on("config", (data) => {
this.domain = data.domain;
2022-01-26 11:14:22 +01:00
this.version = data.version;
2022-09-07 13:18:42 +01:00
this.device = data.device;
});
2021-12-08 16:14:57 +01:00
this.socket.on("fprint-enroll-error", (data) => {
console.log({ event: 'enroll-error', data });
swal("Oops!", `Operation failed. ${data}.`, "error");
2022-01-26 11:14:22 +01:00
this.busy.capture = false;
2021-12-08 16:14:57 +01:00
});
2021-12-08 14:35:55 +01:00
this.socket.on("fprint-enroll-done", (data) => {
console.log({ event: 'enroll-done', data});
if (data.ok) {
let { id, fingerprint, data: { finger }} = data;
this.step = 1.2;
this.fingerDetails[finger] = { id, fingerprint, finger }
}
2022-01-26 11:14:22 +01:00
this.busy.capture = false;
});
2021-12-08 14:35:55 +01:00
this.socket.on("fprint-verify-done", (data) => {
console.log({ event: 'verify-done', data});
});
},
methods: {
authenticateUrl: function (api, authenticate = true) {
return `https://apis.a2loft.net/identity${api}` + (authenticate ? `?phone=${this.user.phone}&otp=${this.otp}` : '');
},
login: async function () {
this.busy.login = true;
var { data } = await axios.get(
this.authenticateUrl(`/validate/uc/${this.phone}/${this.otp}`, false)
);
this.errorMessage = '';
if (!data.ok)
this.errorMessage = "Invalid OTP specified.";
else {
localStorage.setItem("user", JSON.stringify(data.data));
this.user = data.data;
this.step = 1.0;
}
this.busy.login = false;
},
logout: function () {
localStorage.removeItem("user");
this.step = 0;
},
loadUserByReference: async function () {
this.busy.login = true;
try {
var { data } = await axios.get(
this.authenticateUrl(`/${this.domain.code}/${this.staff.reference}`)
2021-12-08 14:35:55 +01:00
);
if (!data.ok) {
swal("Oops!", `Operation failed. ${data.message}.` + this.staff.reference, "error");
} else {
this.staff = data.data;
// this.staff.verified = false;
this.step = 1.1;
}
} finally {
this.busy.login = false;
}
},
captureFingerPrint: async function (finger) {
2022-01-26 11:14:22 +01:00
this.busy.capture = true;
2021-12-08 14:35:55 +01:00
this.step = 1.1;
this.socket.emit("fprint-enroll", { finger });
},
2022-01-26 11:14:22 +01:00
cancelCapture: async function () {
this.socket.emit("fprint-enroll-stop", { });
},
2021-12-08 14:35:55 +01:00
saveFingerPrint: async function () {
this.busy.login = true;
try {
2021-12-08 16:14:57 +01:00
var fingerprints = Object.keys(this.fingerDetails).map(finger => {
2021-12-08 14:35:55 +01:00
return {
finger,
2021-12-08 17:34:01 +01:00
fingerprint: this.fingerDetails[finger].fingerprint
2021-12-08 14:35:55 +01:00
}
});
2021-12-08 17:36:11 +01:00
if (fingerprints.length < 2) {
swal("Oops!", 'Please capture the two fingers for this profile.', "error");
return;
}
2021-12-08 14:35:55 +01:00
var { data } = await axios.post(
this.authenticateUrl(`/${this.domain.code}/fingerprints/${this.staff.reference}`),
2021-12-08 14:35:55 +01:00
{ fingerprints }
);
if (data.ok) {
swal("Saved", `Fingerprint saved for ${this.staff.name} with reference ${this.staff.reference}.`, "success");
this.newEnrolment();
} else {
swal("Oops!", `Operation failed. ${data.message}.` + this.staff.reference, "error");
}
} finally {
this.busy.login = false;
}
},
newEnrolment: function () {
this.step = 1.0;
2021-12-13 13:59:09 +01:00
this.busy.login = false;
2022-01-26 11:14:22 +01:00
this.busy.capture = false;
2021-12-08 14:35:55 +01:00
this.staff.reference = "";
2021-12-13 13:59:09 +01:00
this.fingerDetails = {
'right-thumb': { },
'right-index-finger': { }
};
2021-12-08 14:35:55 +01:00
}
}
2022-09-07 13:18:42 +01:00
})