Public Access
Fixed Pin
This commit is contained in:
1 parent
ef0686a63e
commit
06b4616356
5 files changed
+74
-4
No files matched your search
+27
-1
@@ -941,6 +941,18 @@ router.patch('/frequent/:id', (req, res) => {
|
||||
photoPath = null;
|
||||
}
|
||||
|
||||
// A PIN typed into the edit form has to actually be set. It used to be
|
||||
// accepted and ignored, so an admin would hand out a PIN the kiosk had never
|
||||
// heard of. Blank means "leave the current one alone".
|
||||
const requestedPin = String(req.body?.pin ?? '').trim();
|
||||
let newPin = null;
|
||||
if (requestedPin) {
|
||||
if (!/^\d{4}$/.test(requestedPin)) {
|
||||
throw new Error('A PIN must be exactly 4 digits. Leave it blank to keep the current one.');
|
||||
}
|
||||
newPin = allocatePin(requestedPin, row.id);
|
||||
}
|
||||
|
||||
db.prepare(
|
||||
`UPDATE frequent_visitors SET first_name = ?, last_name = ?, company = ?, phone = ?, email = ?,
|
||||
check_type = ?, check_number = ?, check_expiry = ?, default_host_id = ?, site_id = ?,
|
||||
@@ -954,7 +966,21 @@ router.patch('/frequent/:id', (req, res) => {
|
||||
req.body?.active !== undefined ? (req.body.active ? 1 : 0) : row.active,
|
||||
row.id
|
||||
);
|
||||
res.json(shapeFrequent(db.prepare('SELECT * FROM frequent_visitors WHERE id = ?').get(row.id), true));
|
||||
|
||||
if (newPin) {
|
||||
db.prepare(
|
||||
"UPDATE frequent_visitors SET pin_enc = ?, pin_lookup = ?, updated_at = datetime('now') WHERE id = ?"
|
||||
).run(encryptPin(newPin), pinLookup(newPin), row.id);
|
||||
}
|
||||
|
||||
// Attempt counters are keyed by phone number, so a changed number would
|
||||
// otherwise leave a stale lockout behind under the old one.
|
||||
db.prepare('DELETE FROM pin_attempts WHERE phone IN (?, ?)').run(row.phone, v.phone);
|
||||
|
||||
res.json({
|
||||
...shapeFrequent(db.prepare('SELECT * FROM frequent_visitors WHERE id = ?').get(row.id), true),
|
||||
pinChanged: Boolean(newPin),
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(400).json({ error: err.message });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user