Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2584,71 +2584,6 @@ DEFAULT_ADMIN_EMAIL = os.getenv("ADMIN_EMAIL", "jin2li@rebom.kr").strip().lower(
|
|
| 2584 |
DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
| 2585 |
|
| 2586 |
|
| 2587 |
-
def now_iso():
|
| 2588 |
-
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 2589 |
-
|
| 2590 |
-
|
| 2591 |
-
def normalize_email(email):
|
| 2592 |
-
return safe_str(email).lower()
|
| 2593 |
-
|
| 2594 |
-
|
| 2595 |
-
def hash_password(password):
|
| 2596 |
-
password = safe_str(password)
|
| 2597 |
-
salt = secrets.token_hex(16)
|
| 2598 |
-
digest = hashlib.pbkdf2_hmac(
|
| 2599 |
-
"sha256",
|
| 2600 |
-
password.encode("utf-8"),
|
| 2601 |
-
salt.encode("utf-8"),
|
| 2602 |
-
120000,
|
| 2603 |
-
).hex()
|
| 2604 |
-
return f"{salt}${digest}"
|
| 2605 |
-
|
| 2606 |
-
|
| 2607 |
-
def verify_password(password, stored_hash):
|
| 2608 |
-
password = safe_str(password)
|
| 2609 |
-
stored_hash = safe_str(stored_hash)
|
| 2610 |
-
|
| 2611 |
-
try:
|
| 2612 |
-
salt, digest = stored_hash.split("$", 1)
|
| 2613 |
-
except Exception:
|
| 2614 |
-
return False
|
| 2615 |
-
|
| 2616 |
-
check = hashlib.pbkdf2_hmac(
|
| 2617 |
-
"sha256",
|
| 2618 |
-
password.encode("utf-8"),
|
| 2619 |
-
salt.encode("utf-8"),
|
| 2620 |
-
120000,
|
| 2621 |
-
).hex()
|
| 2622 |
-
|
| 2623 |
-
return secrets.compare_digest(check, digest)
|
| 2624 |
-
|
| 2625 |
-
|
| 2626 |
-
def logout_user():
|
| 2627 |
-
return {}, "๐ช ๋ก๊ทธ์์๋์์ต๋๋ค."
|
| 2628 |
-
|
| 2629 |
-
|
| 2630 |
-
def is_approved_user(user):
|
| 2631 |
-
return isinstance(user, dict) and user.get("status") == "approved" and safe_str(user.get("email"))
|
| 2632 |
-
|
| 2633 |
-
|
| 2634 |
-
def is_admin_user(user):
|
| 2635 |
-
if not is_approved_user(user):
|
| 2636 |
-
return False
|
| 2637 |
-
|
| 2638 |
-
email = normalize_email(user.get("email", ""))
|
| 2639 |
-
role = safe_str(user.get("role", ""))
|
| 2640 |
-
|
| 2641 |
-
return role == "admin" or email in ADMIN_EMAILS
|
| 2642 |
-
|
| 2643 |
-
|
| 2644 |
-
def require_login_message():
|
| 2645 |
-
return (
|
| 2646 |
-
"โ ๋ก๊ทธ์ธ ํ ์ด์ฉํ ์ ์์ต๋๋ค.\n"
|
| 2647 |
-
"- ๊ณ์ ๋ฑ๋ก์ ๊ด๋ฆฌ์์๊ฒ ์์ฒญ ํ ๊ด๋ฆฌ์๊ฐ ์น์ธํด์ผ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.\n"
|
| 2648 |
-
"- ์น์ธ๋ ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํด์ฃผ์ธ์."
|
| 2649 |
-
)
|
| 2650 |
-
|
| 2651 |
-
|
| 2652 |
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 2653 |
if not is_approved_user(user):
|
| 2654 |
return None, None, require_login_message()
|
|
@@ -2671,27 +2606,6 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 2671 |
)
|
| 2672 |
|
| 2673 |
|
| 2674 |
-
def pick_user_email_from_table(evt):
|
| 2675 |
-
"""
|
| 2676 |
-
ํ์ ๋ชฉ๋ก ํ์์ ํ์ ํด๋ฆญํ๋ฉด ํด๋น ํ์ email์ ์น์ธ/๊ฑฐ์ /์ญ์ ์
๋ ฅ์นธ์ ์๋ ์
๋ ฅํ๋ค.
|
| 2677 |
-
"""
|
| 2678 |
-
try:
|
| 2679 |
-
row = evt.value
|
| 2680 |
-
|
| 2681 |
-
if isinstance(row, dict):
|
| 2682 |
-
return safe_str(row.get("email", ""))
|
| 2683 |
-
|
| 2684 |
-
if isinstance(row, list) and row:
|
| 2685 |
-
return safe_str(row[0])
|
| 2686 |
-
|
| 2687 |
-
if isinstance(row, tuple) and row:
|
| 2688 |
-
return safe_str(row[0])
|
| 2689 |
-
except Exception:
|
| 2690 |
-
pass
|
| 2691 |
-
|
| 2692 |
-
return ""
|
| 2693 |
-
|
| 2694 |
-
|
| 2695 |
def auth_fn(username, password):
|
| 2696 |
username = str(username).strip().lower()
|
| 2697 |
password = str(password).strip()
|
|
@@ -2727,12 +2641,11 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 2727 |
|
| 2728 |
USER_DB = {
|
| 2729 |
"jin2li@rebom.kr": "qwer0515!",
|
| 2730 |
-
"jkh@rebom.kr": "rebom123!"
|
| 2731 |
-
"admin" : "rebom123!"
|
| 2732 |
|
| 2733 |
# ์ฌ์ฉ์ ์ถ๊ฐ ์์:
|
| 2734 |
# "yubin.p@rebom.kr": "์ํ๋๋น๋ฐ๋ฒํธ",
|
| 2735 |
-
|
|
|
|
| 2736 |
|
| 2737 |
|
| 2738 |
def auth_fn(username, password):
|
|
@@ -2873,14 +2786,25 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 2873 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 2874 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 2875 |
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2876 |
# ============================================================
|
| 2877 |
|
| 2878 |
USER_DB = {
|
| 2879 |
"jin2li@rebom.kr": "qwer0515!",
|
|
|
|
|
|
|
| 2880 |
|
| 2881 |
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 2882 |
# "yubin.p@rebom.kr": "123456!",
|
| 2883 |
-
# "jkh@rebom.kr": "rebom123!",
|
| 2884 |
}
|
| 2885 |
|
| 2886 |
|
|
@@ -3040,53 +2964,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 3040 |
inputs=[current_user,single_country,single_query,single_amount,single_function,single_use_mfds_live],
|
| 3041 |
outputs=[single_df_out,single_msg_out],
|
| 3042 |
)
|
| 3043 |
-
|
| 3044 |
-
|
| 3045 |
-
user_filter = gr.Dropdown(
|
| 3046 |
-
choices=["pending", "approved", "rejected", "์ ์ฒด"],
|
| 3047 |
-
value="pending",
|
| 3048 |
-
label="์กฐํ ์ํ",
|
| 3049 |
-
)
|
| 3050 |
-
load_users_btn = gr.Button("ํ์ ๋ชฉ๋ก ์กฐํ", variant="secondary")
|
| 3051 |
-
users_table = gr.Dataframe(label="ํ์ ๋ชฉ๋ก", interactive=False, wrap=True)
|
| 3052 |
-
target_email = gr.Textbox(label="์ ํํ ํ์ ๋ฉ์ผ ์ฃผ์", placeholder="ํ์ ๋ชฉ๋ก์์ ํ์ ํด๋ฆญํ๊ฑฐ๋ ๋ฉ์ผ ์ฃผ์๋ฅผ ์ง์ ์
๋ ฅ")
|
| 3053 |
-
|
| 3054 |
-
with gr.Row():
|
| 3055 |
-
delete_btn = gr.Button("์ญ์ ", variant="stop")
|
| 3056 |
-
|
| 3057 |
-
admin_status = gr.Textbox(label="๊ด๋ฆฌ์ ์ฒ๋ฆฌ ์ํ", interactive=False, lines=4)
|
| 3058 |
-
|
| 3059 |
-
load_users_btn.click(
|
| 3060 |
-
fn=admin_load_users,
|
| 3061 |
-
inputs=[current_user, user_filter],
|
| 3062 |
-
outputs=[users_table, admin_status],
|
| 3063 |
-
)
|
| 3064 |
-
|
| 3065 |
-
|
| 3066 |
-
users_table.select(
|
| 3067 |
-
fn=pick_user_email_from_table,
|
| 3068 |
-
inputs=[],
|
| 3069 |
-
outputs=target_email,
|
| 3070 |
-
)
|
| 3071 |
-
|
| 3072 |
-
approve_btn.click(
|
| 3073 |
-
fn=admin_approve_user,
|
| 3074 |
-
inputs=[current_user, target_email],
|
| 3075 |
-
outputs=[users_table, admin_status],
|
| 3076 |
-
)
|
| 3077 |
-
|
| 3078 |
-
reject_btn.click(
|
| 3079 |
-
fn=admin_reject_user,
|
| 3080 |
-
inputs=[current_user, target_email],
|
| 3081 |
-
outputs=[users_table, admin_status],
|
| 3082 |
-
)
|
| 3083 |
-
|
| 3084 |
-
|
| 3085 |
-
delete_btn.click(
|
| 3086 |
-
fn=admin_delete_user,
|
| 3087 |
-
inputs=[current_user, target_email],
|
| 3088 |
-
outputs=[users_table, admin_status],
|
| 3089 |
-
)
|
| 3090 |
try:
|
| 3091 |
demo.launch(
|
| 3092 |
auth=auth_fn,
|
|
|
|
| 2584 |
DEFAULT_ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "qwer0515!")
|
| 2585 |
|
| 2586 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2587 |
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 2588 |
if not is_approved_user(user):
|
| 2589 |
return None, None, require_login_message()
|
|
|
|
| 2606 |
)
|
| 2607 |
|
| 2608 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2609 |
def auth_fn(username, password):
|
| 2610 |
username = str(username).strip().lower()
|
| 2611 |
password = str(password).strip()
|
|
|
|
| 2641 |
|
| 2642 |
USER_DB = {
|
| 2643 |
"jin2li@rebom.kr": "qwer0515!",
|
|
|
|
|
|
|
| 2644 |
|
| 2645 |
# ์ฌ์ฉ์ ์ถ๊ฐ ์์:
|
| 2646 |
# "yubin.p@rebom.kr": "์ํ๋๋น๋ฐ๋ฒํธ",
|
| 2647 |
+
# "jkh@rebom.kr": "rebom123!",
|
| 2648 |
+
}
|
| 2649 |
|
| 2650 |
|
| 2651 |
def auth_fn(username, password):
|
|
|
|
| 2786 |
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 2787 |
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 2788 |
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 2789 |
+
|
| 2790 |
+
|
| 2791 |
+
# ============================================================
|
| 2792 |
+
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 2793 |
+
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 2794 |
+
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 2795 |
+
# ============================================================
|
| 2796 |
+
# ์ฌ์ฉ์ ์ถ๊ฐ ๋ฐฉ๋ฒ:
|
| 2797 |
+
# USER_DB ์์ "์์ด๋": "๋น๋ฐ๋ฒํธ", ํ์์ผ๋ก ํ ์ค์ฉ ์ถ๊ฐํ์ธ์.
|
| 2798 |
+
# ๊ฐ ์ค ๋์๋ ์ฝค๋ง(,)๋ฅผ ๋ถ์ด๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
|
| 2799 |
# ============================================================
|
| 2800 |
|
| 2801 |
USER_DB = {
|
| 2802 |
"jin2li@rebom.kr": "qwer0515!",
|
| 2803 |
+
"jkh@rebom.kr": "rebom123!",
|
| 2804 |
+
"admin": "rebom123!",
|
| 2805 |
|
| 2806 |
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 2807 |
# "yubin.p@rebom.kr": "123456!",
|
|
|
|
| 2808 |
}
|
| 2809 |
|
| 2810 |
|
|
|
|
| 2964 |
inputs=[current_user,single_country,single_query,single_amount,single_function,single_use_mfds_live],
|
| 2965 |
outputs=[single_df_out,single_msg_out],
|
| 2966 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2967 |
try:
|
| 2968 |
demo.launch(
|
| 2969 |
auth=auth_fn,
|