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

added login and logout

Browse files
Files changed (1) hide show
  1. login.py +69 -0
login.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from home import Home
3
+
4
+ def login():
5
+
6
+ st.set_page_config(
7
+ page_title="Login Page",
8
+ layout="centered",
9
+ initial_sidebar_state="collapsed"
10
+ )
11
+ col1, col2, col3 = st.columns(spec=[1, 3, 1])
12
+
13
+ with col2:
14
+ st.title("Login")
15
+ username = st.text_input("Email Address", value='johndoe@hr.company.com')
16
+ password = st.text_input("Password", type="password")
17
+
18
+
19
+ col1, col2 = st.columns(spec=[1,1])
20
+
21
+ with col1:
22
+ if st.button(
23
+ label="Forgot Password?",
24
+ use_container_width=True,
25
+ type="secondary"
26
+ ):
27
+
28
+ st.info("Please contact your manager or the IT department for a password reset.")
29
+
30
+ with col2:
31
+ if st.button(
32
+ label="Login",
33
+ use_container_width=True,
34
+ type="primary"
35
+ ):
36
+
37
+ class UnregisteredUser(Exception):
38
+ """
39
+ Represents an exception when the user is not registered.
40
+ """
41
+
42
+ def __init__(self, message="User not registered"):
43
+ self.message = message
44
+ super().__init__(self.message)
45
+
46
+ class IncompleteDetails(Exception):
47
+ """
48
+ Represents an exception when the user's details are incomplete.
49
+ """
50
+
51
+ def __init__(self, message="Incomplete details"):
52
+ self.message = message
53
+ super().__init__(self.message)
54
+
55
+ #imaginary db calls for existing user, if user is in imaginary db, user is logged in
56
+ try:
57
+ if username == "johndoe@hr.company.com" and password == "password":
58
+ st.session_state.LOGGED_IN = True
59
+ st.switch_page(st.Page(Home, title="Home", icon=":material/home:"))
60
+
61
+ if username == "" or password == "":
62
+ raise IncompleteDetails
63
+
64
+ raise UnregisteredUser
65
+
66
+ except UnregisteredUser as e:
67
+ st.error(e)
68
+ except IncompleteDetails as e:
69
+ st.error(e)