feat: 账号密码登录新增IP黑名单校验
This commit is contained in:
@@ -56,6 +56,7 @@ class LoginService:
|
|||||||
:param login_user: 登录用户对象
|
:param login_user: 登录用户对象
|
||||||
:return: 校验结果
|
:return: 校验结果
|
||||||
"""
|
"""
|
||||||
|
await cls.__check_login_ip(request)
|
||||||
account_lock = await request.app.state.redis.get(
|
account_lock = await request.app.state.redis.get(
|
||||||
f"{RedisInitKeyConfig.ACCOUNT_LOCK.get('key')}:{login_user.user_name}")
|
f"{RedisInitKeyConfig.ACCOUNT_LOCK.get('key')}:{login_user.user_name}")
|
||||||
if login_user.user_name == account_lock:
|
if login_user.user_name == account_lock:
|
||||||
@@ -100,6 +101,21 @@ class LoginService:
|
|||||||
f"{RedisInitKeyConfig.PASSWORD_ERROR_COUNT.get('key')}:{login_user.user_name}")
|
f"{RedisInitKeyConfig.PASSWORD_ERROR_COUNT.get('key')}:{login_user.user_name}")
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def __check_login_ip(cls, request: Request):
|
||||||
|
"""
|
||||||
|
校验用户登录ip是否在黑名单内
|
||||||
|
:param request: Request对象
|
||||||
|
:return: 校验结果
|
||||||
|
"""
|
||||||
|
black_ip_value = await request.app.state.redis.get(
|
||||||
|
f"{RedisInitKeyConfig.SYS_CONFIG.get('key')}:sys.login.blackIPList")
|
||||||
|
black_ip_list = black_ip_value.split(',') if black_ip_value else []
|
||||||
|
if request.headers.get('X-Forwarded-For') in black_ip_list:
|
||||||
|
logger.warning("当前IP禁止登录")
|
||||||
|
raise LoginException(data="", message="当前IP禁止登录")
|
||||||
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def __check_login_captcha(cls, request: Request, login_user: UserLogin):
|
async def __check_login_captcha(cls, request: Request, login_user: UserLogin):
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user