{mode === "login" ? "New student?" : "Already have an account?"}{" "}
// auth.jsx — Student Login / Register + Dashboard (wired to the WordPress REST API)
(function () {
const { useState, useEffect } = React;
const Icon = window.Icon;
const { PageHero } = window;
const CFG = window.INFOTECH || {};
const STATUS_META = {
valid: { cls: "status-valid", label: "Valid", color: "var(--ok)", bg: "var(--ok-bg)" },
expired: { cls: "status-expired", label: "Expired", color: "var(--warn)", bg: "var(--warn-bg)" },
cancelled: { cls: "status-cancelled", label: "Cancelled", color: "var(--bad)", bg: "var(--bad-bg)" },
};
/* ===================== LOGIN / REGISTER ===================== */
function Login({ navigate }) {
const [mode, setMode] = useState("login"); // login | register
const [form, setForm] = useState({ username: "", password: "", name: "", email: "", reg: "" });
const [errors, setErrors] = useState({});
const [msg, setMsg] = useState("");
const [busy, setBusy] = useState(false);
// Already signed in? Go straight to the dashboard.
useEffect(() => { if (CFG.loggedIn) navigate("dashboard"); /* eslint-disable-next-line */ }, []);
const set = (k, v) => { setForm((f) => ({ ...f, [k]: v })); if (errors[k]) setErrors((e) => ({ ...e, [k]: null })); setMsg(""); };
const finishAuth = (data) => {
if (data.nonce) window.setNonce(data.nonce);
CFG.loggedIn = true;
CFG.user = data.user;
navigate("dashboard");
};
const submit = (e) => {
e.preventDefault();
setErrors({}); setMsg("");
if (mode === "login") {
if (!form.username.trim() || !form.password) { setMsg("Please enter your username/email and password."); return; }
setBusy(true);
window.api("login", { method: "POST", body: { username: form.username, password: form.password } }).then((res) => {
setBusy(false);
if (res.data && res.data.ok) finishAuth(res.data);
else setMsg((res.data && res.data.message) || "Login failed. Please try again.");
});
} else {
setBusy(true);
window.api("register", { method: "POST", body: { name: form.name, email: form.email, reg: form.reg, password: form.password } }).then((res) => {
setBusy(false);
if (res.data && res.data.ok) finishAuth(res.data);
else if (res.data && res.data.errors) setErrors(res.data.errors);
else setMsg((res.data && res.data.message) || "Could not create your account. Please try again.");
});
}
};
const Tab = ({ id, label }) => (
);
return (
{mode === "login" ? "New student?" : "Already have an account?"}{" "}
| Subject | Obtained | Total |
|---|---|---|
| {m.subject} | {m.obtained} | {m.total} |
Loading your dashboard…
You need to be signed in to view your student dashboard.
Your certificates and results will appear here once the institute issues them. If you have a Registration number, add it to your profile so we can link your records.