1차 최종
This commit is contained in:
parent
47c6a476a5
commit
856b6e2855
@ -92,6 +92,21 @@ async def update_last_login_dt(user_seq, db):
|
||||
return False
|
||||
|
||||
|
||||
# oauth 유저인지 확인
|
||||
async def is_oauth_user(user_email, db):
|
||||
query = text(f"""
|
||||
select
|
||||
user_seq
|
||||
from manage_user
|
||||
where user_email = :user_email
|
||||
and oauth_type != 'idpw'
|
||||
""")
|
||||
params = {
|
||||
"user_email": user_email,
|
||||
}
|
||||
return db.execute(query, params).fetchall()
|
||||
|
||||
|
||||
# 아이디 찾기(닉네임, 이메일)
|
||||
async def find_id_by_name_email(nickname, user_email, db):
|
||||
query = text(f"""
|
||||
@ -317,7 +332,8 @@ async def get_my_info_by_user_seq(user_seq, db):
|
||||
user_email,
|
||||
department,
|
||||
profile_img,
|
||||
introduce_myself
|
||||
introduce_myself,
|
||||
oauth_type
|
||||
from manage_user
|
||||
where user_seq = :user_seq
|
||||
""")
|
||||
@ -380,13 +396,13 @@ async def update_user_info(user_info, db):
|
||||
""")
|
||||
params = {
|
||||
"user_seq": user_info['user_seq'],
|
||||
"new_user_pw": user_info['new_user_pw'],
|
||||
"user_pw_solt": user_info['user_pw_solt'],
|
||||
"new_user_pw": user_info.get('new_user_pw', ''),
|
||||
"user_pw_solt": user_info.get('user_pw_solt', ''),
|
||||
"nickname": user_info['nickname'],
|
||||
"user_email": user_info['user_email'],
|
||||
"department": user_info.get('department', ''),
|
||||
"department": user_info['department'],
|
||||
"profile_img": user_info['profile_img'],
|
||||
"introduce_myself": user_info.get('introduce_myself', ''),
|
||||
"introduce_myself": user_info['introduce_myself'],
|
||||
}
|
||||
try:
|
||||
db.execute(query, params)
|
||||
|
@ -190,8 +190,19 @@ async def update_team_name(data):
|
||||
# 업데이트
|
||||
ref.update({
|
||||
"team_name_list": updated_team_names
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
# 유저의 팀명 수정
|
||||
ref = frd_db.reference("rooms").child(f"korea-{data['room_seq']}").child("userInfo")
|
||||
# 이전 팀명을 갖고있는 유저 확인
|
||||
user_list = ref.get()
|
||||
for user_seq, user_info in user_list.items():
|
||||
if user_info['team_name'] == data['before_team_name']:
|
||||
user_info['team_name'] = data['after_team_name']
|
||||
ref.update({
|
||||
f"{user_seq}": user_info
|
||||
})
|
||||
|
||||
return {
|
||||
"result": "OK",
|
||||
"msg": "업데이트 성공"
|
||||
@ -374,7 +385,6 @@ async def check_kick_user(user_seq, room_seq):
|
||||
|
||||
ref = frd_db.reference("rooms").child(f"korea-{room_seq}").child("userList").child(user_seq)
|
||||
user_info = ref.get()
|
||||
logger.info(f"user_info: {user_info}")
|
||||
|
||||
if user_info is None:
|
||||
return {
|
||||
|
@ -91,6 +91,20 @@ async def update_last_login_dt(user_seq, db):
|
||||
}
|
||||
|
||||
|
||||
# oauth 유저인지 확인
|
||||
async def is_oauth_user(user_email, db):
|
||||
db_result = await crud_user.is_oauth_user(user_email=user_email, db=db)
|
||||
|
||||
if len(db_result) == 1:
|
||||
return {
|
||||
"result": "OK"
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"result": "FAIL"
|
||||
}
|
||||
|
||||
|
||||
# 아이디 찾기(닉네임, 이메일)
|
||||
async def find_id_by_name_email(nickname, user_email, db):
|
||||
# DB에서 회원정보 찾기
|
||||
@ -262,7 +276,8 @@ async def get_my_info_by_user_seq(user_seq, db):
|
||||
"user_email": db_result[1],
|
||||
"department": db_result[2],
|
||||
"profile_img": db_result[3],
|
||||
"introduce_myself": db_result[4]
|
||||
"introduce_myself": db_result[4],
|
||||
"oauth_type": db_result[5]
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
@ -63,6 +63,28 @@ def check_new_data(user_info):
|
||||
return None
|
||||
|
||||
|
||||
# 회원정보 수정 입력값 검증
|
||||
def check_new_data_for_oauth(user_info):
|
||||
# oauth 계정이 비밀번호 변경요청은 허용하지 않음
|
||||
if user_info['user_pw_change_yn'] == 'Y':
|
||||
return '소셜로그인 계정은 비밀번호 변경을 허용하지 않습니다.'
|
||||
|
||||
# nickname 확인
|
||||
if not validate_nickname(nickname=user_info['nickname']):
|
||||
return '사용자 닉네임 규칙이 맞지 않습니다.'
|
||||
|
||||
# profile_img 확인
|
||||
if not starts_with_user_dir(user_info['profile_img']):
|
||||
return '프로필 이미지 경로가 정확하지 않습니다.'
|
||||
|
||||
# introduce_myself 확인
|
||||
if len(user_info['introduce_myself']) > 2000:
|
||||
return '자기소개 글은 2000byte까지만 입력 가능합니다.'
|
||||
|
||||
# 이상없음
|
||||
return None
|
||||
|
||||
|
||||
# user_id 정규식 검증
|
||||
def validate_user_id(user_id: str) -> bool:
|
||||
pattern = r'^[a-zA-Z0-9]{6,20}$'
|
||||
@ -112,7 +134,7 @@ async def is_valid_user_id_by_user_id(user_id, db):
|
||||
|
||||
# profile_img 파일명이 /user/temp_dir/profile_img/IMG 로 시작하는지 검증
|
||||
def starts_with_user_dir(value: str) -> bool:
|
||||
prefix = '/user/temp_dir/profile_img/IMG'
|
||||
prefix = '/user/temp_dir/profile_img/'
|
||||
return value.startswith(prefix)
|
||||
|
||||
|
||||
|
@ -154,7 +154,7 @@ async def google_signup(request: Request, body: bytes = Depends(get_body), db: S
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/google/signup\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='구글 회원가입 에러', msg_content='구글 회원가입 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
#==================================================================================================
|
||||
# 로그인
|
||||
@ -223,6 +223,10 @@ async def find_id(request: Request, body: bytes = Depends(get_body), db: Session
|
||||
# 이메일 패턴 검증
|
||||
if not manage_user_pattern.validate_user_email(user_email=user_email):
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='이메일 확인', msg_content='이메일 주소를 정확히 입력해주세요.', data={})
|
||||
# oauth 유저인지 확인
|
||||
is_oauth_user_result = await manage_user.is_oauth_user(user_email=user_email, db=db)
|
||||
if is_oauth_user_result['result'] == 'OK':
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='아이디 찾기 실패', msg_content='구글 계정으로 가입된 이메일입니다.', data={})
|
||||
|
||||
# 닉네임, EMAIL로 아이디 찾기 시도
|
||||
find_id_result = await manage_user.find_id_by_name_email(nickname=nickname, user_email=user_email, db=db)
|
||||
@ -245,7 +249,7 @@ async def find_id(request: Request, body: bytes = Depends(get_body), db: Session
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/find/id\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='아이디 찾기 에러', msg_content='아이디 찾기 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
|
||||
#==================================================================================================
|
||||
@ -333,6 +337,10 @@ async def find_pw(request: Request, body: bytes = Depends(get_body), db: Session
|
||||
# 이메일 패턴 검증
|
||||
if not manage_user_pattern.validate_user_email(user_email=user_email):
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='이메일 확인', msg_content='이메일 주소를 정확히 입력해주세요.', data={})
|
||||
# oauth 유저인지 확인
|
||||
is_oauth_user_result = await manage_user.is_oauth_user(user_email=user_email, db=db)
|
||||
if is_oauth_user_result['result'] == 'OK':
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='비밀번호 찾기 실패', msg_content='구글 계정으로 가입된 이메일입니다.', data={})
|
||||
# 이메일 발송 3회 이상 됐는지 확인
|
||||
send_email_cnt_result = await manage_user.select_send_email_cnt(user_email=user_email, db=db)
|
||||
if send_email_cnt_result['result'] == 'OK':
|
||||
@ -364,7 +372,7 @@ async def find_pw(request: Request, body: bytes = Depends(get_body), db: Session
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/find/password\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='비밀번호 찾기 에러', msg_content='비밀번호 찾기 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
|
||||
#==================================================================================================
|
||||
@ -411,7 +419,7 @@ async def signup(request: Request, body: bytes = Depends(get_body), db: Session
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/signup\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='회원가입 에러', msg_content='회원가입 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
|
||||
#==================================================================================================
|
||||
@ -481,7 +489,7 @@ async def update_profile_img(request: Request, body: str = Form(...), file: Uplo
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/update/profile/img\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='프로필 이미지 업로드 에러', msg_content='프로필 이미지 업로드 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
|
||||
#==================================================================================================
|
||||
@ -518,7 +526,7 @@ async def update_user_info(request: Request, body: bytes = Depends(get_body), db
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/myinfo\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='마이페이지 내정보 가져오기 에러', msg_content='마이페이지 데이터 조회중 에러가 발생했습니다.', data={})
|
||||
|
||||
|
||||
#==================================================================================================
|
||||
@ -545,15 +553,24 @@ async def update_user_info(request: Request, body: bytes = Depends(get_body), db
|
||||
if user_seq_result["result"] == 'OK':
|
||||
user_seq = user_seq_result['data']['user_seq']
|
||||
body['user_seq'] = user_seq
|
||||
# 현재 비밀번호 일치하는지 확인
|
||||
current_pw_correct_result = await manage_user.check_current_user_pw(user_seq=user_seq, user_pw=body['user_pw'], db=db)
|
||||
if current_pw_correct_result['result'] == 'FAIL':
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='현재 비밀번호 인증 실패', msg_content='현재 비밀번호가 일치하지 않습니다.', data={})
|
||||
# oauth 계정 유저면 비밀번호 확인 생략
|
||||
if body['oauth_type'] == 'idpw':
|
||||
# 현재 비밀번호 일치하는지 확인
|
||||
current_pw_correct_result = await manage_user.check_current_user_pw(user_seq=user_seq, user_pw=body['user_pw'], db=db)
|
||||
if current_pw_correct_result['result'] == 'FAIL':
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='현재 비밀번호 인증 실패', msg_content='현재 비밀번호가 일치하지 않습니다.', data={})
|
||||
|
||||
# 입력된 값 패턴 검증
|
||||
new_data_pattern_result_msg = manage_user_pattern.check_new_data(user_info=body)
|
||||
if new_data_pattern_result_msg is not None:
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='회원정보 수정 실패', msg_content=new_data_pattern_result_msg, data={})
|
||||
# 로그인 타입에 따라 패턴검증 다르게 해주기
|
||||
if body['oauth_type'] == 'idpw':
|
||||
# 입력된 값 패턴 검증
|
||||
new_data_pattern_result_msg = manage_user_pattern.check_new_data(user_info=body)
|
||||
if new_data_pattern_result_msg is not None:
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='회원정보 수정 실패', msg_content=new_data_pattern_result_msg, data={})
|
||||
else:
|
||||
# 입력된 값 패턴 검증
|
||||
new_data_pattern_result_msg = manage_user_pattern.check_new_data_for_oauth(user_info=body)
|
||||
if new_data_pattern_result_msg is not None:
|
||||
return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='회원정보 수정 실패', msg_content=new_data_pattern_result_msg, data={})
|
||||
|
||||
# 유저 정보 가져오기
|
||||
user_data = await manage_user.get_my_info_by_user_seq(user_seq=user_seq, db=db)
|
||||
@ -565,15 +582,21 @@ async def update_user_info(request: Request, body: bytes = Depends(get_body), db
|
||||
# user_pw 변경 됐는지 확인
|
||||
if body['user_pw_change_yn'] == 'Y':
|
||||
body['user_pw_solt'] = generate_random_string(10)
|
||||
# oauth 계정은 비밀번호 변경 허용하지 않음
|
||||
if body['oauth_type'] != 'idpw':
|
||||
body['user_pw_change_yn'] = 'N'
|
||||
# nickname 변경 됐는지 확인
|
||||
body['nickname'] = body['nickname'] if body['nickname'] != user_data['nickname'] else user_data['nickname']
|
||||
# user_email 변경 됐는지 확인
|
||||
body['user_email'] = body['user_email'] if body['user_email'] != user_data['user_email'] else user_data['user_email']
|
||||
# oauth 계정은 이메일 변경 허용하지 않음
|
||||
if body['oauth_type'] != 'idpw':
|
||||
body['user_email'] = user_data['user_email']
|
||||
# department 변경 됐는지 확인
|
||||
body['department'] = body['department'] if body['department'] != user_data['department'] else user_data['department']
|
||||
# profile_img 변경 됐는지 확인
|
||||
body['profile_img'] = body['profile_img'] if body['profile_img'] != user_data['profile_img'] else user_data['profile_img']
|
||||
# profile_img 변경 됐는지 확인
|
||||
# introduce_myself 변경 됐는지 확인
|
||||
body['introduce_myself'] = body['introduce_myself'] if body['introduce_myself'] != user_data['introduce_myself'] else user_data['introduce_myself']
|
||||
|
||||
# 변경된 정보에 대해서만 업데이트하기
|
||||
@ -590,7 +613,7 @@ async def update_user_info(request: Request, body: bytes = Depends(get_body), db
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/update/user/info\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='회원정보 수정 에러', msg_content='회원정보 수정 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
|
||||
#==================================================================================================
|
||||
@ -637,8 +660,7 @@ async def withdraw_user(request: Request, body: bytes = Depends(get_body), db: S
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"request error. URL: /user/withdraw/user\nerror message: {e}")
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='로그인 에러', msg_content='로그인 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='회원탈퇴 에러', msg_content='회원탈퇴 처리중 에러가 발생했습니다.', data={})
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user