From f3aceb69af05a9315ce91b9279a5d5c292550888 Mon Sep 17 00:00:00 2001 From: metacryst Date: Tue, 24 Mar 2026 10:39:57 -0500 Subject: [PATCH] accepting code for auth page --- src/Home/AuthPage/AuthPage.js | 8 +-- src/Home/AuthPage/EnterCode.js | 99 ++++++++++++++++++++++++++++++++++ src/index.js | 2 + 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/Home/AuthPage/EnterCode.js diff --git a/src/Home/AuthPage/AuthPage.js b/src/Home/AuthPage/AuthPage.js index 53da3f2..20ceabc 100644 --- a/src/Home/AuthPage/AuthPage.js +++ b/src/Home/AuthPage/AuthPage.js @@ -1,7 +1,7 @@ import { Preferences } from '@capacitor/preferences'; -import util from "../../util.js" import "./Login.js"; import "./Signup.js" +import "./EnterCode.js" class AuthPage extends Shadow { inputStyles(el) { @@ -48,7 +48,7 @@ class AuthPage extends Shadow { this.attr("selected", "1") }) - p("Sign Up") + p("Enter Code") .state(this, "selected", function (selected) { if(selected === "2") { this.fontWeight("bold") @@ -86,10 +86,10 @@ class AuthPage extends Shadow { } }) - Signup() + EnterCode() .state(this, "selected", function (selected) { if(selected === "2") { - this.display("") + this.display("flex") } else { this.display("none") } diff --git a/src/Home/AuthPage/EnterCode.js b/src/Home/AuthPage/EnterCode.js new file mode 100644 index 0000000..8a41b29 --- /dev/null +++ b/src/Home/AuthPage/EnterCode.js @@ -0,0 +1,99 @@ +import util from "../../util.js" +import "./Signup.js" + +class EnterCode extends Shadow { + inputStyles(el) { + return el + .background("var(--main)") + .color("var(--text)") + .border("1px solid var(--accent)") + .fontSize(0.9, rem) + .backgroundColor("var(--searchbackground)") + .borderRadius(12, px) + .outline("none") + .onTouch((start) => { + if (start) { + this.style.backgroundColor = "var(--accent)" + } else { + this.style.backgroundColor = "var(--searchbackground)" + } + }) + } + + render() { + VStack(() => { + + VStack(() => { + p("Enter the code given to you by your organization.") + .color("#614945") + .maxWidth(70, vw) + .marginTop(3, em) + + input("Code", "70vw") + .attr({ name: "firstName", type: "text" }) + .margin("auto") + .marginVertical(1, em) + .padding(1, em) + .styles(this.inputStyles) + + button("==>") + .padding(1, em) + .fontSize(0.9, rem) + .borderRadius(12, px) + .background("var(--searchbackground)") + .color("var(--text)") + .border("1px solid var(--accent)") + .boxSizing("border-box") + .onTouch(function (start) { + if (start) { + this.style.backgroundColor = "var(--accent)" + } else { + this.style.backgroundColor = "var(--searchbackground)" + } + }) + .onClick((done) => { + if (done) this.submit() + }) + }) + .state(this, "codeaccepted", function (accepted) { + if(!accepted) { + this.display("flex") + } else { + this.display("none") + } + }) + + Signup() + .state(this, "codeaccepted", function (accepted) { + if(accepted) { + this.display("") + } else { + this.display("none") + } + }) + }) + .horizontalAlign("center") + .display("flex") + + this.style.display = "flex" + } + + async submit() { + console.log("submit") + const res = await fetch(`${util.HOST}/auth/joincode`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ code: this.$("input").value }) + }); + + if (res.ok) { + console.log("got join code succ") + this.attr("codeaccepted", "true") + } else { + const { error } = await res.json(); + console.error(error) + } + } +} + +register(EnterCode) \ No newline at end of file diff --git a/src/index.js b/src/index.js index fb99471..693675e 100644 --- a/src/index.js +++ b/src/index.js @@ -41,6 +41,7 @@ let Global = class { } onNavigate = async () => { + if(!global.profile) return let selectedNetwork = this.networkFromPath() if(!selectedNetwork) { @@ -188,6 +189,7 @@ let Global = class { this.getProfile().then(async (status) => { if (status === 401) { + navigateTo("/") AuthPage() } else if(status === 500) { ConnectionError()