You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.6 KiB
85 lines
2.6 KiB
import streamlit as st |
|
import streamlit_authenticator as stauth |
|
import yaml |
|
from yaml.loader import SafeLoader |
|
import main |
|
import create_credentials |
|
|
|
with open('credentials.yaml') as file: |
|
config = yaml.load(file, Loader=SafeLoader) |
|
|
|
authenticator = stauth.Authenticate( |
|
config['credentials'], |
|
config['cookie']['name'], |
|
config['cookie']['key'], |
|
config['cookie']['expiry_days'], |
|
config['preauthorized'] |
|
) |
|
|
|
def add_user(): |
|
st.write(':red[Skapa ny användare]') |
|
with st.form("new_credentials"): |
|
new_username = st.text_input('Användarnamn') |
|
new_name = st.text_input('Namn') |
|
new_pwd = st.text_input('Lösenord') |
|
submitted = st.form_submit_button("Lägg till användare", ) |
|
if submitted: |
|
credentials, valid = create_credentials.credentials(new_username, new_name, new_pwd) |
|
if valid: |
|
create_credentials.update(credentials, print_out=False, update=True) |
|
st.write('Användare tillagd.') |
|
else: |
|
st.write('Användare finns redan.') |
|
|
|
|
|
def main(): |
|
name, authentication_status, username = authenticator.login('Logga in', 'main') |
|
|
|
if authentication_status: |
|
|
|
# Say hello |
|
st.markdown(f':blue[**Hej {name}!**]') |
|
|
|
if username == 'admin': |
|
add_user() |
|
|
|
# Ask for input |
|
help_text = '[Du kan hitta en profils Facebook-ID här](https://lookup-id.com/)' |
|
user_input = str(st.text_input('Skriv in telefonnummer eller Facebook-ID', help=help_text, placeholder='Skriv här...')).strip() |
|
|
|
if user_input != '': |
|
s = [] |
|
for i in user_input: |
|
if i.isnumeric(): |
|
s.append(str(i)) |
|
s = ''.join(s) |
|
|
|
if s[0:2] == '07' and len(s) == 10: |
|
s = '46' + s[1:] |
|
|
|
# Search for info. |
|
r = main.search(s) |
|
|
|
# Present result. |
|
if r != None: |
|
if r['column_find'] == 'ID': |
|
id = r['find'] |
|
r['find'] = f'<a href="http://facebook.com/{id}">{id}</a>' |
|
st.write(f"{r['name']}, {r['column_find']}: {r['find']}", unsafe_allow_html=True) |
|
|
|
with st.expander('Mer information'): |
|
st.dataframe(r['df'], use_container_width=True) |
|
else: |
|
st.text('Not found.') |
|
|
|
authenticator.logout('Logout', 'main') |
|
|
|
elif authentication_status is False: |
|
st.error('Fel användarnamn/lösenord') |
|
|
|
elif authentication_status is None: |
|
st.warning('Skriv in användarnamn och lösenord') |
|
|
|
|
|
main() |
|
|
|
|