-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_pages.py
128 lines (117 loc) · 4.63 KB
/
auth_pages.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import streamlit as st
from auth import register_user, authenticate_user
def render_login_page():
"""Render the login page"""
st.markdown("""
<style>
.main {
background-color: #FFF8E6;
}
.stButton>button {
background-color: #1E1B4B;
color: white;
border-radius: 8px;
padding: 0.75rem 1.5rem;
width: 100%;
}
.form-container {
max-width: 400px;
margin: 0 auto;
padding: 2rem;
background: white;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
/* New input field styles */
.stTextInput>div>div>input {
color: #1E1B4B !important;
background-color: white !important;
border: 1px solid #E5E7EB !important;
border-radius: 8px !important;
padding: 0.75rem !important;
font-size: 1rem !important;
transition: border-color 0.2s ease !important;
}
.stTextInput>div>div>input:focus {
border-color: #1E1B4B !important;
box-shadow: 0 0 0 2px rgba(30, 27, 75, 0.1) !important;
}
.stTextInput>div>div>input::placeholder {
color: #6B7280 !important;
opacity: 1 !important;
}
.stSelectbox>div>div>div {
color: #1E1B4B !important;
background-color: white !important;
border: 1px solid #E5E7EB !important;
border-radius: 8px !important;
}
</style>
""", unsafe_allow_html=True)
st.image("assets/logoclio.png", width=100)
st.markdown("<h1 style='text-align: center;'>Welcome to Clio AI</h1>", unsafe_allow_html=True)
with st.form("login_form"):
email = st.text_input("Email address")
password = st.text_input("Password", type="password")
if st.form_submit_button("Log In"):
if email and password:
result = authenticate_user(email, password)
if "error" in result:
st.error(result["error"])
else:
st.session_state.user_id = result["user_id"]
st.session_state.user_email = result["email"]
st.session_state.access_token = result["access_token"]
st.rerun()
else:
st.error("Please fill in all fields")
col1, col2 = st.columns(2)
with col1:
if st.button("Don't have an account?"):
st.session_state.show_register = True
st.rerun()
with col2:
if st.button("Forgot password?"):
st.session_state.show_reset = True
st.rerun()
def render_registration_page():
"""Render the registration page"""
st.image("assets/logoclio.png", width=100)
st.markdown("<h1 style='text-align: center;'>Create Account</h1>", unsafe_allow_html=True)
with st.form("registration_form"):
email = st.text_input("Email address")
password = st.text_input("Password", type="password")
name = st.text_input("Name")
surname = st.text_input("Surname")
cellphone = st.text_input("Cellphone")
purpose = st.selectbox(
"How can we help you?",
["", "For Education - Personalized Learning", "For Human Resources", "For Marketing - Personalized Ads"]
)
if st.form_submit_button("Sign Up"):
if all([email, password, name, surname, cellphone, purpose]):
result = register_user(email, password, name, surname, cellphone, purpose)
if "error" in result:
st.error(result["error"])
else:
st.success(result["message"])
# Set session state for automatic login
st.session_state.user_id = result["user_id"]
st.session_state.user_email = result["email"]
st.session_state.access_token = result["access_token"]
st.rerun()
else:
st.error("Please fill in all fields")
if st.button("Already have an account? Log in"):
st.session_state.show_register = False
st.rerun()
def render_auth_pages():
"""Main function to render authentication pages"""
if "show_register" not in st.session_state:
st.session_state.show_register = False
if "show_reset" not in st.session_state:
st.session_state.show_reset = False
if st.session_state.show_register:
render_registration_page()
else:
render_login_page()