Skip to content

Commit

Permalink
Merge pull request #48 from wafflestudio/user_link
Browse files Browse the repository at this point in the history
User link
  • Loading branch information
odumag99 authored Jan 30, 2025
2 parents 3314a65 + ed76982 commit 7a900e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions snuvote/app/user/dto/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ class UserInfoResponse(BaseModel):
userid: str
email: str
college: int
is_naver_user: bool
is_kakao_user: bool

@staticmethod
def from_user(user: User) -> "UserInfoResponse":
def from_user(user: User) -> "UserInfoResponse":
return UserInfoResponse(
name = user.name,
userid = user.userid,
email = user.email,
college = user.college
college = user.college,
is_naver_user = user.naver_user != None,
is_kakao_user = user.kakao_user != None
)
11 changes: 11 additions & 0 deletions snuvote/app/user/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from snuvote.app.user.store import UserStore
from snuvote.app.user.errors import InvalidUsernameOrPasswordError, NotAccessTokenError, NotRefreshTokenError, InvalidTokenError, ExpiredTokenError, BlockedRefreshTokenError, InvalidPasswordError, NaverApiError, InvalidNaverTokenError, KakaoApiError, InvalidKakaoTokenError, UserNotFoundError


import jwt
from datetime import datetime, timedelta, timezone
from enum import Enum
Expand Down Expand Up @@ -173,6 +174,11 @@ async def get_naver_id_with_naver_access_token(self, access_token: str) -> str:

# 네이버 계정과 연동
async def link_with_naver(self, user:User, naver_access_token: str) -> None:

#만약 유저가 이미 네이버 연동이 되어 있다면
if user.naver_user is not None:
raise NaverLinkAlreadyExistsError()

naver_id = await self.get_naver_id_with_naver_access_token(naver_access_token) # 네이버 access_token 이용해 User의 네이버 고유 식별 id 가져오기
self.user_store.link_with_naver(user.userid, naver_id) # User의 네이버 고유 식별 id 등록

Expand Down Expand Up @@ -212,6 +218,11 @@ async def get_kakao_id_with_kakao_access_token(self, kakao_access_token) -> int:

# 카카오 계정과 연동
async def link_with_kakao(self, user:User, kakao_access_token: str) -> None:

#만약 유저가 이미 카카오 연동이 되어 있다면
if user.kakao_user is not None:
raise KakaoLinkAlreadyExistsError()

kakao_id = await self.get_kakao_id_with_kakao_access_token(kakao_access_token) # 카카오 access_token 이용해 User의 카카오 고유 식별 id 가져오기
self.user_store.link_with_kakao(user.userid, kakao_id) # User의 카카오 고유 식별 id 등록

Expand Down
4 changes: 2 additions & 2 deletions snuvote/app/user/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def get_user_by_naver_id(self, naver_id: str) -> User:
# 카카오 고유 식별 id 등록
def link_with_kakao(self, userid: str, kakao_id: int):
user = self.get_user_by_userid(userid)
new_naveruser = KakaoUser(user_id=user.id, kakao_id=kakao_id)
self.session.add(new_naveruser)
new_kakaouser = KakaoUser(user_id=user.id, kakao_id=kakao_id)
self.session.add(new_kakaouser)
try:
self.session.flush()
except IntegrityError as e:
Expand Down

0 comments on commit 7a900e2

Please sign in to comment.