File size: 2,065 Bytes
cdd0177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import yaml
import streamlit as st
from yaml.loader import SafeLoader
import streamlit_authenticator as stauth
from streamlit_authenticator.utilities.exceptions import (CredentialsError,ForgotError,LoginError,RegisterError,ResetError,UpdateError) 
from streamlit_extras.switch_page_button import switch_page
import pickle

#  https://docs.kanaries.net/topics/Streamlit/streamlit-authentication
# Loading config file


if 'auth' not in st.session_state:
    st.session_state['auth'] = ''
if 'logged_in' not in st.session_state:
    st.session_state['logged_in'] = ''

st.session_state["authentication_status"] = None
st.session_state['logged_in'] = False

filehandler = open(b"login_state.pkl","wb")
pickle.dump(st.session_state['logged_in'],filehandler)

with open('config.yaml', 'r', encoding='utf-8') as file:
    config = yaml.load(file, Loader=SafeLoader)

# Creating the authenticator object
authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['pre-authorized']
)
st.session_state['auth'] = authenticator
# Creating a login widget
try:
    a = authenticator.login()
    print(a)
except LoginError as e:
    st.error(e)

if st.session_state["authentication_status"]:
    authenticator.logout()
    st.session_state["logged_in"] = True
    filehandler = open(b"login_state.pkl","wb")
    pickle.dump(st.session_state['logged_in'],filehandler)
    switch_page("page_0")
elif st.session_state["authentication_status"] is False:
    st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] is None:
    st.warning('Please enter your username and password')

st.subheader("CONFIDENTIALITY NOTICE:  This Dashboard, its analysis and any accompanying data / documents contain information belonging to the San Bernardino Public Defender's Office which may be confidential and legally bounded by The work product doctrine. This information is only for the use of the individual or entity to which it was intended.")