2024-07-12 00:29:46 +00:00
|
|
|
/* global qs request */
|
|
|
|
|
2024-07-11 23:57:39 +00:00
|
|
|
async function changeValue(setting_name, value) {
|
2024-07-09 19:15:44 +00:00
|
|
|
const form = {
|
|
|
|
setting_name: setting_name,
|
2024-07-12 00:07:42 +00:00
|
|
|
value: value.value || value,
|
2024-07-09 19:15:44 +00:00
|
|
|
id: window.location.href.split("/")[4],
|
|
|
|
};
|
|
|
|
const response = await request(`/api/web/user`, "PATCH", form);
|
|
|
|
|
|
|
|
// TODO: On failure, notify the user
|
|
|
|
if (response.body.success) {
|
2024-07-10 23:20:22 +00:00
|
|
|
alert("Successfully changed setting.");
|
2024-07-09 19:15:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const change_password_dialog = qs("#change-password-dialog");
|
|
|
|
|
|
|
|
qs("#change-password-button").addEventListener("click", () => change_password_dialog.showModal());
|
|
|
|
qs("#cp-cancel").addEventListener("click", () => change_password_dialog.close());
|
|
|
|
|
|
|
|
function changePasswordInputUpdate() {
|
|
|
|
const status = qs("#change-password-dialog .status");
|
|
|
|
const current_password = qs("#cp-current");
|
|
|
|
const new_password_1 = qs("#cp-new-1");
|
|
|
|
const new_password_2 = qs("#cp-new-2");
|
|
|
|
|
|
|
|
if (current_password.value === "") return (status.innerText = "Please enter your current password.");
|
|
|
|
|
|
|
|
if (new_password_1.value !== new_password_2.value) return (status.innerText = "New password does not match.");
|
|
|
|
|
|
|
|
return (status.innerHTML = " ");
|
2024-04-30 15:26:35 +00:00
|
|
|
}
|
2024-07-09 19:15:44 +00:00
|
|
|
|
2024-07-10 23:20:22 +00:00
|
|
|
async function sendPasswordUpdate() {
|
2024-07-09 19:15:44 +00:00
|
|
|
const new_password_1 = qs("#cp-new-1");
|
2024-07-11 23:57:39 +00:00
|
|
|
const original_password_value = qs("#cp-current").value;
|
2024-07-10 23:20:22 +00:00
|
|
|
|
|
|
|
const form = {
|
|
|
|
setting_name: "password",
|
|
|
|
value: new_password_1.value,
|
|
|
|
original_password: original_password_value,
|
|
|
|
id: window.location.href.split("/")[4],
|
|
|
|
};
|
|
|
|
const response = await request(`/api/web/user`, "PATCH", form);
|
|
|
|
|
|
|
|
if (response.body.success) {
|
|
|
|
alert("Successfully changed password");
|
|
|
|
}
|
2024-07-11 23:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const fileInput = qs("#profile_picture");
|
|
|
|
fileInput.addEventListener("change", uploadProfileImage);
|
|
|
|
|
|
|
|
async function uploadProfileImage(event) {
|
|
|
|
const file = event.target.files[0];
|
|
|
|
const image_object = {
|
|
|
|
data_blob: new Blob([await file.arrayBuffer()]),
|
|
|
|
content_type: file.type,
|
|
|
|
};
|
|
|
|
|
|
|
|
let form_data = {
|
|
|
|
buffer: await _readFile(image_object.data_blob),
|
|
|
|
content_type: image_object.content_type,
|
|
|
|
parent_id: window.location.href.split("/")[4],
|
|
|
|
parent_type: "user",
|
|
|
|
};
|
|
|
|
|
|
|
|
const image_uploading_request = await request("/api/web/image", "POST", form_data);
|
|
|
|
|
|
|
|
if (image_uploading_request.status == 200) {
|
|
|
|
// Update profile picture link
|
|
|
|
changeValue("profile_image", image_uploading_request.body);
|
|
|
|
// alert(image_uploading_request.body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _readFile(file) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = () => resolve(reader.result);
|
|
|
|
reader.onerror = reject;
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
});
|
|
|
|
}
|
2024-07-12 18:34:17 +00:00
|
|
|
|
|
|
|
async function updateBiography() {
|
|
|
|
let form_data = {
|
|
|
|
media: media,
|
|
|
|
content: qs("#post-content").value,
|
|
|
|
id: window.location.href.split("/")[4],
|
|
|
|
};
|
|
|
|
|
|
|
|
const post_response = await request("/api/web/biography", "PATCH", form_data);
|
|
|
|
|
|
|
|
if (post_response.body.success) {
|
|
|
|
window.location.href = `/post/${post_response.body.post_id}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|