Jon Solow
commited on
Commit
•
86b69b9
1
Parent(s):
f9247be
Connect the user registration and new url request to the db
Browse files- src/data_storage.py +1 -0
- src/login.py +16 -13
src/data_storage.py
CHANGED
@@ -104,3 +104,4 @@ def create_new_token_for_user(user_id: int, existing_user: bool = False):
|
|
104 |
VALUES({user_id}, '{token}')
|
105 |
"""
|
106 |
)
|
|
|
|
104 |
VALUES({user_id}, '{token}')
|
105 |
"""
|
106 |
)
|
107 |
+
return token
|
src/login.py
CHANGED
@@ -5,7 +5,7 @@ import re
|
|
5 |
import streamlit as st
|
6 |
from streamlit_gsheets import GSheetsConnection
|
7 |
from streamlit.runtime.secrets import AttrDict, secrets_singleton
|
8 |
-
from data_storage import get_user_id_if_email_exists, get_user, add_new_user
|
9 |
|
10 |
|
11 |
class HFFriendlyGSheetsConnection(GSheetsConnection):
|
@@ -78,32 +78,35 @@ def generate_new_token_request():
|
|
78 |
if not check_email(email := st.session_state["reset_token_user_email"]):
|
79 |
st.warning("Sorry email is invalid. Please try a valid email address.")
|
80 |
return
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
conn.update(
|
83 |
-
worksheet="token-requests",
|
84 |
-
data=pd.DataFrame(
|
85 |
-
{
|
86 |
-
"email": email,
|
87 |
-
},
|
88 |
-
index=[0],
|
89 |
-
),
|
90 |
-
)
|
91 |
st.info("Request submitted. Please check your email for a login url with a few minutes.")
|
92 |
del st.session_state["reset_token_user_email"]
|
93 |
|
94 |
|
95 |
-
def
|
96 |
conn.update(
|
97 |
-
worksheet="
|
98 |
data=pd.DataFrame(
|
99 |
{
|
100 |
"email": email,
|
101 |
-
"
|
102 |
},
|
103 |
index=[0],
|
104 |
),
|
105 |
)
|
|
|
|
|
|
|
106 |
add_new_user(email, name)
|
|
|
|
|
|
|
|
|
107 |
st.info("New user request submitted. Please check your email for a login url with a few minutes.")
|
108 |
|
109 |
|
|
|
5 |
import streamlit as st
|
6 |
from streamlit_gsheets import GSheetsConnection
|
7 |
from streamlit.runtime.secrets import AttrDict, secrets_singleton
|
8 |
+
from data_storage import get_user_id_if_email_exists, get_user, add_new_user, create_new_token_for_user
|
9 |
|
10 |
|
11 |
class HFFriendlyGSheetsConnection(GSheetsConnection):
|
|
|
78 |
if not check_email(email := st.session_state["reset_token_user_email"]):
|
79 |
st.warning("Sorry email is invalid. Please try a valid email address.")
|
80 |
return
|
81 |
+
user_id = get_user_id_if_email_exists(email)
|
82 |
+
if not user_id:
|
83 |
+
return
|
84 |
+
token = create_new_token_for_user(user_id, existing_user=True)
|
85 |
+
insert_new_token_to_sheet(email, token)
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
st.info("Request submitted. Please check your email for a login url with a few minutes.")
|
88 |
del st.session_state["reset_token_user_email"]
|
89 |
|
90 |
|
91 |
+
def insert_new_token_to_sheet(email: str, token: str):
|
92 |
conn.update(
|
93 |
+
worksheet="token-requests",
|
94 |
data=pd.DataFrame(
|
95 |
{
|
96 |
"email": email,
|
97 |
+
"token": token,
|
98 |
},
|
99 |
index=[0],
|
100 |
),
|
101 |
)
|
102 |
+
|
103 |
+
|
104 |
+
def create_new_user_request(email: str, name: str):
|
105 |
add_new_user(email, name)
|
106 |
+
user_id = get_user_id_if_email_exists(email)
|
107 |
+
assert user_id
|
108 |
+
token = create_new_token_for_user(user_id)
|
109 |
+
insert_new_token_to_sheet(email, token)
|
110 |
st.info("New user request submitted. Please check your email for a login url with a few minutes.")
|
111 |
|
112 |
|