add icon for user
This commit is contained in:
1 parent
ef08b9f433
commit
78cf43d7ff
7 files changed
+72
-36
No files matched your search
@@ -24,6 +24,7 @@ def user_view(user: User) -> dict:
|
||||
return {
|
||||
"email": user.email,
|
||||
"name": user.name,
|
||||
"picture": user.picture_url,
|
||||
"jobs_created": user.jobs_created,
|
||||
"job_limit": user.job_limit,
|
||||
"jobs_left": user.jobs_left,
|
||||
@@ -33,11 +34,13 @@ def user_view(user: User) -> dict:
|
||||
async def find_or_create(session: AsyncSession, account) -> User:
|
||||
user = await session.get(User, account.sub)
|
||||
if user is None:
|
||||
user = User(id=account.sub, email=account.email, name=account.name)
|
||||
user = User(id=account.sub, email=account.email, name=account.name,
|
||||
picture_url=account.picture)
|
||||
session.add(user)
|
||||
else:
|
||||
# 이메일·이름은 구글 쪽에서 바뀔 수 있어 로그인할 때마다 맞춘다
|
||||
user.email, user.name = account.email, account.name
|
||||
# 이메일·이름·사진은 구글 쪽에서 바뀔 수 있어 로그인할 때마다 맞춘다
|
||||
user.email, user.name, user.picture_url = (account.email, account.name,
|
||||
account.picture)
|
||||
await session.commit()
|
||||
return user
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from utils.database import Base
|
||||
|
||||
USER_ID_LENGTH = 64
|
||||
EMAIL_LENGTH = 320
|
||||
PICTURE_URL_LENGTH = 512
|
||||
DEFAULT_JOB_LIMIT = 3
|
||||
|
||||
# 소유자를 모르는 잡의 자리. 나중에 admin의 sub로 덮어쓴다
|
||||
@@ -24,6 +25,8 @@ class User(Base):
|
||||
id: Mapped[str] = mapped_column(String(USER_ID_LENGTH), primary_key=True)
|
||||
email: Mapped[str] = mapped_column(String(EMAIL_LENGTH), index=True)
|
||||
name: Mapped[str] = mapped_column(String(255), default="")
|
||||
# 구글 프로필 사진. 토큰에만 들어오는 값이라 로그인할 때 받아 둔다
|
||||
picture_url: Mapped[str] = mapped_column(String(PICTURE_URL_LENGTH), default="")
|
||||
|
||||
# 만들 수 있는 총 잡 수. 무제한으로 둘 계정은 이 값을 크게 올린다
|
||||
job_limit: Mapped[int] = mapped_column(Integer, default=DEFAULT_JOB_LIMIT)
|
||||
|
||||
@@ -38,10 +38,11 @@ class GoogleTokenInvalid(RuntimeError):
|
||||
|
||||
|
||||
class GoogleAccount:
|
||||
def __init__(self, sub: str, email: str, name: str):
|
||||
def __init__(self, sub: str, email: str, name: str, picture: str):
|
||||
self.sub = sub
|
||||
self.email = email
|
||||
self.name = name
|
||||
self.picture = picture
|
||||
|
||||
|
||||
def is_enabled() -> bool:
|
||||
@@ -113,4 +114,5 @@ async def verify_id_token(credential: str) -> GoogleAccount:
|
||||
raise GoogleTokenInvalid("이메일이 인증되지 않은 계정입니다")
|
||||
|
||||
return GoogleAccount(sub=sub, email=str(claims.get("email") or ""),
|
||||
name=str(claims.get("name") or ""))
|
||||
name=str(claims.get("name") or ""),
|
||||
picture=str(claims.get("picture") or ""))
|
||||
Reference in new issue
Block a user