| import streamlit as st |
| import extra_streamlit_components as stx |
| from dependency import get_manager |
| from dependency import db |
| from passlib.hash import pbkdf2_sha256 |
| import bcrypt |
|
|
| admin_collection = db['admin'] |
|
|
| |
| st.session_state.cookie = "value" |
| st.session_state.cookie_expires = 3600 |
| st.session_state.cookie_domain = "share.streamlit.io" |
| st.session_state.cookie_secure = True |
| st.session_state.cookie_path = "/" |
|
|
| |
| def authenticate(email, password): |
| |
| admin = admin_collection.find_one({"email": email}) |
|
|
| |
| if not admin: |
| return False |
|
|
| if bcrypt.checkpw(password.encode('utf-8'), admin["password"].encode('utf-8')): |
| return True |
| else: |
| return False |
|
|
| |
| if pbkdf2_sha256.verify(password, admin["password"]): |
| return True |
| else: |
| return False |
|
|
| cookie_manager = get_manager() |
| auth_state = cookie_manager.get(cookie='auth_state') |
|
|
| def login(): |
| st.title("Login") |
| username = st.text_input("Username") |
| password = st.text_input("Password", type="password") |
| if st.button("Login"): |
| if authenticate(username, password): |
| st.success("Login successful!") |
| cookie_manager.set('auth_state', 'authenticated') |
| st.session_state.auth_state = True |
| st.switch_page('pages/manage_faqs.py') |
| else: |
| st.error("Invalid username or password") |
|
|
| if not auth_state == "authenticated": |
| login() |
| else: |
| st.warning("You are already logged in. Redirecting to FAQ management page.") |
| st.experimental_set_query_params(page="manage_faqs") |