-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
80 lines (57 loc) · 2.52 KB
/
streamlit_app.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
# Import Necessary Libraries ------------------------------
import streamlit as st
from streamlit_extras.switch_page_button import switch_page
from datetime import datetime
import os
import json
from google.cloud import firestore
from google.oauth2 import service_account
# ---------------------------------------------------------
# DATABASE ------------------------------------------------
# Connect to firestore database by using JSON account key
key_dict = json.loads(st.secrets["textkey"])
creds = service_account.Credentials.from_service_account_info(key_dict)
db = firestore.Client(credentials=creds)
# Lists out all the collection in the database (For user verification purposes)
userList = [collection.id for collection in db.collections()]
# Read all posts
post_ref = db.collection('user1')
# ----------------------------------------------------------
# STREAMLIT ------------------------------------------------
# Page STYLE ===============
st.set_page_config(initial_sidebar_state="collapsed")
st.markdown(
"""
<style>
[data-testid="collapsedControl"] {
display: none
}
</style>
""",
unsafe_allow_html=True,
)
# ============================
# Display Page
st.header('Smart Irrigation System')
# LOGIN FUNCTION ===================================================================
username = st.text_input('Username: ')
if st.button('Login'):
if len(username) == 0:
st.warning("Username should not be EMPTY!", icon='🚨')
elif username not in userList:
st.warning("Username has not been registered", icon='🚨')
else:
userInfo = db.collection(username).document('secret').get().to_dict()
currUser = db.collection('currentUser').document('curr').get().to_dict()
if userInfo['password'] == currUser['rfid']:
curr_username = db.collection('currentUser').document('curr')
curr_username.set({'rfid': "b''", 'user':username})
switch_page('main')
elif currUser['rfid'] == "b''":
st.warning("Please scan RFID card/ tag", icon='🚨')
elif userInfo['password'] != currUser['rfid']:
st.warning("Username and RFID card/tag did not match", icon='🚨')
elif st.button('Don\'t have an account yet? Click to Register'):
switch_page('register')
# =================================================================================
# ----------------------------------------------------------