Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2573,7 +2573,7 @@ def process_single_ingredient(
|
|
| 2573 |
|
| 2574 |
|
| 2575 |
# ============================================================
|
| 2576 |
-
#
|
| 2577 |
# ============================================================
|
| 2578 |
|
| 2579 |
USER_DB_PATH = os.getenv("USER_DB_PATH", str(BASE_DIR / "users.db"))
|
|
@@ -2682,70 +2682,7 @@ def init_user_db():
|
|
| 2682 |
|
| 2683 |
|
| 2684 |
def create_signup_request(team, name, email, password, password_confirm):
|
| 2685 |
-
|
| 2686 |
-
|
| 2687 |
-
team = safe_str(team)
|
| 2688 |
-
name = safe_str(name)
|
| 2689 |
-
email = normalize_email(email)
|
| 2690 |
-
password = safe_str(password)
|
| 2691 |
-
password_confirm = safe_str(password_confirm)
|
| 2692 |
-
|
| 2693 |
-
if not team:
|
| 2694 |
-
return "โ ํ์ ์
๋ ฅํด์ฃผ์ธ์."
|
| 2695 |
-
if not name:
|
| 2696 |
-
return "โ ์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์."
|
| 2697 |
-
if not email or "@" not in email:
|
| 2698 |
-
return "โ ์ฌ๋ฐ๋ฅธ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
|
| 2699 |
-
if len(password) < 6:
|
| 2700 |
-
return "โ ๋น๋ฐ๋ฒํธ๋ 6์ ์ด์์ผ๋ก ์
๋ ฅํด์ฃผ์ธ์."
|
| 2701 |
-
if password != password_confirm:
|
| 2702 |
-
return "โ ๋น๋ฐ๋ฒํธ์ ๋น๋ฐ๋ฒํธ ํ์ธ์ด ์ผ์นํ์ง ์์ต๋๋ค."
|
| 2703 |
-
|
| 2704 |
-
conn = get_user_conn()
|
| 2705 |
-
cur = conn.cursor()
|
| 2706 |
-
|
| 2707 |
-
cur.execute("SELECT status FROM users WHERE email = ?", (email,))
|
| 2708 |
-
row = cur.fetchone()
|
| 2709 |
-
|
| 2710 |
-
if row:
|
| 2711 |
-
status = row["status"]
|
| 2712 |
-
|
| 2713 |
-
if status == "approved":
|
| 2714 |
-
conn.close()
|
| 2715 |
-
return "โ ์ด๋ฏธ ์น์ธ๋ ๊ณ์ ์
๋๋ค. ๋ก๊ทธ์ธํด์ฃผ์ธ์."
|
| 2716 |
-
if status == "pending":
|
| 2717 |
-
conn.close()
|
| 2718 |
-
return "โ ์ด๋ฏธ ๊ฐ์
์ ์ฒญ์ด ์ ์๋ ๊ณ์ ์
๋๋ค. ๊ด๋ฆฌ์ ์น์ธ์ ๊ธฐ๋ค๋ ค์ฃผ์ธ์."
|
| 2719 |
-
if status == "rejected":
|
| 2720 |
-
cur.execute(
|
| 2721 |
-
"""
|
| 2722 |
-
UPDATE users
|
| 2723 |
-
SET password_hash = ?, name = ?, team = ?, status = 'pending',
|
| 2724 |
-
created_at = ?, approved_at = NULL, approved_by = NULL,
|
| 2725 |
-
rejected_at = NULL, rejected_by = NULL
|
| 2726 |
-
WHERE email = ?
|
| 2727 |
-
""",
|
| 2728 |
-
(hash_password(password), name, team, now_iso(), email),
|
| 2729 |
-
)
|
| 2730 |
-
conn.commit()
|
| 2731 |
-
conn.close()
|
| 2732 |
-
return "โ
๊ฐ์
์ ์ฒญ์ด ๋ค์ ์ ์๋์์ต๋๋ค. ๊ด๋ฆฌ์ ์น์ธ ํ ์ด์ฉํ ์ ์์ต๋๋ค."
|
| 2733 |
-
|
| 2734 |
-
cur.execute(
|
| 2735 |
-
"""
|
| 2736 |
-
INSERT INTO users (
|
| 2737 |
-
email, password_hash, name, team, status, role, created_at
|
| 2738 |
-
)
|
| 2739 |
-
VALUES (?, ?, ?, ?, 'pending', 'user', ?)
|
| 2740 |
-
""",
|
| 2741 |
-
(email, hash_password(password), name, team, now_iso()),
|
| 2742 |
-
)
|
| 2743 |
-
|
| 2744 |
-
conn.commit()
|
| 2745 |
-
conn.close()
|
| 2746 |
-
|
| 2747 |
-
return "โ
๊ฐ์
์ ์ฒญ์ด ์๋ฃ๋์์ต๋๋ค. ๊ด๋ฆฌ์ ์น์ธ ํ ์ด์ฉํ ์ ์์ต๋๋ค."
|
| 2748 |
-
|
| 2749 |
|
| 2750 |
def login_user(email, password):
|
| 2751 |
init_user_db()
|
|
@@ -2809,7 +2746,7 @@ def is_admin_user(user):
|
|
| 2809 |
def require_login_message():
|
| 2810 |
return (
|
| 2811 |
"โ ๋ก๊ทธ์ธ ํ ์ด์ฉํ ์ ์์ต๋๋ค.\n"
|
| 2812 |
-
"-
|
| 2813 |
"- ์น์ธ๋ ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํด์ฃผ์ธ์."
|
| 2814 |
)
|
| 2815 |
|
|
@@ -3201,6 +3138,47 @@ def process_single_ingredient_with_auth(user, countries, single_query, single_am
|
|
| 3201 |
)
|
| 3202 |
|
| 3203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3204 |
with gr.Blocks(css=custom_css) as demo:
|
| 3205 |
current_user = gr.State({})
|
| 3206 |
session_user_json = gr.Textbox(visible=False, elem_id="rebom_session_user_json")
|
|
@@ -3375,8 +3353,8 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 3375 |
logout_btn = gr.Button("๋ก๊ทธ์์", variant="secondary")
|
| 3376 |
login_status = gr.Textbox(label="๋ก๊ทธ์ธ ์ํ", interactive=False, lines=3)
|
| 3377 |
|
| 3378 |
-
with gr.Tab("๐
|
| 3379 |
-
gr.Markdown("## ๐
|
| 3380 |
gr.Markdown("ํ, ์ด๋ฆ, ๋ฉ์ผ ์ฃผ์, ๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํ๋ฉด ๊ด๋ฆฌ์ ์น์ธ ํ ์ฌ์ดํธ ์ด์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.")
|
| 3381 |
|
| 3382 |
signup_team = gr.Textbox(label="ํ", placeholder="์: ์ ๋ต์ ํ์ฐ๊ตฌํ")
|
|
@@ -3384,7 +3362,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 3384 |
signup_email = gr.Textbox(label="๋ฉ์ผ ์ฃผ์", placeholder="example@rebom.kr")
|
| 3385 |
signup_password = gr.Textbox(label="๋น๋ฐ๋ฒํธ", type="password")
|
| 3386 |
signup_password_confirm = gr.Textbox(label="๋น๋ฐ๋ฒํธ ํ์ธ", type="password")
|
| 3387 |
-
signup_btn = gr.Button("
|
| 3388 |
signup_status = gr.Textbox(label="์ ์ฒญ ์ํ", interactive=False, lines=3)
|
| 3389 |
|
| 3390 |
signup_btn.click(
|
|
|
|
| 2573 |
|
| 2574 |
|
| 2575 |
# ============================================================
|
| 2576 |
+
# ๊ณ์ ๋ฑ๋ก์ ๊ด๋ฆฌ์์๊ฒ ์์ฒญ / ๊ด๋ฆฌ์ ์น์ธ / ๋ก๊ทธ์ธ
|
| 2577 |
# ============================================================
|
| 2578 |
|
| 2579 |
USER_DB_PATH = os.getenv("USER_DB_PATH", str(BASE_DIR / "users.db"))
|
|
|
|
| 2682 |
|
| 2683 |
|
| 2684 |
def create_signup_request(team, name, email, password, password_confirm):
|
| 2685 |
+
return "โน๏ธ ํ์๊ฐ์
๊ธฐ๋ฅ์ ์ฌ์ฉํ์ง ์์ต๋๋ค. ๊ด๋ฆฌ์๊ฐ app.py์ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋กํฉ๋๋ค."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2686 |
|
| 2687 |
def login_user(email, password):
|
| 2688 |
init_user_db()
|
|
|
|
| 2746 |
def require_login_message():
|
| 2747 |
return (
|
| 2748 |
"โ ๋ก๊ทธ์ธ ํ ์ด์ฉํ ์ ์์ต๋๋ค.\n"
|
| 2749 |
+
"- ๊ณ์ ๋ฑ๋ก์ ๊ด๋ฆฌ์์๊ฒ ์์ฒญ ํ ๊ด๋ฆฌ์๊ฐ ์น์ธํด์ผ ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.\n"
|
| 2750 |
"- ์น์ธ๋ ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํด์ฃผ์ธ์."
|
| 2751 |
)
|
| 2752 |
|
|
|
|
| 3138 |
)
|
| 3139 |
|
| 3140 |
|
| 3141 |
+
|
| 3142 |
+
# ============================================================
|
| 3143 |
+
# ๋ก๊ทธ์ธ ์ธ์ฆ
|
| 3144 |
+
# - Gradio ๊ธฐ๋ณธ ๋ก๊ทธ์ธ์ฐฝ ์ฌ์ฉ
|
| 3145 |
+
# - ์๋ USER_DB์ ๋ฉ์ผ/๋น๋ฐ๋ฒํธ๋ฅผ ์ง์ ๋ฑ๋ก
|
| 3146 |
+
# ============================================================
|
| 3147 |
+
# ์ฌ์ฉ์ ์ถ๊ฐ ๋ฐฉ๋ฒ:
|
| 3148 |
+
# USER_DB ์์ ์๋ ํ์์ผ๋ก ํ ์ค์ฉ ์ถ๊ฐํ์ธ์.
|
| 3149 |
+
# "๋ฉ์ผ์ฃผ์": "๋น๋ฐ๋ฒํธ",
|
| 3150 |
+
# ============================================================
|
| 3151 |
+
|
| 3152 |
+
USER_DB = {
|
| 3153 |
+
"jin2li@rebom.kr": "qwer0515!",
|
| 3154 |
+
|
| 3155 |
+
# ์ฌ์ฉ์ ๋ฑ๋ก ์์:
|
| 3156 |
+
# "yubin.p@rebom.kr": "123456!",
|
| 3157 |
+
# "jkh@rebom.kr": "rebom123!",
|
| 3158 |
+
}
|
| 3159 |
+
|
| 3160 |
+
|
| 3161 |
+
def auth_fn(username, password):
|
| 3162 |
+
username = str(username).strip().lower()
|
| 3163 |
+
password = str(password).strip()
|
| 3164 |
+
return USER_DB.get(username) == password
|
| 3165 |
+
|
| 3166 |
+
|
| 3167 |
+
# Gradio ๊ธฐ๋ณธ auth๋ฅผ ํต๊ณผํ ์ฌ์ฉ์๋ ์ด๋ฏธ ์ธ์ฆ๋ ์ํ์ด๋ฏ๋ก ๋ด๋ถ ๋ก๊ทธ์ธ ์ฒดํฌ๋ฅผ ํ์ง ์๋๋ค.
|
| 3168 |
+
def process_with_auth(user, countries, file, product_name="", use_mfds_live=False, live_max_terms=30, live_headless=True):
|
| 3169 |
+
return process(countries, file, product_name, use_mfds_live, live_max_terms, live_headless)
|
| 3170 |
+
|
| 3171 |
+
|
| 3172 |
+
def process_single_ingredient_with_auth(user, countries, single_query, single_amount, single_function, single_use_mfds_live=False):
|
| 3173 |
+
return process_single_ingredient(
|
| 3174 |
+
countries,
|
| 3175 |
+
single_query,
|
| 3176 |
+
single_amount,
|
| 3177 |
+
single_function,
|
| 3178 |
+
single_use_mfds_live,
|
| 3179 |
+
)
|
| 3180 |
+
|
| 3181 |
+
|
| 3182 |
with gr.Blocks(css=custom_css) as demo:
|
| 3183 |
current_user = gr.State({})
|
| 3184 |
session_user_json = gr.Textbox(visible=False, elem_id="rebom_session_user_json")
|
|
|
|
| 3353 |
logout_btn = gr.Button("๋ก๊ทธ์์", variant="secondary")
|
| 3354 |
login_status = gr.Textbox(label="๋ก๊ทธ์ธ ์ํ", interactive=False, lines=3)
|
| 3355 |
|
| 3356 |
+
with gr.Tab("๐ ๊ณ์ ๋ฑ๋ก์ ๊ด๋ฆฌ์์๊ฒ ์์ฒญ", visible=False):
|
| 3357 |
+
gr.Markdown("## ๐ ๊ณ์ ๋ฑ๋ก์ ๊ด๋ฆฌ์์๊ฒ ์์ฒญ")
|
| 3358 |
gr.Markdown("ํ, ์ด๋ฆ, ๋ฉ์ผ ์ฃผ์, ๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํ๋ฉด ๊ด๋ฆฌ์ ์น์ธ ํ ์ฌ์ดํธ ์ด์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค.")
|
| 3359 |
|
| 3360 |
signup_team = gr.Textbox(label="ํ", placeholder="์: ์ ๋ต์ ํ์ฐ๊ตฌํ")
|
|
|
|
| 3362 |
signup_email = gr.Textbox(label="๋ฉ์ผ ์ฃผ์", placeholder="example@rebom.kr")
|
| 3363 |
signup_password = gr.Textbox(label="๋น๋ฐ๋ฒํธ", type="password")
|
| 3364 |
signup_password_confirm = gr.Textbox(label="๋น๋ฐ๋ฒํธ ํ์ธ", type="password")
|
| 3365 |
+
signup_btn = gr.Button("๊ณ์ ๋ฑ๋ก์ ๊ด๋ฆฌ์์๊ฒ ์์ฒญ", variant="primary")
|
| 3366 |
signup_status = gr.Textbox(label="์ ์ฒญ ์ํ", interactive=False, lines=3)
|
| 3367 |
|
| 3368 |
signup_btn.click(
|