Spaces:
Running
Running
| 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() |