Fix login
Browse files
app.py
CHANGED
|
@@ -28,6 +28,8 @@ agent_name = os.getenv('agent_name')
|
|
| 28 |
app_id = os.getenv('app_id')
|
| 29 |
login_status_key = os.getenv('login_status_key')
|
| 30 |
login_info_key = os.getenv('login_info_key')
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
def parse_response(response):
|
|
@@ -223,14 +225,17 @@ def load_description(file_path):
|
|
| 223 |
|
| 224 |
|
| 225 |
def check_login_status(headers):
|
| 226 |
-
print(f"headers={headers}")
|
| 227 |
if not headers:
|
| 228 |
return None, None
|
| 229 |
|
| 230 |
try:
|
|
|
|
| 231 |
text = headers.get(login_status_key)
|
| 232 |
if not text or "." not in text:
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
infos = text.split(".")
|
| 236 |
if len(infos) < 2:
|
|
@@ -244,15 +249,20 @@ def check_login_status(headers):
|
|
| 244 |
decoded_bytes = base64.b64decode(info)
|
| 245 |
decoded_str = decoded_bytes.decode('utf-8')
|
| 246 |
datas = json.loads(decoded_str)
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
return None, None
|
| 251 |
|
| 252 |
-
user_id = data.get("_id")
|
| 253 |
-
user_name = data.get("user")
|
| 254 |
-
return user_id, user_name
|
| 255 |
-
|
| 256 |
except Exception as e:
|
| 257 |
print(f"An error occurred: {repr(e)}")
|
| 258 |
return None, None
|
|
@@ -261,16 +271,13 @@ def check_login_status(headers):
|
|
| 261 |
def generate_image(main_image, background_image, did, request: gr.Request):
|
| 262 |
if not did:
|
| 263 |
did = str(uuid.uuid4())
|
| 264 |
-
print(f"request.request.__dict__={request.request.__dict__}")
|
| 265 |
-
print(f"request.request.cookies={request.request.cookies}")
|
| 266 |
-
print(f"request.request.scope={request.request.scope }")
|
| 267 |
-
print(f"request.request._cookies ={request.request._cookies}")
|
| 268 |
-
print(f"request.username={request.username}")
|
| 269 |
-
print(f"request.session_hash={request.session_hash}")
|
| 270 |
user_id, user_name = check_login_status(request.request.headers)
|
|
|
|
|
|
|
| 271 |
if not user_id or not user_name:
|
| 272 |
m = "Please log in to your Hugging Face account to use the features of this application."
|
| 273 |
return gr.Warning(m), did
|
|
|
|
| 274 |
if main_image is None or background_image is None:
|
| 275 |
m = "Please upload both the main image and the background reference image before generating."
|
| 276 |
return gr.Warning(m), did
|
|
|
|
| 28 |
app_id = os.getenv('app_id')
|
| 29 |
login_status_key = os.getenv('login_status_key')
|
| 30 |
login_info_key = os.getenv('login_info_key')
|
| 31 |
+
login_status_key2 = os.getenv('login_status_key2')
|
| 32 |
+
login_mark_key = os.getenv('login_mark_key')
|
| 33 |
|
| 34 |
|
| 35 |
def parse_response(response):
|
|
|
|
| 225 |
|
| 226 |
|
| 227 |
def check_login_status(headers):
|
|
|
|
| 228 |
if not headers:
|
| 229 |
return None, None
|
| 230 |
|
| 231 |
try:
|
| 232 |
+
login_status = 1
|
| 233 |
text = headers.get(login_status_key)
|
| 234 |
if not text or "." not in text:
|
| 235 |
+
text = headers.get(login_status_key2)
|
| 236 |
+
login_status = 2
|
| 237 |
+
if not text or "." not in text:
|
| 238 |
+
return None, None
|
| 239 |
|
| 240 |
infos = text.split(".")
|
| 241 |
if len(infos) < 2:
|
|
|
|
| 249 |
decoded_bytes = base64.b64decode(info)
|
| 250 |
decoded_str = decoded_bytes.decode('utf-8')
|
| 251 |
datas = json.loads(decoded_str)
|
| 252 |
+
if login_status == 1:
|
| 253 |
+
data = datas.get(login_info_key)
|
| 254 |
+
if not data:
|
| 255 |
+
return None, None
|
| 256 |
+
user_id = data.get("_id")
|
| 257 |
+
user_name = data.get("user")
|
| 258 |
+
return user_id, user_name
|
| 259 |
+
elif login_status == 2:
|
| 260 |
+
user_id = datas.get("uuid")
|
| 261 |
+
user_name = datas.get("user")
|
| 262 |
+
return user_id, user_name
|
| 263 |
+
else:
|
| 264 |
return None, None
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
except Exception as e:
|
| 267 |
print(f"An error occurred: {repr(e)}")
|
| 268 |
return None, None
|
|
|
|
| 271 |
def generate_image(main_image, background_image, did, request: gr.Request):
|
| 272 |
if not did:
|
| 273 |
did = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
user_id, user_name = check_login_status(request.request.headers)
|
| 275 |
+
print(f"user_id = {user_id}")
|
| 276 |
+
print(f"user_name = {user_name}")
|
| 277 |
if not user_id or not user_name:
|
| 278 |
m = "Please log in to your Hugging Face account to use the features of this application."
|
| 279 |
return gr.Warning(m), did
|
| 280 |
+
user_id = f"{login_mark_key}{user_id}"
|
| 281 |
if main_image is None or background_image is None:
|
| 282 |
m = "Please upload both the main image and the background reference image before generating."
|
| 283 |
return gr.Warning(m), did
|