Merge remote-tracking branch 'origin/main' into feat/apps-in-toss
# Conflicts: # TODO.md # backend/crud/user_crud.py # backend/router/v1/auth/account.py # backend/router/v1/auth/protocol.py # backend/services/auth_service.py # compose.yaml # docs/이벤트_추적.md # frontend/src/api/client/@tanstack/react-query.gen.ts # frontend/src/api/client/index.ts # frontend/src/api/client/sdk.gen.ts # frontend/src/api/client/types.gen.ts # frontend/src/b/Sheets.tsx # frontend/src/b/region.tsx # frontend/src/lib/analytics.ts
This commit is contained in:
commit
84212099e6
285 files changed
+39026
-767
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
import secrets
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
@@ -6,6 +7,7 @@ from fastapi import Depends
|
||||
|
||||
from common.auth import PASSWORD_MAX_BYTES, decode, hash_password, issue_tokens, verify_password
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.google_id import verify as verify_google
|
||||
from common.database.model.models import User
|
||||
from common.enums import AuthProvider, ErrorType
|
||||
from common.logger import LOG
|
||||
@@ -22,6 +24,15 @@ MOODS = ("clear", "partly", "cloudy", "rain", "thunder", "snow", "fog", "rainbow
|
||||
TOSS_REFERRERS = ("DEFAULT", "SANDBOX")
|
||||
|
||||
|
||||
_NICK_WORDS = ("맑은", "포근한", "산들", "반짝", "느긋한", "보슬", "선선한", "따끈한")
|
||||
_NICK_ANIMALS = {"rabbit": "토끼", "bear": "곰", "dog": "강아지", "sun": "해님", "moon": "달님", "cloud": "구름"}
|
||||
|
||||
|
||||
def auto_nickname() -> str:
|
||||
"""구글로 처음 들어온 사람의 이름: 맑은토끼 482. 내 정보에서 바꿀 수 있다."""
|
||||
return f"{secrets.choice(_NICK_WORDS)}{secrets.choice(list(_NICK_ANIMALS.values()))} {secrets.randbelow(900) + 100}"
|
||||
|
||||
|
||||
class AuthService:
|
||||
def __init__(self, crud: UserCRUD = Depends(UserCRUD)) -> None:
|
||||
self.crud = crud
|
||||
@@ -76,6 +87,26 @@ class AuthService:
|
||||
return ErrorType.AUTH_FAILED, None
|
||||
return ErrorType.SUCCESS, user
|
||||
|
||||
async def google(self, credential: str) -> tuple[ErrorType, Optional[User]]:
|
||||
"""구글 ID 토큰으로 로그인. 처음이면 자동 닉네임으로 계정을 만든다. 구글 이름·이메일은 저장하지 않는다."""
|
||||
sub = await verify_google(credential)
|
||||
if sub is None:
|
||||
return ErrorType.AUTH_FAILED, None
|
||||
login_id = f"google_{sub}"
|
||||
err, user = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.by_login_id(s, login_id))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
return err, None
|
||||
if user is None:
|
||||
err, user = await DB_SESSION_MNG.execute_lambda_write(lambda s: self.crud.create_google(s, sub, auto_nickname()))
|
||||
if err is not ErrorType.SUCCESS:
|
||||
# 같은 계정이 동시에 처음 들어온 경우엔 먼저 만들어진 쪽을 쓴다
|
||||
err, user = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.by_login_id(s, login_id))
|
||||
if err is not ErrorType.SUCCESS or user is None:
|
||||
return ErrorType.DB_ERROR, None
|
||||
if user.status != 1:
|
||||
return ErrorType.AUTH_FAILED, None
|
||||
return ErrorType.SUCCESS, user
|
||||
|
||||
async def toss_unlink(self, user_key: str) -> ErrorType:
|
||||
"""토스에서 연결을 끊으면 그 계정의 모든 토큰을 무효로 만든다. 계정이 없어도 성공으로 본다."""
|
||||
err, user = await DB_SESSION_MNG.execute_lambda(lambda s: self.crud.by_provider_uid(s, AuthProvider.TOSS.value, user_key))
|
||||
|
||||
Reference in new issue
Block a user