Spaces:
Sleeping
Sleeping
added login functionality *hard coded* user
Browse files
app.py
CHANGED
|
@@ -5,19 +5,68 @@ from resume_screener import ResumeScreener
|
|
| 5 |
from user_documentation import UserDocumentation
|
| 6 |
from home import Home
|
| 7 |
|
| 8 |
-
UserDocPage = st.Page(UserDocumentation, title="User Documentation")
|
| 9 |
-
ResumeScreenerPage = st.Page(ResumeScreener, title="Resume Screener")
|
| 10 |
-
HomePage = st.Page(Home, title="Home")
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from user_documentation import UserDocumentation
|
| 6 |
from home import Home
|
| 7 |
|
| 8 |
+
UserDocPage = st.Page(UserDocumentation, title="User Documentation", icon=":material/help:")
|
| 9 |
+
ResumeScreenerPage = st.Page(ResumeScreener, title="Resume Screener", icon=":material/recent_actors:")
|
| 10 |
+
HomePage = st.Page(Home, title="Home", icon=":material/home:")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if "LOGGED_IN" not in st.session_state:
|
| 14 |
+
st.session_state.LOGGED_IN = False
|
| 15 |
+
|
| 16 |
+
if st.session_state.LOGGED_IN:
|
| 17 |
+
pages = {
|
| 18 |
+
"Dashboard": [
|
| 19 |
+
HomePage,
|
| 20 |
+
ResumeScreenerPage,
|
| 21 |
+
],
|
| 22 |
+
"Resources": [
|
| 23 |
+
UserDocPage,
|
| 24 |
+
]
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
pg = st.navigation(pages)
|
| 28 |
+
pg.run()
|
| 29 |
+
|
| 30 |
+
else:
|
| 31 |
+
col1, col2, col3 = st.columns(spec=[1, 3, 1])
|
| 32 |
+
|
| 33 |
+
with col2:
|
| 34 |
+
st.title("Login")
|
| 35 |
+
username = st.text_input("Email Address", value="johndoe@hr.company.com")
|
| 36 |
+
password = st.text_input("Password", type="password")
|
| 37 |
+
|
| 38 |
+
if st.button("Login"):
|
| 39 |
+
|
| 40 |
+
class UnregisteredUser(Exception):
|
| 41 |
+
"""
|
| 42 |
+
Represents an exception when the user is not registered.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
def __init__(self, message="User not registered"):
|
| 46 |
+
self.message = message
|
| 47 |
+
super().__init__(self.message)
|
| 48 |
+
|
| 49 |
+
class IncompleteDetails(Exception):
|
| 50 |
+
"""
|
| 51 |
+
Represents an exception when the user's details are incomplete.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
def __init__(self, message="Incomplete details"):
|
| 55 |
+
self.message = message
|
| 56 |
+
super().__init__(self.message)
|
| 57 |
+
|
| 58 |
+
#imaginary db calls for existing user, if user is in imaginary db, user is logged in
|
| 59 |
+
try:
|
| 60 |
+
if username == "johndoe@hr.company.com" and password == "password":
|
| 61 |
+
st.session_state.LOGGED_IN = True
|
| 62 |
+
st.rerun()
|
| 63 |
+
|
| 64 |
+
if username == "" or password == "":
|
| 65 |
+
raise IncompleteDetails
|
| 66 |
+
|
| 67 |
+
raise UnregisteredUser
|
| 68 |
+
|
| 69 |
+
except UnregisteredUser as e:
|
| 70 |
+
st.error(e)
|
| 71 |
+
except IncompleteDetails as e:
|
| 72 |
+
st.error(e)
|