* Display app version.

* Fix: FPrint enroll start/stop toggle.
This commit is contained in:
2022-01-26 11:14:22 +01:00
parent f9ef35103c
commit 8bbfb59c6b
3 changed files with 56 additions and 29 deletions
+32 -8
View File
@@ -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
+12 -11
View File
@@ -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': { },
+12 -10
View File
@@ -18,7 +18,7 @@
</div>
<h1>
{{domain.name}} Biometrics Enrolment Wizard
{{domain.name}} Biometrics Enrolment Wizard <span style="color: gainsboro">#{{version}}</span>
</h1>
<hr />
<div v-if="step > 0" style="text-align: right">
@@ -114,16 +114,17 @@
<label>Enrolment ID</label>
<input type="text" readonly v-model="fingerDetails['right-thumb'].id" class="form-control" />
</div>
<div class="btn btn-success" style="display: inline" v-if="!fingerDetails['right-thumb'].id" v-bind:class="{ disabledbutton: busy.login }"
<div class="btn btn-success" style="display: inline" v-if="!fingerDetails['right-thumb'].id" v-bind:class="{ disabledbutton: busy.capture }"
v-on:click="() => { captureFingerPrint('right-thumb') }">
<span v-if="!busy.login">Capture Fingerprint</span>
<span v-if="!busy.capture">Capture Fingerprint</span>
<span v-else>Please wait...</span>
</div>
<div class="btn btn-warning" style="display: inline" v-if="fingerDetails['right-thumb'].id" v-bind:class="{ disabledbutton: busy.login }"
<div class="btn btn-warning" style="display: inline" v-if="fingerDetails['right-thumb'].id" v-bind:class="{ disabledbutton: busy.capture }"
v-on:click="() => { captureFingerPrint('right-thumb') }">
<span v-if="!busy.login">Recapture Fingerprint</span>
<span v-if="!busy.capture">Recapture Fingerprint</span>
<span v-else>Please wait...</span>
</div>
<span style="cursor:pointer;" @click="cancelCapture" v-if="busy.capture">&nbsp;&nbsp;Cancel</span>
</div>
<div class="col-md-6">
<div class="form-group">
@@ -134,16 +135,17 @@
<label>Enrolment ID</label>
<input type="text" readonly v-model="fingerDetails['right-index-finger'].id" class="form-control" />
</div>
<div class="btn btn-success" style="display: inline" v-if="!fingerDetails['right-index-finger'].id" v-bind:class="{ disabledbutton: busy.login }"
<div class="btn btn-success" style="display: inline" v-if="!fingerDetails['right-index-finger'].id" v-bind:class="{ disabledbutton: busy.capture }"
v-on:click="() => { captureFingerPrint('right-index-finger') }">
<span v-if="!busy.login">Capture Fingerprint</span>
<span v-if="!busy.capture">Capture Fingerprint</span>
<span v-else>Please wait...</span>
</div>
<div class="btn btn-warning" style="display: inline" v-if="fingerDetails['right-index-finger'].id" v-bind:class="{ disabledbutton: busy.login }"
<div class="btn btn-warning" style="display: inline" v-if="fingerDetails['right-index-finger'].id" v-bind:class="{ disabledbutton: busy.capture }"
v-on:click="() => { captureFingerPrint('right-index-finger') }">
<span v-if="!busy.login">Recapture Fingerprint</span>
<span v-if="!busy.capture">Recapture Fingerprint</span>
<span v-else>Please wait...</span>
</div>
</div>
<span style="cursor:pointer;" @click="cancelCapture" v-if="busy.capture">&nbsp;&nbsp;Cancel</span>
</div>
</div>
<!-- &nbsp;&nbsp;Your profile has <span style="color: red; font-weight: bold;" v-if="!staff.verified">NOT </span>been verified. -->