Spaces:
Sleeping
Sleeping
FauziIsyrinApridal
commited on
Commit
·
d99d7ed
1
Parent(s):
d8b920e
..
Browse files- app/auth.py +2 -2
- pages/Reset_Password.py +0 -94
app/auth.py
CHANGED
@@ -142,7 +142,7 @@ def auth_view():
|
|
142 |
try:
|
143 |
redirect_url = os.getenv(
|
144 |
"SUPABASE_EMAIL_REDIRECT",
|
145 |
-
os.getenv("NEXT_PUBLIC_SITE_URL", "https://yozora721-pnp-chatbot-v1.hf.space
|
146 |
)
|
147 |
supabase.auth.sign_up({
|
148 |
"email": r_email,
|
@@ -163,7 +163,7 @@ def auth_view():
|
|
163 |
try:
|
164 |
redirect_url = os.getenv(
|
165 |
"SUPABASE_EMAIL_REDIRECT",
|
166 |
-
os.getenv("NEXT_PUBLIC_SITE_URL", "https://yozora721-pnp-chatbot-v1.hf.space
|
167 |
)
|
168 |
supabase.auth.reset_password_for_email(f_email, {"redirect_to": redirect_url})
|
169 |
st.success("Email reset password telah dikirim. Periksa kotak masuk Anda.")
|
|
|
142 |
try:
|
143 |
redirect_url = os.getenv(
|
144 |
"SUPABASE_EMAIL_REDIRECT",
|
145 |
+
os.getenv("NEXT_PUBLIC_SITE_URL", "https://yozora721-pnp-chatbot-v1.hf.space"),
|
146 |
)
|
147 |
supabase.auth.sign_up({
|
148 |
"email": r_email,
|
|
|
163 |
try:
|
164 |
redirect_url = os.getenv(
|
165 |
"SUPABASE_EMAIL_REDIRECT",
|
166 |
+
os.getenv("NEXT_PUBLIC_SITE_URL", "https://yozora721-pnp-chatbot-v1.hf.space"),
|
167 |
)
|
168 |
supabase.auth.reset_password_for_email(f_email, {"redirect_to": redirect_url})
|
169 |
st.success("Email reset password telah dikirim. Periksa kotak masuk Anda.")
|
pages/Reset_Password.py
DELETED
@@ -1,94 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import base64
|
3 |
-
import streamlit as st
|
4 |
-
from app.db import supabase
|
5 |
-
|
6 |
-
|
7 |
-
def _centered_header():
|
8 |
-
logo_path = os.path.join("assets", "pnp-logo.png")
|
9 |
-
|
10 |
-
def get_base64_image(path):
|
11 |
-
with open(path, "rb") as f:
|
12 |
-
return base64.b64encode(f.read()).decode()
|
13 |
-
|
14 |
-
encoded_logo = get_base64_image(logo_path)
|
15 |
-
st.markdown(
|
16 |
-
f"""
|
17 |
-
<div style="text-align:center;">
|
18 |
-
<img src="data:image/png;base64,{encoded_logo}" width="100">
|
19 |
-
<h1 style="margin-top:0.25rem;">Reset Password</h1>
|
20 |
-
</div>
|
21 |
-
""",
|
22 |
-
unsafe_allow_html=True,
|
23 |
-
)
|
24 |
-
|
25 |
-
|
26 |
-
def main():
|
27 |
-
st.set_page_config(page_title="Reset Password - PNP Bot", page_icon="assets/favicon.ico")
|
28 |
-
_centered_header()
|
29 |
-
|
30 |
-
# Convert hash (#...) to query (?...) so Streamlit can read tokens
|
31 |
-
st.markdown(
|
32 |
-
"""
|
33 |
-
<script>
|
34 |
-
(function() {
|
35 |
-
const hash = window.location.hash;
|
36 |
-
if (hash && hash.length > 1 && !sessionStorage.getItem("hash_migrated")) {
|
37 |
-
const query = hash.substring(1);
|
38 |
-
const newUrl = window.location.pathname + "?" + query;
|
39 |
-
sessionStorage.setItem("hash_migrated", "true");
|
40 |
-
window.history.replaceState(null, "", newUrl);
|
41 |
-
window.location.reload();
|
42 |
-
}
|
43 |
-
})();
|
44 |
-
</script>
|
45 |
-
""",
|
46 |
-
unsafe_allow_html=True,
|
47 |
-
)
|
48 |
-
|
49 |
-
# Read query params
|
50 |
-
try:
|
51 |
-
qp = st.query_params # Streamlit >= 1.30
|
52 |
-
get_q = lambda k: qp.get(k)
|
53 |
-
except Exception:
|
54 |
-
qp = st.experimental_get_query_params()
|
55 |
-
get_q = lambda k: (qp.get(k, [None])[0] if isinstance(qp.get(k, None), list) else qp.get(k))
|
56 |
-
|
57 |
-
q_type = get_q("type")
|
58 |
-
if q_type == "recovery":
|
59 |
-
st.info("Masukkan password baru Anda di bawah ini.")
|
60 |
-
access_token = get_q("access_token")
|
61 |
-
refresh_token = get_q("refresh_token")
|
62 |
-
with st.form("reset_password_form"):
|
63 |
-
npw = st.text_input("Password Baru", type="password")
|
64 |
-
npw2 = st.text_input("Konfirmasi Password Baru", type="password")
|
65 |
-
submit_reset = st.form_submit_button("Set Password Baru")
|
66 |
-
if submit_reset:
|
67 |
-
if not npw or len(npw) < 6:
|
68 |
-
st.error("Password minimal 6 karakter.")
|
69 |
-
elif npw != npw2:
|
70 |
-
st.error("Konfirmasi password tidak sama.")
|
71 |
-
elif not access_token or not refresh_token:
|
72 |
-
st.error("Token pemulihan tidak ditemukan. Coba klik ulang tautan dari email.")
|
73 |
-
else:
|
74 |
-
try:
|
75 |
-
supabase.auth.set_session(access_token, refresh_token)
|
76 |
-
supabase.auth.update_user({"password": npw})
|
77 |
-
st.success("Password berhasil diubah. Silakan login kembali di halaman utama.")
|
78 |
-
# Clear query params and session state, then offer a back link
|
79 |
-
try:
|
80 |
-
st.experimental_set_query_params()
|
81 |
-
except Exception:
|
82 |
-
pass
|
83 |
-
st.markdown("[Kembali ke halaman utama](/)")
|
84 |
-
except Exception as e:
|
85 |
-
st.error(f"Gagal mengubah password: {e}")
|
86 |
-
return
|
87 |
-
|
88 |
-
# No recovery params found
|
89 |
-
st.warning("Tautan reset tidak valid atau sudah kadaluarsa. Silakan minta tautan baru melalui menu Forgot Password.")
|
90 |
-
st.markdown("[Kembali ke halaman utama](/)")
|
91 |
-
|
92 |
-
|
93 |
-
if __name__ == "__main__":
|
94 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|