Cleaned up validators and browser-side ajax utils

This commit is contained in:
rainbownapkin 2024-11-17 18:33:57 -05:00
parent 8a4a21cff0
commit cf55be21eb
8 changed files with 79 additions and 35 deletions

View file

@ -63,11 +63,10 @@ class profileEditPrompt{
updateObj[this.field] = this.prompt.value;
//contact server, and collect response
var response = await utils.ajax.updateProfile(updateObj);
var updated_content = (await response.json())[this.field];
var updated_content = (await utils.ajax.updateProfile(updateObj))[this.field];
//Update label
if(response.status == 200){
if(updated_content != null){
if(this.field == "img"){
this.content.src = updated_content;
}else{
@ -76,7 +75,6 @@ class profileEditPrompt{
}
this.finish();
}else if(event.key == "Escape" || event.key == "Enter"){
console.log(response);
this.finish();
}
}
@ -144,7 +142,7 @@ class passwordResetPrompt{
const response = await utils.ajax.updateProfile(updateObj);
if(response.status == 200){
if(response != null){
//Return user homepage after good pass change, as we've probably been logged out by the server for security.
window.location.pathname = '/';
}
@ -167,13 +165,7 @@ class deleteAccountPrompt{
async deletePrompt(event){
const pass = window.prompt("Warning: You are about to nuke your account off of the face of the fucking planet, no taksie-backsies.\n \n (todo: replace with dialog that has obscured password input) \n Enter your password to confirm.");
const response = await utils.ajax.deleteAccount(pass);
if(response.status == 200){
window.location.pathname = '/';
}else{
utils.ux.displayResponseError(await response.json());
}
await utils.ajax.deleteAccount(pass);
}
}

View file

@ -137,6 +137,8 @@ class canopyAjaxUtils{
if(response.status == 200){
location = "/";
}else{
utils.ux.displayResponseError(await response.json());
}
}
@ -151,6 +153,8 @@ class canopyAjaxUtils{
if(response.status == 200){
location.reload();
}else{
utils.ux.displayResponseError(await response.json());
}
}
@ -161,27 +165,42 @@ class canopyAjaxUtils{
if(response.status == 200){
location.reload();
}else{
utils.ux.displayResponseError(await response.json());
}
}
//We need to fix this one to use displayResponseError function
async updateProfile(update){
return await fetch(`/api/account/update`,{
const response = await fetch(`/api/account/update`,{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(update)
});
if(response.status == 200){
return await response.json();
}else{
utils.ux.displayResponseError(await response.json());
}
}
async deleteAccount(pass){
return await fetch(`/api/account/delete`,{
const response = await fetch(`/api/account/delete`,{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({pass})
});
if(response.status == 200){
window.location.pathname = '/';
}else{
utils.ux.displayResponseError(await response.json());
}
}
async newChannel(name, description, thumbnail){
@ -195,6 +214,8 @@ class canopyAjaxUtils{
if(response.status == 200){
location = "/";
}else{
utils.ux.displayResponseError(await response.json());
}
}
@ -210,6 +231,8 @@ class canopyAjaxUtils{
if(response.status == 200){
return await response.json();
}else{
utils.ux.displayResponseError(await response.json());
}
}
@ -224,6 +247,8 @@ class canopyAjaxUtils{
if(response.status == 200){
location = "/";
}else{
utils.ux.displayResponseError(await response.json());
}
}
}