Add NFC chore submission feature and enhance family settings
- Introduced NFC support for chore submissions, allowing specific person credit after Head of Household approval. - Updated family settings to include NFC base URL, scan cooldown, and confirmation page options. - Enhanced chore management with options for anyone to complete chores and NFC link generation. - Improved API endpoints for handling NFC tokens and chore submissions. - Updated readme to reflect new NFC features and settings.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../includes/api_bootstrap.php';
|
||||
require_once __DIR__ . '/../includes/chore_helpers.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
sendJson(['success' => false, 'error' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
$people = migrateAllPeople(normalizePeopleList(readJsonFile('people.json')));
|
||||
$actor = requireActivePerson($people);
|
||||
if (($actor['role'] ?? '') !== ROLE_HEAD || !isHohVerified()) {
|
||||
sendJson(['success' => false, 'error' => 'Only a verified Head of household can rotate NFC person tokens'], 403);
|
||||
}
|
||||
|
||||
$body = readJsonBody();
|
||||
$personId = isset($body['person_id']) ? trim((string) $body['person_id']) : '';
|
||||
if ($personId === '') {
|
||||
sendJson(['success' => false, 'error' => 'person_id is required'], 400);
|
||||
}
|
||||
|
||||
$match = null;
|
||||
foreach ($people as $i => $person) {
|
||||
if (($person['id'] ?? '') === $personId) {
|
||||
$match = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($match === null) {
|
||||
sendJson(['success' => false, 'error' => 'Person not found'], 404);
|
||||
}
|
||||
|
||||
$token = generateOpaqueToken();
|
||||
$people[$match]['nfc_submit_token_hash'] = hashOpaqueToken($token);
|
||||
$people[$match]['nfc_submit_token_updated_at'] = gmdate('c');
|
||||
|
||||
if (!writeJsonFile('people.json', $people)) {
|
||||
sendJson(['success' => false, 'error' => 'Failed to save person token'], 500);
|
||||
}
|
||||
|
||||
sendJson([
|
||||
'success' => true,
|
||||
'person_id' => $personId,
|
||||
'person_name' => (string) ($people[$match]['name'] ?? $personId),
|
||||
'person_token' => $token,
|
||||
]);
|
||||
Reference in New Issue
Block a user