Spaces:
Running
Running
File size: 4,245 Bytes
c1af3b2 350a399 c1af3b2 e3df3f1 c1af3b2 350a399 c1af3b2 350a399 c1af3b2 350a399 c1af3b2 e7e1917 c1af3b2 350a399 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
import streamlit as st
import os
import base64
from utils.utils import __get_user_details,app_config_col,encrypt_with_password,__encode, __update_user_config, __generate_password
def load_user_config():
st.sidebar.header("Options")
page = st.sidebar.radio("Select Option", ["Validate New User", "Show User Details"],label_visibility="collapsed")
if st.sidebar.button("Logout"):
st.session_state.logged_in = False
st.session_state.user = None
st.session_state.show_audio = False
st.session_state.bg_started = False
st.rerun()
if page=="Validate New User":
new_users = __get_user_details(user_type='New')
# Initialize step index in session state
if "index" not in st.session_state:
st.session_state.index = 0
# --- Sidebar Profile Section ---
st.title("User Information")
# Stop if finished
if st.session_state.index >= len(new_users):
st.success("No new user to validate")
if st.button("Restart"):
st.session_state.index = 0
st.rerun()
st.stop()
# Show current item
current_user = new_users[st.session_state.index]
st.info("Username: **{}**".format(current_user.get("username")))
st.info("Email: **{}**".format(current_user.get("email")))
st.info("Token: **{}**".format(current_user.get("token")))
st.info("Validated By: **{}**".format(current_user.get("validated_by","Validation Not Completed")))
is_email_validated=st.selectbox(label="Is Email Validation Completed?",options=["Y", "N"])
# User action area
st.write("Perform your action below:")
action_done = st.checkbox("TokenID is send to email:{}".format(current_user.get("email")))
# Next button
if st.button("Next"):
if not action_done:
st.warning("Please complete the action before continuing!")
else:
#current_user['token']="1111"
current_user['validated_by']=st.session_state.user
current_user['_is_validated']= "Y" if is_email_validated=="Y" else "N"
current_user['_is_email_validated'] = is_email_validated
salt_bytes=base64.b64encode(app_config_col.get('SALT_KEY').encode("utf-8"))
app_api_key=app_config_col.get("APP_API_KEY")
enc = encrypt_with_password(app_api_key, salt_bytes, current_user)
__update_user_config(key=__encode(userinfo=current_user),value=enc)
st.session_state.index += 1
st.rerun()
if page=="Show User Details":
users = __get_user_details()
# Initialize step index
if "index" not in st.session_state:
st.session_state.index = 0
st.title("User Information")
# Bound protection
total_users = len(users)
if total_users == 0:
st.warning("No users found")
st.stop()
if st.session_state.index >= total_users:
st.session_state.index = total_users - 1
if st.session_state.index < 0:
st.session_state.index = 0
current_user = users[st.session_state.index]
st.info(f"Username: **{current_user.get('username')}**")
st.info(f"Email: **{current_user.get('email')}**")
st.info(f"Token: **{current_user.get('token')}**")
st.info(f"Validated By: **{current_user.get('validated_by','Validation Not Completed')}**")
# -------- Horizontal Navigation UI --------
col1, col2 = st.columns([1, 1])
with col1:
disable_prev = (st.session_state.index == 0)
if st.button("⬅ Previous", disabled=disable_prev):
st.session_state.index -= 1
st.rerun()
with col2:
disable_next = (st.session_state.index == total_users - 1)
if st.button("Next ➡", disabled=disable_next):
st.session_state.index += 1
st.rerun() |