chrisandrei commited on
Commit
ec42a37
·
verified ·
1 Parent(s): 9f9aa0a

added login and logout

Browse files
Files changed (1) hide show
  1. app.py +38 -42
app.py CHANGED
@@ -1,18 +1,52 @@
1
  import streamlit as st
 
2
 
3
  #importing the pages
4
  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", 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": [
@@ -21,6 +55,9 @@ if st.session_state.LOGGED_IN:
21
  ],
22
  "Resources": [
23
  UserDocPage,
 
 
 
24
  ]
25
  }
26
 
@@ -28,45 +65,4 @@ if st.session_state.LOGGED_IN:
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)
 
1
  import streamlit as st
2
+ import time
3
 
4
  #importing the pages
5
  from resume_screener import ResumeScreener
6
  from user_documentation import UserDocumentation
7
  from home import Home
8
+ from login import login
9
 
10
  UserDocPage = st.Page(UserDocumentation, title="User Documentation", icon=":material/help:")
11
  ResumeScreenerPage = st.Page(ResumeScreener, title="Resume Screener", icon=":material/recent_actors:")
12
  HomePage = st.Page(Home, title="Home", icon=":material/home:")
13
+ LoginPage = st.Page(login, title="Login", icon=":material/login:")
14
 
15
+ if 'USER_DOC_PAGE' not in st.session_state:
16
+ st.session_state.USER_DOC_PAGE = UserDocPage
17
+
18
+ if 'RESUME_SCREENER_PAGE' not in st.session_state:
19
+ st.session_state.RESUME_SCREENER_PAGE = ResumeScreenerPage
20
+
21
+ if 'HOME_PAGE' not in st.session_state:
22
+ st.session_state.HOME_PAGE = HomePage
23
+
24
+ if 'CURRENT_PAGE' not in st.session_state:
25
+ st.session_state.CURRENT_PAGE = None
26
 
27
  if "LOGGED_IN" not in st.session_state:
28
  st.session_state.LOGGED_IN = False
29
 
30
+ def logout():
31
+ @st.dialog("Are you sure you want to log out?")
32
+
33
+ def chose():
34
+ col1, col2 = st.columns(spec=[1,1])
35
+
36
+ with col1:
37
+ if st.button("No", use_container_width=True):
38
+ st.switch_page(st.session_state.CURRENT_PAGE)
39
+
40
+ with col2:
41
+ if st.button("Yes", use_container_width=True):
42
+ st.session_state.clear()
43
+ st.rerun()
44
+
45
+ chose()
46
+
47
+
48
+ logout_page = st.Page(logout, title="Log out", icon=":material/logout:")
49
+
50
  if st.session_state.LOGGED_IN:
51
  pages = {
52
  "Dashboard": [
 
55
  ],
56
  "Resources": [
57
  UserDocPage,
58
+ ],
59
+ "Account": [
60
+ logout_page
61
  ]
62
  }
63
 
 
65
  pg.run()
66
 
67
  else:
68
+ login()