Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -87,7 +87,9 @@ def authenticate_gmail(credentials_file):
|
|
87 |
if creds and creds.valid:
|
88 |
st.session_state.creds = creds
|
89 |
st.session_state.authenticated = True
|
90 |
-
st.
|
|
|
|
|
91 |
return creds
|
92 |
except Exception as e:
|
93 |
st.error(f"β Invalid token.json file: {e}")
|
@@ -97,7 +99,9 @@ def authenticate_gmail(credentials_file):
|
|
97 |
creds.refresh(Request())
|
98 |
st.session_state.creds = creds
|
99 |
st.session_state.authenticated = True
|
100 |
-
st.
|
|
|
|
|
101 |
with open('token.json', 'w') as token_file:
|
102 |
token_file.write(creds.to_json())
|
103 |
return creds
|
@@ -112,13 +116,21 @@ def authenticate_gmail(credentials_file):
|
|
112 |
|
113 |
def submit_auth_code():
|
114 |
try:
|
|
|
115 |
st.session_state.flow.fetch_token(code=st.session_state.auth_code)
|
116 |
st.session_state.creds = st.session_state.flow.credentials
|
117 |
-
|
|
|
118 |
with open('token.json', 'w') as token_file:
|
119 |
-
st.session_state.creds.to_json(
|
|
|
|
|
|
|
|
|
120 |
st.success("β
Authentication successful!")
|
121 |
except Exception as e:
|
|
|
|
|
122 |
st.error(f"β Error during authentication: {e}")
|
123 |
|
124 |
# ===============================
|
|
|
87 |
if creds and creds.valid:
|
88 |
st.session_state.creds = creds
|
89 |
st.session_state.authenticated = True
|
90 |
+
if not st.session_state.candidates_message_shown:
|
91 |
+
st.success("β
Authentication successful!")
|
92 |
+
st.session_state.candidates_message_shown = True
|
93 |
return creds
|
94 |
except Exception as e:
|
95 |
st.error(f"β Invalid token.json file: {e}")
|
|
|
99 |
creds.refresh(Request())
|
100 |
st.session_state.creds = creds
|
101 |
st.session_state.authenticated = True
|
102 |
+
if not st.session_state.candidates_message_shown:
|
103 |
+
st.success("β
Authentication successful!")
|
104 |
+
st.session_state.candidates_message_shown = True
|
105 |
with open('token.json', 'w') as token_file:
|
106 |
token_file.write(creds.to_json())
|
107 |
return creds
|
|
|
116 |
|
117 |
def submit_auth_code():
|
118 |
try:
|
119 |
+
# Attempt to fetch the token using the provided authorization code
|
120 |
st.session_state.flow.fetch_token(code=st.session_state.auth_code)
|
121 |
st.session_state.creds = st.session_state.flow.credentials
|
122 |
+
|
123 |
+
# Attempt to write the credentials to token.json
|
124 |
with open('token.json', 'w') as token_file:
|
125 |
+
token_json = st.session_state.creds.to_json()
|
126 |
+
token_file.write(token_json)
|
127 |
+
|
128 |
+
# If writing is successful, update the session state
|
129 |
+
st.session_state.authenticated = True
|
130 |
st.success("β
Authentication successful!")
|
131 |
except Exception as e:
|
132 |
+
# If any error occurs, ensure the authenticated flag is not set
|
133 |
+
st.session_state.authenticated = False
|
134 |
st.error(f"β Error during authentication: {e}")
|
135 |
|
136 |
# ===============================
|