-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprofile_1.py
More file actions
110 lines (76 loc) · 2.91 KB
/
profile_1.py
File metadata and controls
110 lines (76 loc) · 2.91 KB
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
import streamlit as st
import firebase_admin
from firebase_admin import credentials
from firebase_admin import auth
from firebase_admin import firestore
def initialize_firebase_app():
try:
# Attempt to get the app, which will throw an exception if it doesn't exist
firebase_admin.get_app()
except ValueError:
# Initialize the app only if it doesn't exist
cred = credentials.Certificate('hopex-learn-6372ccf7e745.json')
firebase_admin.initialize_app(cred)
# Call the function to initialize the app
initialize_firebase_app()
def app():
st.title('Welcome to :violet[MDX learn]')
if 'username' not in st.session_state:
st.session_state.username = ''
if 'useremail' not in st.session_state:
st.session_state.useremail = ''
def f():
try:
user = auth.get_user_by_email(email)
print(user.uid)
st.success('Login Successfully!')
st.session_state.username = user.uid
st.session_state.useremail = user.email
st.session_state.signout = True
st.session_state.signedout = True
except:
st.warning('Login Failed')
# sign out function
def t():
st.session_state.signout = False
st.session_state.signedout = False
st.session_state.username = ''
if 'signedout' not in st.session_state:
st.session_state.signedout = False
if 'signout' not in st.session_state:
st.session_state.signout = False
if not st.session_state['signedout']:
choice = st.selectbox('Login/Signup', ['Login', 'Sign Up'])
if choice == 'Login':
email = st.text_input('Email Address')
password = st.text_input('Password', type='password')
st.button('Login', on_click=f)
else:
email = st.text_input('Email Address')
password = st.text_input('Password', type='password')
username = st.text_input('Enter your unique username')
if st.button('Create my account'):
user = auth.create_user(email=email, password=password, uid=username)
st.success('Account created successfully!')
st.markdown('Please login using your email and password')
st.balloons()
if st.session_state.signout:
st.text('Name: ' + st.session_state.username)
st.text('Email: ' + st.session_state.useremail)
if 'db' not in st.session_state:
st.session_state.db = ''
db = firestore.client()
st.session_state.db = db
docs = db.collection('Quizzes').get()
for doc in docs:
d = doc.to_dict()
if d['Username'] == st.session_state.username:
st.text('Taken Quizzes')
taken_quizzes = d['taken_quizzes']
quiz_scores = d['quiz_scores']
for i in range( len(taken_quizzes)-1, -1, -1):
st.text_area(label=':green[Quiz name: {}]'.format(taken_quizzes[i]), value=taken_quizzes[i]+': '+ str(quiz_scores[i]) + '/10 points', height=10, key = i)
else:
continue
print(d)
st.button('Sign out', on_click=t)