260706_2_로그인 인증 검토
This commit is contained in:
@@ -6,17 +6,17 @@ from fastapi import APIRouter, HTTPException, Query
|
||||
|
||||
from common_util.common_util_auth import generate_otp, hash_password, verify_password
|
||||
from common_util.common_util_auth_repository import (
|
||||
company_master_email,
|
||||
complete_registration,
|
||||
consume_otp,
|
||||
create_registration,
|
||||
get_active_otp,
|
||||
get_user_by_email,
|
||||
refresh_pending_registration,
|
||||
replace_otp,
|
||||
search_companies,
|
||||
)
|
||||
from common_util.common_util_email import send_email_background
|
||||
from common_util.common_util_email_templates import join_request_email, otp_email
|
||||
from common_util.common_util_email_templates import otp_email
|
||||
|
||||
from .A07_Register_Schema import RegisterRequest, RegisterVerifyRequest
|
||||
|
||||
@@ -31,11 +31,21 @@ async def find_companies(q: str = Query(min_length=1, max_length=100)):
|
||||
@router.post("/register/request", status_code=202)
|
||||
async def request_registration(payload: RegisterRequest):
|
||||
email = str(payload.email).lower()
|
||||
if await get_user_by_email(email):
|
||||
raise HTTPException(status_code=409, detail="이미 등록된 이메일입니다.")
|
||||
data = payload.model_dump()
|
||||
data = payload.model_dump(exclude={"password_confirm"})
|
||||
data["email"] = email
|
||||
user_id = await create_registration(data, hash_password(payload.password))
|
||||
password_hash = hash_password(payload.password)
|
||||
|
||||
existing = await get_user_by_email(email)
|
||||
if existing:
|
||||
# 이미 이메일 인증까지 마친 계정이면 재가입 불가
|
||||
if existing["status"] != "PENDING_EMAIL":
|
||||
raise HTTPException(status_code=409, detail="이미 등록된 이메일입니다.")
|
||||
# 미인증 계정이면 최신 요청으로 갱신하고 새 인증 코드를 발급
|
||||
user_id = existing["id"]
|
||||
await refresh_pending_registration(user_id, data, password_hash)
|
||||
else:
|
||||
user_id = await create_registration(data, password_hash)
|
||||
|
||||
code = generate_otp()
|
||||
await replace_otp(user_id, "REGISTER", hash_password(code))
|
||||
subject, html = otp_email(code, "회원가입")
|
||||
@@ -57,13 +67,9 @@ async def verify_registration(payload: RegisterVerifyRequest):
|
||||
raise HTTPException(status_code=400, detail="인증 코드가 유효하지 않습니다.")
|
||||
await consume_otp(otp["id"])
|
||||
await complete_registration(user["id"], bool(user["is_master"]))
|
||||
|
||||
if not user["is_master"]:
|
||||
master_email = await company_master_email(user["company_id"])
|
||||
if master_email:
|
||||
subject, html = join_request_email(user["name"], user["email"])
|
||||
send_email_background(master_email, subject, html)
|
||||
# 회원가입 시점에는 회사가 없으므로(NO_COMPANY) 마스터 알림은 발송하지 않는다.
|
||||
# 회사 생성/연결은 로그인 후 B01_AccountDetail에서 진행한다.
|
||||
return {
|
||||
"status": "success",
|
||||
"account_status": "ACTIVE" if user["is_master"] else "PENDING",
|
||||
"account_status": "NO_COMPANY",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user