feat: 댓글 신고·차단·약관 동의(관리 스크립트 포함), 구글 로그인(서버·웹·안드로이드 앱), 앱 패키지 kr.o2o.nalssigak·versionCode 1000
This commit is contained in:
1 parent
fbebdcb796
commit
3f3a3ea039
35 files changed
+1723
-115
No files matched your search
@@ -322,6 +322,7 @@ class User(Base):
|
||||
color: Mapped[str] = mapped_column(String(20), default="orange")
|
||||
mood: Mapped[Optional[str]] = mapped_column(String(20), nullable=True)
|
||||
status: Mapped[int] = mapped_column(SmallInteger, default=1)
|
||||
terms_agreed_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
token_version: Mapped[int] = mapped_column(SmallInteger, default=1)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
@@ -352,10 +353,29 @@ class Comment(Base):
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True))
|
||||
body: Mapped[str] = mapped_column(String(60))
|
||||
like_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
report_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
is_hidden: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
deleted: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
|
||||
class CommentReport(Base):
|
||||
__tablename__ = "comment_report"
|
||||
|
||||
comment_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True)
|
||||
reason: Mapped[int] = mapped_column(SmallInteger)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class UserBlock(Base):
|
||||
__tablename__ = "user_block"
|
||||
|
||||
user_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True)
|
||||
blocked_id: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), primary_key=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
|
||||
class CommentLike(Base):
|
||||
__tablename__ = "comment_like"
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ class ErrorType(Enum):
|
||||
AUTH_FAILED = 4002
|
||||
AUTH_DUPLICATE_ID = 4003
|
||||
AUTH_TOKEN_INVALID = 4004
|
||||
TERMS_REQUIRED = 4005
|
||||
|
||||
|
||||
class Sky(CodeEnum):
|
||||
@@ -159,3 +160,10 @@ class RefType(CodeEnum):
|
||||
class AuthProvider(CodeEnum):
|
||||
LOCAL = 1
|
||||
GOOGLE = 2
|
||||
|
||||
|
||||
class ReportReason(CodeEnum):
|
||||
ABUSE = 1
|
||||
AD = 2
|
||||
PRIVACY = 3
|
||||
OTHER = 4
|
||||
@@ -0,0 +1,43 @@
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
import httpx
|
||||
from jose import JWTError, jwt
|
||||
|
||||
from common.logger import LOG
|
||||
from config.settings import settings
|
||||
|
||||
CERTS_URL = "https://www.googleapis.com/oauth2/v3/certs"
|
||||
ISSUERS = ("accounts.google.com", "https://accounts.google.com")
|
||||
_CERTS_TTL = 3600
|
||||
_certs: dict = {"keys": [], "at": 0.0}
|
||||
|
||||
|
||||
async def _keys(force: bool = False) -> list[dict]:
|
||||
"""구글 서명 공개키. 한 시간 캐시하고, 모르는 키가 오면 한 번 다시 받는다."""
|
||||
if force or not _certs["keys"] or time.monotonic() - _certs["at"] > _CERTS_TTL:
|
||||
async with httpx.AsyncClient(timeout=5) as c:
|
||||
res = await c.get(CERTS_URL)
|
||||
res.raise_for_status()
|
||||
_certs["keys"], _certs["at"] = res.json()["keys"], time.monotonic()
|
||||
return _certs["keys"]
|
||||
|
||||
|
||||
async def verify(credential: str) -> Optional[str]:
|
||||
"""구글 로그인 버튼이 준 ID 토큰을 확인하고 구글 사용자 고유 번호(sub)를 돌려준다. 서명·발급처·우리 클라이언트 ID·만료가 하나라도 안 맞으면 None."""
|
||||
if not settings.google_client_id:
|
||||
LOG.error("[google] GOOGLE_CLIENT_ID is empty")
|
||||
return None
|
||||
try:
|
||||
kid = jwt.get_unverified_header(credential).get("kid")
|
||||
keys = await _keys()
|
||||
key = next((k for k in keys if k.get("kid") == kid), None) or next((k for k in await _keys(force=True) if k.get("kid") == kid), None)
|
||||
if key is None:
|
||||
return None
|
||||
claims = jwt.decode(credential, key, algorithms=["RS256"], audience=settings.google_client_id, options={"verify_at_hash": False})
|
||||
except (JWTError, httpx.HTTPError, KeyError, ValueError) as e:
|
||||
LOG.warning("[google] id token rejected: %s", type(e).__name__)
|
||||
return None
|
||||
if claims.get("iss") not in ISSUERS or not claims.get("sub"):
|
||||
return None
|
||||
return str(claims["sub"])
|
||||
Reference in new issue
Block a user