fixed register page

This commit is contained in:
MathMan05 2024-07-01 14:04:26 -05:00
parent dfb20c60ab
commit 9311914ae9
9 changed files with 85 additions and 4 deletions

View file

@ -580,6 +580,24 @@ class Channel {
const prev = this.messages[(+i) + 1]; const prev = this.messages[(+i) + 1];
const built = this.messages[i].buildhtml(prev); const built = this.messages[i].buildhtml(prev);
document.getElementById("messages").prepend(built); document.getElementById("messages").prepend(built);
if (prev) {
const prevDate = new Date(prev.timestamp);
const currentDate = new Date(this.messages[i].timestamp);
if (prevDate.toLocaleDateString() != currentDate.toLocaleDateString()) {
const dateContainer = document.createElement("div");
dateContainer.classList.add("replyflex");
const line = document.createElement("hr");
line.classList.add("reply");
dateContainer.appendChild(line);
const date = document.createElement("span");
date.textContent = currentDate.toLocaleDateString(undefined, { weekday: "long", year: "numeric", month: "long", day: "numeric" });
dateContainer.appendChild(date);
const line2 = document.createElement("hr");
line2.classList.add("reply");
dateContainer.appendChild(line2);
document.getElementById("messages").prepend(dateContainer);
}
}
} }
document.getElementById("messagecontainer").scrollTop = document.getElementById("messagecontainer").scrollHeight; document.getElementById("messagecontainer").scrollTop = document.getElementById("messagecontainer").scrollHeight;
} }

View file

@ -34,6 +34,7 @@ class File {
img.src = src; img.src = src;
img.height = this.height; img.height = this.height;
img.width = this.width; img.width = this.width;
console.log(this.width, this.height);
return img; return img;
} }
else if (this.content_type.startsWith('video/')) { else if (this.content_type.startsWith('video/')) {

View file

@ -236,3 +236,4 @@ if ("serviceWorker" in navigator) {
} }
}); });
} }
export { checkInstance };

60
.dist/register.js Normal file
View file

@ -0,0 +1,60 @@
import { checkInstance } from "./login.js";
if (document.getElementById("register")) {
document.getElementById("register").addEventListener("submit", registertry);
}
async function registertry(e) {
e.preventDefault();
const elements = e.srcElement;
const email = elements[1].value;
const username = elements[2].value;
if (elements[3].value !== elements[4].value) {
document.getElementById("wrong").textContent = "Passwords don't match";
return;
}
const password = elements[3].value;
const dateofbirth = elements[5].value;
const apiurl = new URL(JSON.parse(localStorage.getItem("instanceinfo")).api);
fetch(apiurl + "/auth/register", {
body: JSON.stringify({
date_of_birth: dateofbirth,
email: email,
username: username,
password: password,
consent: elements[6].checked,
}),
headers: {
"content-type": "application/json"
},
method: "POST"
}).then(e => {
e.json().then(e => {
if (!e.token) {
console.log(e);
document.getElementById("wrong").textContent = e.errors[Object.keys(e.errors)[0]]._errors[0].message;
}
else {
localStorage.setItem("token", e.token);
window.location.href = '/channels/@me';
}
});
});
//document.getElementById("wrong").textContent=h;
// console.log(h);
}
let TOSa = document.getElementById("TOSa");
async function tosLogic() {
const apiurl = new URL(JSON.parse(localStorage.getItem("instanceinfo")).api);
const tosPage = (await (await fetch(apiurl.toString() + "/ping")).json()).instance.tosPage;
if (tosPage) {
document.getElementById("TOSbox").innerHTML = "I agree to the <a href=\"\" id=\"TOSa\">Terms of Service</a>:";
TOSa = document.getElementById("TOSa");
TOSa.href = tosPage;
}
else {
document.getElementById("TOSbox").textContent = "This instance has no Terms of Service, accept ToS anyways:";
TOSa = null;
}
console.log(tosPage);
}
tosLogic();
checkInstance.alt = tosLogic;

View file

@ -36,6 +36,7 @@ class File{
img.src=src; img.src=src;
img.height=this.height; img.height=this.height;
img.width=this.width; img.width=this.width;
console.log(this.width,this.height)
return img; return img;
}else if(this.content_type.startsWith('video/')){ }else if(this.content_type.startsWith('video/')){
const video=document.createElement("video"); const video=document.createElement("video");

View file

@ -76,7 +76,6 @@ class Guild{
settings.show(); settings.show();
} }
constructor(JSON,owner:Localuser,member){ constructor(JSON,owner:Localuser,member){
if(JSON===-1){ if(JSON===-1){
return; return;
} }

View file

@ -233,3 +233,4 @@ if ("serviceWorker" in navigator){
} }
}) })
} }
export {checkInstance};

View file

@ -35,6 +35,5 @@
</form> </form>
<a href="/login.html">Already have an account?</a> <a href="/login.html">Already have an account?</a>
</div> </div>
<script src="/login.js"></script> <script src="/register.js" type="module"></script>
<script src="/register.js"></script>
</body> </body>

View file

@ -1,3 +1,4 @@
import {checkInstance} from "./login.js";
if(document.getElementById("register")){ if(document.getElementById("register")){
document.getElementById("register").addEventListener("submit", registertry); document.getElementById("register").addEventListener("submit", registertry);
} }
@ -48,7 +49,7 @@ async function tosLogic(){
if(tosPage){ if(tosPage){
document.getElementById("TOSbox").innerHTML="I agree to the <a href=\"\" id=\"TOSa\">Terms of Service</a>:"; document.getElementById("TOSbox").innerHTML="I agree to the <a href=\"\" id=\"TOSa\">Terms of Service</a>:";
TOSa=document.getElementById("TOSa"); TOSa=document.getElementById("TOSa");
TOSa.href=tosPage; (TOSa as HTMLAnchorElement).href=tosPage;
}else{ }else{
document.getElementById("TOSbox").textContent="This instance has no Terms of Service, accept ToS anyways:"; document.getElementById("TOSbox").textContent="This instance has no Terms of Service, accept ToS anyways:";
TOSa=null; TOSa=null;