From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server-vie001.gnuweeb.org
X-Spam-Level:
X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED,
DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_ZEN_BLOCKED_OPENDNS
autolearn=ham autolearn_force=no version=3.4.6
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org;
s=default; t=1740698569;
bh=q9xb4akHW7ZY4CPkxFRB//zVe//Sb8NnMet8pfTLN3E=;
h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:
MIME-Version:Content-Transfer-Encoding:Message-ID:Date:From:
Reply-To:Subject:To:Cc:In-Reply-To:References:Resent-Date:
Resent-From:Resent-To:Resent-Cc:User-Agent:Content-Type:
Content-Transfer-Encoding;
b=sBRIq+JI9FgwsXPTIROVRRvqQoXCkKasTO3IbW6K2rQjuLJgrfUQzNxQ3gRryJ2EW
8+D23XlEodSXvzkwa/ETWume8B/TflEViTeoSR6hRIRbFxtPwJc8/BltLXgQPKyGWP
rs7k02NAWytFKS/7iaa+GuDAPgc6r0Ycb0tCa2JJbBU1uY0TNQakwwLuGPsSPlua8L
NzGekgOexj2wYJseN8BosTmDA/lHTERvi2vK7sy7InCjgxsZMoZXZoot1DaB3j46Sq
J/EQJW/dCJH12oJzyq6NT13SgUCIjaT/LEQsPrqGZF13QKSi2QTwA0kcZaa+idVAMr
biTQeHeK7imhg==
Received: from integral2.. (unknown [182.253.126.171])
by server-vie001.gnuweeb.org (Postfix) with ESMTPSA id E78452074491;
Thu, 27 Feb 2025 23:22:47 +0000 (UTC)
From: Ammar Faizi
To: Muhammad Rizki
Cc: Ammar Faizi ,
GNU/Weeb Mailing List ,
Alviro Iskandar Setiawan
Subject: [PATCH gwmail 4/7] old: Add profile page
Date: Fri, 28 Feb 2025 06:22:31 +0700
Message-Id: <20250227232234.809858-5-ammarfaizi2@gnuweeb.org>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20250227232234.809858-1-ammarfaizi2@gnuweeb.org>
References: <20250227232234.809858-1-ammarfaizi2@gnuweeb.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
List-Id:
Initial example of profile related API.
Signed-off-by: Ammar Faizi
---
old/assets/js/api.js | 58 ++++++++++++----
old/home.html | 8 +--
old/profile.html | 159 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 206 insertions(+), 19 deletions(-)
create mode 100644 old/profile.html
diff --git a/old/assets/js/api.js b/old/assets/js/api.js
index 6593198aab2a..9a14a83633c8 100644
--- a/old/assets/js/api.js
+++ b/old/assets/js/api.js
@@ -6,6 +6,12 @@ function gid(i)
return document.getElementById(i);
}
+function toggle_disable_inputs(form, disable)
+{
+ for (let i = 0; i < form.length; i++)
+ form[i].disabled = disable;
+}
+
function escape_html(s)
{
return s.replace(/&/g, "&")
@@ -71,6 +77,17 @@ function gwm_api_get_user_info(cb)
});
}
+function gwm_api_set_user_info(cb, data)
+{
+ gwm_exec_api_multipart({
+ method: "POST",
+ url: GWM_API_URL + "set_user_info",
+ data: data,
+ token: LS.getItem("gwm_token"),
+ callback: cb
+ });
+}
+
function gwm_api_login(cb, user, pass)
{
gwm_exec_api_json({
@@ -127,6 +144,11 @@ function gwm_fn_change_password(cb, cur_pass, new_pass, retype_new_pass)
});
}
+function gwm_fn_set_user_info(cb, data)
+{
+ gwm_api_set_user_info(cb, data);
+}
+
function gwm_fn_logout()
{
LS.clear();
@@ -148,6 +170,29 @@ function gwm_auth_redirect_if_authorized()
return false;
}
+function gwm_auth_renew_session(cb = null)
+{
+ gwm_api_get_user_info(function(j, x) {
+ // If cancelled, do nothing
+ if (x.status === 0)
+ return;
+
+ if (j.code !== 200) {
+ alert("Your session has expired. Please login again.");
+ gwm_fn_logout();
+ return;
+ }
+
+ let rt = j.res.renew_token;
+ LS.setItem("gwm_uinfo", JSON.stringify(j.res.user_info));
+ LS.setItem("gwm_token", rt.token);
+ LS.setItem("gwm_token_exp_at", rt.token_exp_at);
+
+ if (cb)
+ cb();
+ });
+}
+
function gwm_auth_redirect_if_not_authorized()
{
let tkn = LS.getItem("gwm_token");
@@ -166,17 +211,6 @@ function gwm_auth_redirect_if_not_authorized()
return true;
}
- gwm_api_get_user_info(function(j) {
- if (j.code !== 200) {
- alert("Your session has expired. Please login again.");
- gwm_fn_logout();
- return;
- }
-
- let rt = j.res.renew_token;
- LS.setItem("gwm_uinfo", JSON.stringify(j.res.user_info));
- LS.setItem("gwm_token", rt.token);
- LS.setItem("gwm_token_exp_at", rt.token_exp_at);
- });
+ gwm_auth_renew_session();
return false;
}
diff --git a/old/home.html b/old/home.html
index baaf067c8f20..4ba0039d044b 100644
--- a/old/home.html
+++ b/old/home.html
@@ -43,6 +43,7 @@ body {
GNU/Weeb Mail Dashboard
Welcome
This is an emergency page to change your password. It's still under development.
+
+Back to Home
+
+
+
+