summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-06-04 15:14:52 +0100
committerJoe Carstairs <me@joeac.net>2026-06-04 15:16:34 +0100
commitfac1199cd61e069b1a144d2548477a2c3b3b94b0 (patch)
treeeacd5ce827c0281633162fe283bcd4c7f8029bcd /http
parent171c957c40172a994189cdc1824421b3a9bd379b (diff)
http: adds actions.js file to interface JS -> PHP
Diffstat (limited to 'http')
-rw-r--r--http/public/scripts/contact/actions.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/http/public/scripts/contact/actions.js b/http/public/scripts/contact/actions.js
new file mode 100644
index 0000000..5a7e32a
--- /dev/null
+++ b/http/public/scripts/contact/actions.js
@@ -0,0 +1,60 @@
+export const actions = {
+ /**
+ * @param {{type: 'email', name: string, email: string}}
+ * @returns {Promise<void>}
+ */
+ sendOtp: async ({ type, name, email }) => {
+ const url = "/do/send_otp.php";
+ const req = new Request(url, {
+ method: "POST",
+ body: JSON.stringify({ type, name, email }),
+ });
+ const res = await fetch(req);
+ if (!res.ok) {
+ throw new Error(
+ `Request to ${url} failed: ${res.status} ${res.statusText} ${await res.text()}`,
+ );
+ }
+ },
+
+ /**
+ * @param {{guess: string, lenient?: bool, userId: string}}
+ * @returns {Promise<string | false>}
+ */
+ verifyOtp: async ({ guess, lenient, userId }) => {
+ const url = "/do/verify_otp.php";
+ const req = new Request(url, {
+ method: "POST",
+ body: JSON.stringify({ guess, lenient, userId }),
+ });
+ const res = await fetch(req);
+
+ if (res.status === 400) {
+ return false;
+ } else if (!res.ok) {
+ throw new Error(
+ `Request to ${url} failed: ${res.status} ${res.statusText} ${await res.text()}`,
+ );
+ }
+
+ return res.text();
+ },
+
+ /**
+ * @param {{email: string, message: string, name: string, userId: string, token: string}}
+ * @returns {Promise<void>}
+ */
+ sendEmail: async ({ email, message, name, userId, token }) => {
+ const url = "/do/send_email.php";
+ const req = new Request(url, {
+ method: "POST",
+ body: JSON.stringify({ email, message, name, userId, token }),
+ });
+ const res = await fetch(req);
+ if (!res.ok) {
+ throw new Error(
+ `Request to ${url} failed: ${res.status} ${res.statusText} ${await res.text()}`,
+ );
+ }
+ },
+};