From 8bbfb59c6b0436d0b1ebb619f4e4c19fe35b8b58 Mon Sep 17 00:00:00 2001 From: "ADEBISI, Foluso A. (Dell-XPS)" Date: Wed, 26 Jan 2022 11:14:22 +0100 Subject: [PATCH] * Display app version. * Fix: FPrint enroll start/stop toggle. --- app.py | 40 +++++++++++++++++++++++++++++++-------- public/capture/app.js | 23 +++++++++++----------- public/capture/index.html | 22 +++++++++++---------- 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/app.py b/app.py index 08d0ece..26b4e09 100644 --- a/app.py +++ b/app.py @@ -5,7 +5,8 @@ import base64 import os import requests from flask import Flask - +import subprocess + import gi gi.require_version("FPrint", "2.0") gi.require_version("Gio", "2.0") @@ -46,7 +47,10 @@ def progress(device, completed_stages, prnt, sessionId, error): else: print('Completed with an error.') -def enroll(sessionId, data): +enroll_canceller = None; +def enroll_start(sessionId, data): + global enroll_canceller; + ctx = FPrint.Context() devices = ctx.get_devices() if (len(devices) == 0): @@ -64,14 +68,20 @@ def enroll(sessionId, data): print('Opening...') try: prt = FPrint.Print.new(device) - prt = device.enroll_sync(prt, None, progress_cb=progress, progress_data=sessionId) + enroll_canceller = Gio.Cancellable.new(); + prt = device.enroll_sync(prt, enroll_canceller, progress_cb=progress, progress_data=sessionId) img = prt.serialize() sio.emit('fprint-enroll-done', { 'ok': True, "fingerprint": base64.b64encode(img).decode('utf-8'), 'id': str(uuid.uuid4()), 'data': data }) except Exception as e: print({'error': e}); - sio.emit('fprint-enroll-done', { 'ok': False, 'message': e}) + sio.emit('fprint-enroll-done', { 'ok': False, 'message': e.message}) finally: - device.close_sync() + try: + device.close_sync() + except: + print('An error occured while closing device.'); + finally: + print('It appears device has already been removed.') is_verify_active = False device = None; @@ -208,6 +218,14 @@ def stop_fprint_identify(): sio.emit("fprint-identify-stop-done", { 'ok': True, 'message': 'Identification stopped.' }) is_identify_active = False; + +def stop_fprint_enroll(): + global enroll_canceller; + + if enroll_canceller: + enroll_canceller.cancel() + + sio.emit("fprint-enroll-done", { 'ok': False, 'message': 'Enrollment stopped.' }) @sio.on("fprint-identify-start") def fprint_identify_start(sid, data): @@ -218,11 +236,15 @@ def fprint_identify_stop(sid, data): stop_fprint_identify() @sio.on("fprint-enroll") -def fprint_enroll(sid, data): +def fprint_enroll_start(sid, data): print('Enrolling {}'.format(data['finger'])) - enroll(sid, data) + enroll_start(sid, data) pass +@sio.on("fprint-enroll-stop") +def fprint_enroll_stop(sid, data): + stop_fprint_enroll() + @sio.event def capture(sid, data): print(data) @@ -231,6 +253,7 @@ def capture(sid, data): @sio.event def connect(sid, data): global config; + config['version'] = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() if config['mode'] == 'clockio': global raw_prints; stop_fprint_identify(); @@ -241,7 +264,6 @@ def connect(sid, data): if responseJson['ok']: config['departments'] = responseJson['data']; domain_fprint_file = '{}/fprint-sync/.{}-fprint-data.json'.format(os.getenv("HOME"), domain_code); - print(domain_fprint_file); if os.path.exists(domain_fprint_file): with open(domain_fprint_file) as f: records = json.loads(f.read()); @@ -254,6 +276,8 @@ def connect(sid, data): 'length': len(records['profiles']), 'timestamp': records['timestamp'] }; + else: + stop_fprint_enroll(); sio.emit('config', config); pass diff --git a/public/capture/app.js b/public/capture/app.js index aa5ddaf..0992820 100644 --- a/public/capture/app.js +++ b/public/capture/app.js @@ -6,9 +6,11 @@ var app = new Vue({ phone: '', domain: { code: 'uc', name: 'UNICAL' }, errorMessage: '', + version: '', otp: '', busy: { - login: false + login: false, + capture: false, }, user: { phone: '', @@ -37,12 +39,13 @@ var app = new Vue({ this.socket.on("config", (data) => { this.domain = data.domain; + this.version = data.version; }); this.socket.on("fprint-enroll-error", (data) => { console.log({ event: 'enroll-error', data }); swal("Oops!", `Operation failed. ${data}.`, "error"); - this.busy.login = false; + this.busy.capture = false; }); this.socket.on("fprint-enroll-done", (data) => { @@ -52,8 +55,8 @@ var app = new Vue({ this.step = 1.2; this.fingerDetails[finger] = { id, fingerprint, finger } } - this.busy.login = false; - }) + this.busy.capture = false; + }); this.socket.on("fprint-verify-done", (data) => { console.log({ event: 'verify-done', data}); @@ -100,16 +103,13 @@ var app = new Vue({ } }, captureFingerPrint: async function (finger) { - this.busy.login = true; + this.busy.capture = true; this.step = 1.1; - // var { data: { success, message: { id, data, fingerprint } } } = await axios.post("http://localhost:9000/api/user", { - // name: this.staff.reference - // }); - // this.fingerDetails = { id, fingerprint }; - // var { data } = await axios.delete(`http://localhost:9000/api/user/${id}`); - // console.log(`${id} purged.`); this.socket.emit("fprint-enroll", { finger }); }, + cancelCapture: async function () { + this.socket.emit("fprint-enroll-stop", { }); + }, saveFingerPrint: async function () { this.busy.login = true; try { @@ -143,6 +143,7 @@ var app = new Vue({ newEnrolment: function () { this.step = 1.0; this.busy.login = false; + this.busy.capture = false; this.staff.reference = ""; this.fingerDetails = { 'right-thumb': { }, diff --git a/public/capture/index.html b/public/capture/index.html index e3e1c5c..ae2e516 100644 --- a/public/capture/index.html +++ b/public/capture/index.html @@ -18,7 +18,7 @@

- {{domain.name}} Biometrics Enrolment Wizard + {{domain.name}} Biometrics Enrolment Wizard #{{version}}


@@ -114,16 +114,17 @@
-
- Capture Fingerprint + Capture Fingerprint Please wait...
-
- Recapture Fingerprint + Recapture Fingerprint Please wait...
+   Cancel
@@ -134,16 +135,17 @@
-
- Capture Fingerprint + Capture Fingerprint Please wait...
-
- Recapture Fingerprint + Recapture Fingerprint Please wait... -
+
+   Cancel