diff --git a/app/main.py b/app/main.py
index c9bafe3..50bbe1a 100644
--- a/app/main.py
+++ b/app/main.py
@@ -1,7 +1,9 @@
from fastapi import FastAPI, Depends, Request
from fastapi.staticfiles import StaticFiles
-from fastapi.responses import HTMLResponse, JSONResponse
+from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
from starlette.middleware.sessions import SessionMiddleware
+from html import escape
+from urllib.parse import quote
import logging
import os
@@ -68,18 +70,66 @@ app.include_router(settings.router, prefix="/api/settings", tags=["settings"])
os.makedirs("static", exist_ok=True)
app.mount("/static", StaticFiles(directory="static"), name="static")
+MAIN_LOGIN_URL = os.getenv("MAIN_LOGIN_URL", "https://dbx.no1king.freeddns.org/login")
+
+
@app.get("/", response_class=HTMLResponse)
-async def read_root():
- # Return the main index.html file
+async def read_root(request: Request):
+ # 미인증 사용자는 dbx-main 의 로그인 페이지로 위임 (SSO 원칙).
+ # OMS 는 자체 로그인 UI 를 보여주지 않는다.
+ user_email = request.session.get("user_email")
+ if not user_email:
+ next_path = f"{APP_ROOT_PATH}/" if APP_ROOT_PATH else "/"
+ sep = "&" if "?" in MAIN_LOGIN_URL else "?"
+ target = f"{MAIN_LOGIN_URL}{sep}next={quote(next_path, safe='/')}"
+ return RedirectResponse(url=target, status_code=302)
+
+ user_name = request.session.get("user_name") or user_email
+ user_picture = request.session.get("user_picture", "") or ""
+
+ # 아바타: Google picture URL 이 있으면 , 없으면 폴백 아이콘
+ if user_picture:
+ avatar_html = (
+ f'
'
+ f''
+ )
+ else:
+ avatar_html = ''
+
if os.path.exists("static/index.html"):
with open("static/index.html", "r", encoding="utf-8") as f:
content = f.read()
- content = content.replace("__APP_BASE_PATH__", APP_ROOT_PATH)
- content = content.replace('src="/static/', f'src="{APP_ROOT_PATH}/static/' if APP_ROOT_PATH else 'src="/static/')
- content = content.replace('href="/static/', f'href="{APP_ROOT_PATH}/static/' if APP_ROOT_PATH else 'href="/static/')
- content = content.replace("window.location.href='/login", f"window.location.href='{APP_ROOT_PATH}/login")
- content = content.replace('window.location.href="/login', f'window.location.href="{APP_ROOT_PATH}/login')
- content = content.replace("window.location.href='/logout", f"window.location.href='{APP_ROOT_PATH}/logout")
- content = content.replace('window.location.href="/logout', f'window.location.href="{APP_ROOT_PATH}/logout')
- return HTMLResponse(content=content)
+ content = content.replace("__APP_BASE_PATH__", APP_ROOT_PATH)
+ content = content.replace(
+ 'src="/static/',
+ f'src="{APP_ROOT_PATH}/static/' if APP_ROOT_PATH else 'src="/static/',
+ )
+ content = content.replace(
+ 'href="/static/',
+ f'href="{APP_ROOT_PATH}/static/' if APP_ROOT_PATH else 'href="/static/',
+ )
+ content = content.replace(
+ "window.location.href='/login",
+ f"window.location.href='{APP_ROOT_PATH}/login",
+ )
+ content = content.replace(
+ 'window.location.href="/login',
+ f'window.location.href="{APP_ROOT_PATH}/login',
+ )
+ content = content.replace(
+ "window.location.href='/logout",
+ f"window.location.href='{APP_ROOT_PATH}/logout",
+ )
+ content = content.replace(
+ 'window.location.href="/logout',
+ f'window.location.href="{APP_ROOT_PATH}/logout',
+ )
+ # 사용자 정보 주입 (HTML 안의 placeholder 치환)
+ content = content.replace("__USER_NAME__", escape(user_name))
+ content = content.replace("__USER_EMAIL__", escape(user_email))
+ content = content.replace("__USER_AVATAR__", avatar_html)
+ return HTMLResponse(content=content)
return HTMLResponse(content="
Enter the corporate order management center.
- -Access restricted to approved users.
-