forked from Avdhesh-Varshney/Jarvis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jarvis.py
60 lines (48 loc) · 2.54 KB
/
Jarvis.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
from database.mongodb import create_connection, login_user
from database.localStorageServer import server
from datetime import datetime, timedelta
import streamlit as st
today = datetime.now()
if "user" not in st.session_state:
st.session_state['password'] = None
st.session_state["user"] = ['', '', '', '', '', '', '', '']
st.session_state['expiration_date'] = (today - timedelta(days=10)).isoformat()
st.session_state['verified'] = False
def getCredentials():
conn = server()
return conn.getLocalStorageVal("password"), conn.getLocalStorageVal("user"), conn.getLocalStorageVal("expiration_date"), conn.getLocalStorageVal("verified")
def logged_in():
from src.auth.login import login
userData, password, remember_me = login()
if userData != []:
conn = server()
user = [userData['username'], userData['email'], userData['first_name'], userData['last_name'], userData['role'], userData['gender'], userData['age'], userData['about']]
conn.setLocalStorageVal("user", user)
conn.setLocalStorageVal("password", password)
conn.setLocalStorageVal("expiration_date", (today + timedelta(days=(30 if remember_me else 1))).isoformat())
conn.setLocalStorageVal("verified", True)
st.info("Please refresh the page to continue", icon="ℹ️")
def application():
# /apps/public
home = st.Page("src/apps/public/home.py", title="Home", icon=":material/home:")
youtubePlaylist = st.Page("src/apps/public/youtubePlaylist.py", title="Jarvis Videos", icon=":material/ondemand_video:")
# /auth
login_page = st.Page(logged_in, title="Log in", icon=":material/login:")
sign_up_page = st.Page("src/auth/signup.py", title="Sign up", icon=":material/person_add:")
return st.navigation({"": [home, youtubePlaylist], "Account": [login_page, sign_up_page]})
if __name__ == "__main__":
app = application()
if st.session_state['password'] is None:
st.session_state['password'], st.session_state['user'], st.session_state['expiration_date'], st.session_state['verified'] = getCredentials()
if st.session_state['password'] is not None and st.session_state['expiration_date'] > today.isoformat():
if not st.session_state['verified']:
conn = create_connection()
result = login_user(conn, st.session_state['user'].split(',')[0], st.session_state['password'])
if result:
st.session_state['verified'] = True
conn = server()
conn.setLocalStorageVal("verified", True)
if st.session_state['verified']:
from src.utils.functions import load_functions
app = st.navigation(pages=load_functions())
app.run()