File size: 8,307 Bytes
65c2736
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
import streamlit as  st
import streamlit.components.v1 as components
from streamlit_navigation_bar import st_navbar
from streamlit_option_menu import option_menu
import time

from app import *
from FirebaseDatabase.FirebaseDB import *
import re

##########################################authentication
import yaml
from yaml.loader import SafeLoader


##########################################
def store_email_in_browser(email):
    js = f"""

    <script>

        localStorage.setItem("user_email", "{email}");

    </script>

    """
    st.markdown(js, unsafe_allow_html=True)

introBar7Style = """

<style>

/*Remove popover borders*/

div.st-emotion-cache-m9wt8r div[data-testid="stPopover"] button.st-emotion-cache-1sy6v2f, 

div.st-emotion-cache-m9wt8r div[data-testid="stPopover"] button.st-emotion-cache-xkcexs

{

    padding: 0rem 0rem;

    background-color: transparent;

    border: 0px solid rgba(250, 250, 250, 0.2);

}



/*Nav Bar Adjustments*/

.st-emotion-cache-1ascbf6,.st-emotion-cache-1fke7y1 {

    border: 0px solid rgba(250, 250, 250, 0.2);

    border-radius:0;

    /*height: auto;*/

    z-index: 999999;

    position:fixed;

    width: 100%;

    /*max-height: 50px;*/

    overflow-y: scroll;

}

.st-emotion-cache-1ascbf6{

    background-color: black; 

}

.st-emotion-cache-1fke7y1{

    background-color: white;

}



/*Display the Streamlit Main Menu*/

.st-emotion-cache-12fmjuu, .st-emotion-cache-h4xjwg {

    position: unset;

}



.st-emotion-cache-15ecox0 {

    top: 1.2rem;

    right: 0.7rem;

}



.st-emotion-cache-czk5ss {

    z-index: 9999999;

}



/*LOGO and Sidebar*/

.st-emotion-cache-19u4bdk {

    z-index: 99999999;

    top:0.65rem;

    left:1.5rem;

}



/*First Page LOGO*/

.st-emotion-cache-5drf04 {

    height: 2.5rem;

}



.st-emotion-cache-17sc1v6 {

    height: 2.5rem;

}



/*Button Wrap*/

    button, [type="button"], [type="reset"], [type="submit"] {

            white-space: nowrap;

        }



.st-emotion-cache-m9wt8r {

    min-width: 60px;

}





@media (max-width: 640px) {

    .st-emotion-cache-1j8f7fw {

        max-width: 350px;

        min-width: 0px;

    }

}



@media (max-width: 640px) {

    .st-emotion-cache-m9wt8r {

        max-width: 100px;

        min-width: 0px;

    }

}



@media (max-width: 950px) {

    .st-emotion-cache-15ecox0 {

        right: 0rem; /* Reduce right spacing */

    }

}



@media (max-width: 700px) {

    .st-emotion-cache-15ecox0 {

        top: -5rem; /* Reduce right spacing */

    }

}

</style>

"""

@st.dialog("Login")
def loginForm():
    # with open('config.yaml') as file:
    #     config = yaml.load(file, Loader=SafeLoader)

    # stauth.Hasher.hash_passwords(config['credentials'])

    # st.session_state.authenticator = stauth.Authenticate(
    # config['credentials'],
    # config['cookie']['name'],
    # config['cookie']['key'],
    # config['cookie']['expiry_days'],
    # auto_hash = False
    # )
    # st.session_state.login = st.session_state.authenticator.login(key="initialLogin")
    with st.form(key="LoginForm", clear_on_submit=False):
        email = st.text_input(label = "Email")
        password = st.text_input(label= "Password", type = "password")
        margin, buttoncol = st.columns([0.92,0.08]) 
        loginSubmit = st.form_submit_button(label = "SignIn", use_container_width=True)

    if loginSubmit:
        with st.spinner("Verifying credentials..."):
            if email == "" or password == "":
                st.error('Please enter your username or password')
            else:
                db = firebaseDB()
                st.session_state.database = db
                if db.get_user(email, password):
                    st.session_state.logged_in = True
                    store_email_in_browser(email)

            # if st.session_state['authentication_status']:
            #     st.session_state.logged_in = True
                #st.switch_page(dashboard)
                    st.switch_page(AIManagement)
                else:
                    st.error('Username/password is incorrect')
            #st.session_state.logged_in = True

def emailvalidator(email):
    pattern = r'^[\w\.-]+@grcai\.com$'
    if not re.match(pattern, email):
        st.error('Email must be a grcai.com email!')

def passwordvalidator(password):
    if len(password) < 8:
        st.error('Password must be at least 8 characters long!')
    elif not re.search("[a-z]", password):
        st.error('Password must contain at least one lowercase letter!')
    elif not re.search("[A-Z]", password):
        st.error('Password must contain at least one uppercase letter!')
    elif not re.search("[0-9]", password):
        st.error('Password must contain at least one number!')
    elif not re.search(r"[!@#$%^&*()_+\-=[\]{};':,.<>/?]", password):
        st.error('Password must contain at least one special character!')


@st.dialog("Sign Up")
def signupForm():
    with st.form(key="SignupForm"):
        username = st.text_input(label = "Username", max_chars = 30)
        email = st.text_input(label = "Email", placeholder="user@grcai.com")
        if email:
            emailvalidator(email)
        company = st.text_input(label = "Company Name")
        st.divider()
        password = st.text_input(label= "Password", type = "password", placeholder = "Atleast 8 characters", help = "Must include letters, numbers or special characters or both")
        if password:
            passwordvalidator(password)
        repeat_password = st.text_input(label="Repeat Password", type = "password")

        margin, buttoncol = st.columns([0.92,0.08]) 
        signupSubmit = st.form_submit_button(label = "SignUp", use_container_width=True)

    if signupSubmit:
        if email == "" or password == "" or repeat_password == "" or username == "":
            st.error('All fields are required!')
        elif password != repeat_password:
            st.error('Passwords do not match!')
        else:
            db = firebaseDB()
            db.new_user(username, email, password, company)
            st.toast("User Registered Successfully!")
            st.rerun()

def introBar7():
    introBar = st.container(height=40,border = True)
    
    with introBar:
        blankdiv, loginbutton, signupbutton, marginright = st.columns([0.75,0.1,0.1,0.05],vertical_alignment="center")

        """

        with popover1:

            st.markdown(''' 

                        <a target="_self" href="#html-heading6" style="color: inherit; text-decoration: none; display: flex; align-items:center; justify-content:center; font-weight: 400; margin:0; padding:0;">LinkButton1</a>

                        ''', unsafe_allow_html=True)





        with popover2:

            st.markdown(''' 

                        <a target="_self" href="#html-heading6" style="color: inherit; text-decoration: none; display: flex; align-items:center; justify-content:center; font-weight: 400; margin:0; padding:0;">LinkButton2</a>

                        ''', unsafe_allow_html=True)



    

        

        with popover3:

            st.markdown(''' 

                        <a target="_self" href="#html-heading6" style="color: inherit; text-decoration: none; display: flex; align-items:center; justify-content:center; font-weight: 400; margin:0; padding:0;">LinkButton3</a>

                        ''', unsafe_allow_html=True)







        with popover4:

            st.markdown(''' 

                        <a target="_self" href="#html-heading6" style="color: inherit; text-decoration: none; display: flex; align-items:center; justify-content:center; font-weight: 400; margin:0; padding:0;">LinkButton4</a>

                        ''', unsafe_allow_html=True)





        """
        with loginbutton:
            loginClick = st.button(label=":material/login: Login", use_container_width=True)
            if loginClick:
                loginForm()

        
        with signupbutton:
            signupClick = st.button(label="SignUp",type="primary",use_container_width=True)
            if signupClick:
                signupForm()

    
    st.markdown(introBar7Style ,unsafe_allow_html=True)