ロジック変更
This commit is contained in:
parent
000e9c006f
commit
7a65e2b46e
@ -71,19 +71,21 @@ def login(
|
||||
# ログイン失敗回数が10回以上あれば、ログアウト画面にリダイレクトする
|
||||
if pre_login_user_record is not None and pre_login_user_record.is_login_failed_limit_exceeded():
|
||||
logger.info(f'ログイン失敗回数が10回以上: {pre_login_user_record.user_id}')
|
||||
login_service.incorrect_login_password_attempt(pre_login_user_record.user_id)
|
||||
login_service.increase_login_failed_count(pre_login_user_record.user_id)
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_FAILED_LIMIT_EXCEEDED)
|
||||
|
||||
try:
|
||||
jwt_token = login_service.login(request.username, request.password)
|
||||
except NotAuthorizeException as e:
|
||||
logger.info(f'ログイン失敗:{e}')
|
||||
login_service.incorrect_login_password_attempt(request.username)
|
||||
if pre_login_user_record is not None and pre_login_user_record.is_on_login_failed_limit():
|
||||
login_service.increase_login_failed_count(request.username)
|
||||
|
||||
# pre_login_user_recordのデータ更新
|
||||
pre_login_user_record = login_service.logged_in_user(request.username)
|
||||
if pre_login_user_record is not None and pre_login_user_record.is_login_failed_limit_exceeded():
|
||||
login_service.on_login_fail_limit_exceeded(pre_login_user_record.user_id)
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_FAILED_LIMIT_EXCEEDED)
|
||||
else:
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_ERROR)
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=constants.LOGOUT_REASON_LOGIN_ERROR)
|
||||
except JWTTokenVerifyException as e:
|
||||
logger.info(f'ログイン失敗:{e}')
|
||||
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
@ -49,7 +49,7 @@ class LoginService(BaseService):
|
||||
user_record: UserMasterModel = self.user_repository.fetch_one({'user_id': user_id})
|
||||
return user_record
|
||||
|
||||
def incorrect_login_password_attempt(self, user_id: str):
|
||||
def increase_login_failed_count(self, user_id: str):
|
||||
self.user_repository.increase_login_failed_count({'user_id': user_id})
|
||||
|
||||
def on_login_fail_limit_exceeded(self, user_id: str):
|
||||
|
||||
@ -63,7 +63,7 @@ LOGOUT_REASON_BACKUP_PROCESSING = 'dump_processing'
|
||||
LOGOUT_REASON_NOT_LOGIN = 'not_login'
|
||||
LOGOUT_REASON_DB_ERROR = 'db_error'
|
||||
LOGOUT_REASON_UNEXPECTED = 'unexpected'
|
||||
LOGOUT_REASON_LOGIN_FAILED_LIMIT_EXCEEDED = 'retry_limit_exceeded'
|
||||
LOGOUT_REASON_LOGIN_FAILED_LIMIT_EXCEEDED = 'login_failed_limit_exceeded'
|
||||
|
||||
LOGOUT_REASON_MESSAGE_MAP = {
|
||||
LOGOUT_REASON_DO_LOGOUT: 'Logoutしました。',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user