05/19 Update QR code photo verification togglable

This commit is contained in:
2026-05-19 13:20:52 -04:00
parent 5e0c014ca7
commit 74e0b71a11
5 changed files with 1665 additions and 1542 deletions
+16 -3
View File
@@ -160,6 +160,8 @@ def create_qr_code():
styles=QRCodeStyle.query.all())
# Create new QR code record first (without URL and image)
photo_verification_enabled = request.form.get('photo_verification_enabled', '1') != '0'
new_qr_code = QRCode(
name=name,
location=location,
@@ -174,6 +176,7 @@ def create_qr_code():
coordinate_accuracy=coordinate_accuracy if has_coordinates else None,
coordinates_updated_date=datetime.utcnow() if has_coordinates else None,
qr_type=qr_type, # ADDED: store QR type
photo_verification_enabled=photo_verification_enabled,
# NEW: Customization fields (only if columns exist)
**({
'fill_color': fill_color,
@@ -220,6 +223,7 @@ def create_qr_code():
'location_address': location_address,
'location_event': location_event,
'has_coordinates': has_coordinates,
'photo_verification_enabled': photo_verification_enabled,
'customization': {
'fill_color': fill_color,
'back_color': back_color,
@@ -514,6 +518,9 @@ def edit_qr_code(qr_id):
else:
qr_code.project_id = None
# Per-QR photo verification toggle
qr_code.photo_verification_enabled = request.form.get('photo_verification_enabled', '1') != '0'
# Handle QR code customization (only if columns exist)
fill_color = request.form.get('fill_color', '#000000')
back_color = request.form.get('back_color', '#FFFFFF')
@@ -558,6 +565,11 @@ def edit_qr_code(qr_id):
db.session.commit()
logger_handler.logger.info(
f"QR Code '{qr_code.name}' (ID: {qr_id}) updated by user {session.get('username', 'unknown')}"
f"photo_verification_enabled={qr_code.photo_verification_enabled}"
)
# Success message
flash(f'QR Code "{qr_code.name}" updated successfully!', 'success')
return redirect(url_for('dashboard.dashboard'))
@@ -890,11 +902,12 @@ def qr_checkin(qr_url):
logger_handler.logger.warning("Could not calculate location accuracy — calculation returned None")
# CHECK DISTANCE THRESHOLD FOR PHOTO VERIFICATION
logger_handler.logger.debug(f"Photo verification enabled: {current_app.config.get('PHOTO_VERIFICATION_ENABLED', True)}")
logger_handler.logger.debug(f"Photo verification — global: {current_app.config.get('PHOTO_VERIFICATION_ENABLED', True)}, per-QR: {getattr(qr_code, 'photo_verification_enabled', True)}")
requires_verification = False
verification_photo_data = None
if current_app.config.get('PHOTO_VERIFICATION_ENABLED', True) and location_accuracy is not None and location_accuracy > current_app.config.get('DISTANCE_THRESHOLD_FOR_VERIFICATION', 0.3):
qr_photo_verification = getattr(qr_code, 'photo_verification_enabled', True)
if qr_photo_verification and current_app.config.get('PHOTO_VERIFICATION_ENABLED', True) and location_accuracy is not None and location_accuracy > current_app.config.get('DISTANCE_THRESHOLD_FOR_VERIFICATION', 0.3):
logger_handler.logger.info(f"Distance ({location_accuracy:.3f} mi) exceeds verification threshold for employee {employee_id}")
# Check if photo was provided
@@ -1224,4 +1237,4 @@ def deactivate_qr_code(qr_id):
return jsonify({
'success': False,
'message': 'Error deactivating QR code. Please try again.'
}), 500
}), 500