Skip to content

Commit 47e45f7

Browse files
committed
2 Feb 2024
1) Small UI fixes and general cleanup. 2) NFC login cleanup. 3) QR login cleanup.
1 parent 6c6b653 commit 47e45f7

File tree

12 files changed

+161
-144
lines changed

12 files changed

+161
-144
lines changed

TODO.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* Update reactions module JS
2+
* New GPS tracking module
3+
* New admin file manager
4+
* New login with FB
5+
* Paypal
6+
* Stripe
7+
* Add database column comments - May help AI
8+
* Add tutorial videos

admin/pages/TEMPLATE-ADM-top.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
if ($load[0]=="s") {
4444
printf("<script src='%s'%s></script>", $load[1], isset($load[2]) ? " ".$load[2] : "");
4545
} else {
46-
printf("<link rel='stylesheet' href='%s'>", $load[1], isset($load[2]) ? " ".$load[2] : "");
46+
printf("<link rel='stylesheet' href='%s'>", $load[1]);
4747
}
4848
}}
4949
if (isset($_PMETA)) { unset($_PMETA); } ?>

core/assets/PAGE-cb.css

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+22-56
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,39 @@
11
var unfc = {
22
// (A) SHOW WRITE NFC PAGE
3-
hnBtn : null, // html write nfc button
4-
hnStat : null, // html write nfc button status
5-
hnNull : null, // html null token button
3+
hBtn : null, // html write nfc button
4+
hNull : null, // html null token button
65
show : id => cb.load({
76
page : "admin/users/nfc", target : "cb-page-2",
87
data : { id : id },
98
onload : () => {
10-
unfc.hnBtn = document.getElementById("nfc-btn");
11-
unfc.hnStat = document.getElementById("nfc-stat");
12-
unfc.hnNull = document.getElementById("nfc-null");
13-
if ("NDEFReader" in window) {
14-
unfc.hnStat.innerHTML = "Create Login Token";
15-
unfc.hnBtn.disabled = false;
16-
} else {
17-
unfc.hnStat.innerHTML = "Web NFC not available";
18-
}
9+
unfc.hBtn = document.getElementById("nfc-btn");
10+
unfc.hNull = document.getElementById("nfc-null");
11+
if ("NDEFReader" in window) { unfc.hBtn.disabled = false; }
1912
cb.page(2);
2013
}
2114
}),
2215

2316
// (B) CREATE NEW NFC LOGIN TAG
24-
add : id => {
25-
// (B1) DISABLE "WRITE NFC" BUTTON
26-
unfc.hnBtn.disabled = true;
27-
28-
// (B2) REGISTER WITH SERVER + GET JWT
29-
cb.api({
30-
mod : "nfcin", act : "add",
31-
data : { id : id },
32-
passmsg : false,
33-
onpass : res => {
34-
// (B2-1) ENABLE "NULLIFY" BUTTTON
35-
unfc.hnNull.disabled = false;
36-
37-
// (B2-2) ON SUCCESSFUL NFC WRITE
38-
nfc.onwrite = () => {
39-
nfc.standby();
40-
cb.modal("Successful", "Login token successfully created.");
41-
unfc.hnStat.innerHTML = "Done";
42-
};
43-
44-
// (B2-3) ON FAILED NFC WRITE
45-
nfc.onerror = err => {
46-
nfc.stop();
47-
console.error(err);
48-
cb.modal("ERROR", err.message);
49-
unfc.hnStat.innerHTML = "ERROR!";
50-
unfc.hnBtn.disabled = false;
51-
};
52-
53-
// (B2-4) START NFC WRITE
54-
nfc.write(res.data);
55-
unfc.hnStat.innerHTML = "Tap NFC tag to write";
56-
}
57-
})
58-
},
17+
add : id => cb.api({
18+
mod : "nfcin", act : "add",
19+
data : { id : id },
20+
passmsg : false,
21+
onpass : res => {
22+
unfc.hNull.disabled = false;
23+
nfc.write(res.data);
24+
}
25+
}),
5926

6027
// (C) NULLIFY NFC TOKEN
61-
del : id => cb.api({
28+
null : id => cb.api({
6229
mod : "nfcin", act : "del",
6330
data : { id : id },
6431
passmsg : "Login token nullified.",
65-
onpass : res => unfc.hnNull.disabled = true
66-
}),
32+
onpass : res => unfc.hNull.disabled = true
33+
})
34+
};
6735

68-
// (D) END WRITE NFC SESSION
69-
back : () => {
70-
nfc.stop();
71-
cb.page(1);
72-
}
73-
};
36+
// (D) ATTACH NFC WRITER
37+
window.addEventListener("load", () => {
38+
if (("NDEFReader" in window)) { nfc.init(); }
39+
});
+11-37
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,18 @@
11
var nin = {
22
// (A) INITIALIZE - CHECK NFC
3-
hStatus : null, // html hfc login button text
43
init : () => { if ("NDEFReader" in window) {
5-
nin.hStatus = document.getElementById("nfc-b");
6-
document.getElementById("nfc-a").disabled = false;
4+
document.getElementById("nfc-in").disabled = false;
5+
nfc.init(nin.go);
76
}},
87

9-
// (B) NFC LOGIN
10-
go : () => {
11-
// (B1) ON NFC READ
12-
nfc.onread = evt => {
13-
// (B1-1) GET TOKEN
14-
nfc.standby();
15-
const decoder = new TextDecoder();
16-
let token = "";
17-
for (let record of evt.message.records) {
18-
token = decoder.decode(record.data);
19-
}
20-
21-
// (B1-2) API LOGIN
22-
cb.api({
23-
mod : "nfcin", act : "login",
24-
data : { token : token },
25-
passmsg : false,
26-
onpass : () => location.href = cbhost.base,
27-
onfail : () => nin.go()
28-
});
29-
};
30-
31-
// (B2) ON NFC ERROR
32-
nfc.onerror = err => {
33-
nfc.stop();
34-
console.error(err);
35-
cb.modal("ERROR", err.msg);
36-
nin.hStatus.innerHTML = "ERROR!";
37-
};
38-
39-
// (B3) START SCAN
40-
nin.hStatus.innerHTML = "Scanning - Tap Token";
41-
nfc.scan();
42-
}
8+
// (B) LOGIN WITH NFC TOKEN
9+
go : token => cb.api({
10+
mod : "nfcin", act : "login",
11+
data : { token : token },
12+
passmsg : false,
13+
onpass : () => location.href = cbhost.base
14+
})
4315
};
16+
17+
// (C) INIT NFC LOGIN
4418
window.addEventListener("load", nin.init);

login with nfc/assets/PAGE-nfc.css

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#nfc-wrapA {
2+
position: fixed; top: 0; left: 0;
3+
width:100vw; height: 100vh; z-index: 999;
4+
}
5+
#nfc-wrapB {
6+
max-width: 600px; padding: 30px;
7+
margin: 0 auto;
8+
}
9+
#nfc-wrapC {
10+
padding: 60px 0; line-height: 2em;
11+
text-align: center; color: #fff;
12+
}
13+
#nfc-wrapC i { font-size: 100px; }

login with nfc/assets/PAGE-nfc.js

+79-29
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,102 @@
11
var nfc = {
2-
// (A) INITIALIZE WEB NFC
3-
ndef : null, ctrl : null, // ndef object
4-
onread : null, onwrite : null, onerror : null, // functions to run on read, write, error
5-
init : () => {
6-
nfc.stop();
2+
// (A) PROPERTIES
3+
ndef : null, ctrl : null, // ndef object
4+
ondone : null, onerror : null, // functions to call on complete/error
5+
6+
// (B) INIT WEB NFC SCANNER/WRITER
7+
init : (ondone, onerror) => {
8+
// (B1) ATTACH HTML
9+
if (document.getElementById("nfc-wrapA") == null) {
10+
let nScan = document.createElement("div");
11+
nScan.id = "nfc-wrapA";
12+
nScan.className = "d-none tran-zoom bg-dark";
13+
nScan.innerHTML = `<div id="nfc-wrapB">
14+
<div id="nfc-wrapC" class="bg-success">
15+
<div><i class="icon-feed"></i></div>
16+
<div>READY - SCAN YOUR NFC TAG</div>
17+
</div>
18+
<button type="button" class="mt-4 btn btn-danger d-flex-inline" onclick="nfc.hide()">
19+
<i class="ico-sm icon-cross"></i> Cancel
20+
</button>
21+
</div>`;
22+
document.body.appendChild(nScan);
23+
}
24+
25+
// (B2) SET "POST ACTIONS"
26+
nfc.ondone = ondone;
27+
nfc.onerror = onerror;
28+
},
29+
30+
// (C) START - MISSION START
31+
start : () => {
732
nfc.ctrl = new AbortController();
833
nfc.ndef = new NDEFReader();
934
},
1035

11-
// (B) STOP - MISSION ABORT
36+
// (D) STOP - MISSION ABORT
1237
stop : () => { if (nfc.ndef!=null) {
1338
nfc.ctrl.abort();
1439
nfc.ndef = null;
1540
nfc.ctrl = null;
1641
}},
1742

18-
// (C) STANDBY - SCAN & DO NOTHING
19-
standby : () => {
20-
nfc.init();
21-
nfc.ndef.onreading = null;
22-
nfc.ndef.onreadingerror = null;
23-
nfc.ndef.scan({ signal: nfc.ctrl.signal });
43+
// (E) SHOW NFC WRITER/SCANNER
44+
show : () => cb.transit(() => {
45+
document.getElementById("nfc-wrapA").classList.remove("d-none");
46+
document.body.classList.add("overflow-hidden");
47+
}),
48+
49+
// (F) HIDE NFC WRITER/SCANNER
50+
hide : () => {
51+
cb.transit(() => {
52+
document.getElementById("nfc-wrapA").classList.add("d-none");
53+
document.body.classList.remove("overflow-hidden");
54+
});
2455
},
2556

26-
// (D) SCAN NFC TAG
27-
scan : () => {
28-
nfc.init();
29-
nfc.ndef.scan({ signal: nfc.ctrl.signal })
30-
.then(() => {
31-
if (nfc.onread!=null) { nfc.ndef.onreading = nfc.onread; }
32-
if (nfc.onerror!=null) { nfc.ndef.onreadingerror = nfc.onerror; }
33-
})
34-
.catch(err => { if (nfc.onerror!=null) { nfc.onerrorerr(err); } });
57+
// (G) GENERAL ERROR HANDLER
58+
catcher : err => {
59+
nfc.stop(); nfc.hide();
60+
cb.modal("ERROR", err.msg);
61+
if (nfc.onerror) { nfc.onerror(err); }
3562
},
3663

37-
// (E) WRITE NFC TAG
64+
// (H) WRITE NFC TAG
3865
write : data => {
39-
nfc.init();
66+
nfc.stop(); nfc.start(); nfc.show();
4067
nfc.ndef.write(data, { signal: nfc.ctrl.signal })
41-
.then(() => { if (nfc.onwrite!=null) { nfc.onwrite(); } })
42-
.catch(err => { if (nfc.onerror!=null) { nfc.onerrorerr(err); } });
68+
.then(() => {
69+
nfc.stop(); nfc.hide();
70+
cb.toast(true, "Success", "NFC Tag Created");
71+
if (nfc.ondone) { nfc.ondone(); }
72+
})
73+
.catch(nfc.catcher);
4374
},
4475

45-
// (F) CREATE READ-ONLY NFC TAG
76+
// (I) SCAN NFC TAG
77+
scan : () => {
78+
nfc.stop(); nfc.start(); nfc.show();
79+
nfc.ndef.scan({ signal: nfc.ctrl.signal })
80+
.then(() => {
81+
nfc.ndef.onreading = evt => {
82+
nfc.stop(); nfc.hide();
83+
const decoder = new TextDecoder();
84+
nfc.ondone(decoder.decode(evt.message.records[0].data));
85+
};
86+
nfc.ndef.onreadingerror = nfc.catcher;
87+
})
88+
.catch(nfc.catcher);
89+
},
90+
91+
// (J) CREATE READ-ONLY NFC TAG
4692
readonly : () => {
47-
nfc.init();
93+
nfc.stop(); nfc.start(); nfc.show();
4894
nfc.ndef.makeReadOnly({ signal: nfc.ctrl.signal })
49-
.then(() => { if (nfc.onwrite!=null) { nfc.onwrite(); } })
50-
.catch(err => { if (nfc.onerror!=null) { nfc.onerrorerr(err); } });
95+
.then(() => {
96+
nfc.stop(); nfc.hide();
97+
cb.toast(true, "Success", "NFC Tag Locked");
98+
if (nfc.ondone) { nfc.ondone(); }
99+
})
100+
.catch(nfc.catcher);
51101
}
52102
};

login with nfc/pages/ADM-users-nfc.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,32 @@
22
// (A) GET USER
33
$_POST["hash"] = "NFC";
44
$user = $_CORE->autoCall("Users", "get");
5-
if (!is_array($user)) { exit("Invalid user"); }
6-
?>
5+
if (!is_array($user)) { exit("Invalid user"); } ?>
76
<h3 class="mb-3">USER NFC LOGIN TOKEN</h3>
87

98
<!-- (B) CREATE NEW TOKEN -->
10-
<div class="fw-bold text-danger mb-2">CREATE NEW TOKEN</div>
9+
<div class="fw-bold text-danger">CREATE NEW TOKEN</div>
1110
<div class="bg-white border p-4 mb-3">
1211
<button id="nfc-btn" disabled class="my-1 btn btn-primary d-flex-inline" onclick="unfc.add(<?=$_POST["id"]?>)">
13-
<i class="ico-sm icon-feed"></i> <span id="nfc-stat">Initializing</span>
12+
<i class="ico-sm icon-feed"></i> Create
1413
</button>
1514
<div class="text-secondary mt-2">
1615
* A user can only have one login token, creating a new token will nullify the previous one.
1716
</div>
1817
</div>
1918

2019
<!-- (C) NULL NFC TOKEN -->
21-
<div class="fw-bold text-danger mb-2">NULLIFY NFC TOKEN</div>
20+
<div class="fw-bold text-danger">NULLIFY NFC TOKEN</div>
2221
<div class="bg-white border p-4 mb-3">
2322
<button id="nfc-null" class="my-1 btn btn-primary d-flex-inline"
24-
onclick="unfc.del(<?=$_POST["id"]?>)"<?=$user["hash_code"]==""?" disabled":""?>>
25-
<i class="ico-sm icon-blocked"></i> Nullify Login Token
23+
onclick="unfc.null(<?=$_POST["id"]?>)"<?=$user["hash_code"]==""?" disabled":""?>>
24+
<i class="ico-sm icon-blocked"></i> Nullify
2625
</button>
2726
<div class="text-secondary mt-2">
2827
* The user's NFC login token will be nullified, but the login email/password remains unaffected.
2928
</div>
3029
</div>
3130

32-
<button type="button" class="my-1 btn btn-primary d-flex-inline" onclick="unfc.back()">
31+
<button type="button" class="my-1 btn btn-danger d-flex-inline" onclick="cb.page(1)">
3332
<i class="ico-sm icon-undo2"></i> Back
3433
</button>

0 commit comments

Comments
 (0)