-
Notifications
You must be signed in to change notification settings - Fork 18
/
Welcome.py
89 lines (75 loc) · 3.14 KB
/
Welcome.py
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
import streamlit as st
import streamlit_authenticator as stauth
import pandas as pd
import yaml
from yaml.loader import SafeLoader
import os, sys
from PIL import Image
from UserInterface.helpers import header, safeToYaml
from brownian_motion_generator import brownian_motion_generator
# Get the current directory
current_dir = os.path.dirname(os.path.abspath(__file__))
header(current_dir)
with open('./config.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
st.session_state["authenticator"] = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)
# Sign-up section
with st.expander('Sign-Up', expanded=False):
try:
if st.session_state["authenticator"].register_user(preauthorization=False):
st.success('User registered successfully')
safeToYaml(config)
except Exception as e:
st.error(e)
# Login section
with st.expander('Login', expanded=False):
st.session_state["authenticator"].login()
if st.session_state["authentication_status"]:
st.success(f'✅ Successfully signed in as *{st.session_state["name"]}*')
elif st.session_state["authentication_status"] is False:
st.error('Username/password is incorrect')
# Forgot password
try:
username_of_forgotten_password, email_of_forgotten_password, new_random_password = st.session_state["authenticator"].forgot_password(fields=['username', 'email'])
if username_of_forgotten_password:
st.success('New password to be sent securely')
# Random password should be transferred to user securely
else:
st.error('Username not found')
except Exception as e:
st.error(e)
# Forgot username
try:
username_of_forgotten_username, email_of_forgotten_username = st.session_state["authenticator"].forgot_username(field='email')
if username_of_forgotten_username:
st.success('Username to be sent securely')
# Username should be transferred to user securely
else:
st.error('Email not found')
except Exception as e:
st.error(e)
elif st.session_state["authentication_status"] is None:
st.warning('Please enter your username and password')
# Update user details section
if st.session_state["authentication_status"]:
with st.expander('Update User Details', expanded=False):
# Update user details
try:
if st.session_state["authenticator"].update_user_details(username=st.session_state["username"]):
st.success('Entries updated successfully')
safeToYaml(config)
except Exception as e:
st.error(e)
# Reset password
try:
if st.session_state["authenticator"].reset_password(username=st.session_state["username"]):
st.success('Password modified successfully')
safeToYaml(config)
except Exception as e:
st.error(e)