Skip to content

Commit 9e2f8e6

Browse files
insistencegitee-org
authored andcommitted
!21 Dash-FastAPI-Admin v1.3.1
Merge pull request !21 from insistence/develop
2 parents f955945 + f14d342 commit 9e2f8e6

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<p align="center">
22
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
33
</p>
4-
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.3.0</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.3.1</h1>
55
<h4 align="center">基于Dash+FastAPI前后端分离的纯Python快速开发框架</h4>
66
<p align="center">
77
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/stargazers"><img src="https://gitee.com/insistence2022/dash-fastapi-admin/badge/star.svg?theme=dark"></a>
88
<a href="https://github.com/insistence/Dash-FastAPI-Admin"><img src="https://img.shields.io/github/stars/insistence/Dash-FastAPI-Admin?style=social"></a>
9-
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.3.0-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.3.1-brightgreen.svg"></a>
1010
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
1111
<img src="https://img.shields.io/badge/python-3.8 | 3.9-blue">
1212
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
@@ -15,6 +15,7 @@
1515

1616

1717

18+
1819
## 平台简介
1920

2021
Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。

dash-fastapi-backend/.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.3.0'
13+
APP_VERSION= '1.3.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = true
1616

dash-fastapi-backend/.env.prod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# 应用运行环境
33
APP_ENV = 'prod'
44
# 应用名称
5-
APP_NAME = 'Dash-FasAPI'
5+
APP_NAME = 'Dash-FasAPI-Admin'
66
# 应用代理路径
77
APP_ROOT_PATH = '/prod-api'
88
# 应用主机
99
APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.3.0'
13+
APP_VERSION= '1.3.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = false
1616

dash-fastapi-backend/module_admin/service/login_service.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from module_admin.dao.login_dao import *
1212
from module_admin.service.user_service import UserService
1313
from module_admin.dao.user_dao import *
14-
from config.env import JwtConfig, RedisInitKeyConfig
14+
from config.env import AppConfig, JwtConfig, RedisInitKeyConfig
1515
from utils.pwd_util import *
1616
from utils.response_util import *
1717
from utils.message_util import *
@@ -155,6 +155,22 @@ async def logout_services(request: Request, session_id: str):
155155
return True
156156

157157

158+
async def check_login_ip(request: Request, login_user: UserLogin):
159+
"""
160+
校验用户登录ip是否在黑名单内
161+
:param request: Request对象
162+
:param login_user: 登录用户对象
163+
:return: 校验结果
164+
"""
165+
black_ip_value = await request.app.state.redis.get(
166+
f"{RedisInitKeyConfig.SYS_CONFIG.get('key')}:sys.login.blackIPList")
167+
black_ip_list = black_ip_value.split(',') if black_ip_value else []
168+
if login_user.login_info.get('ipaddr') in black_ip_list:
169+
logger.warning("当前IP禁止登录")
170+
raise LoginException(data="", message="当前IP禁止登录")
171+
return True
172+
173+
158174
async def check_login_captcha(request: Request, login_user: UserLogin):
159175
"""
160176
校验用户登录验证码
@@ -180,12 +196,18 @@ async def authenticate_user(request: Request, query_db: Session, login_user: Use
180196
:param login_user: 登录用户对象
181197
:return: 校验结果
182198
"""
199+
await check_login_ip(request, login_user)
183200
account_lock = await request.app.state.redis.get(f"{RedisInitKeyConfig.ACCOUNT_LOCK.get('key')}:{login_user.user_name}")
184201
if login_user.user_name == account_lock:
185202
logger.warning("账号已锁定,请稍后再试")
186203
raise LoginException(data="", message="账号已锁定,请稍后再试")
187-
# 判断是否开启验证码,开启则验证,否则不验证
188-
if login_user.captcha_enabled:
204+
# 判断请求是否来自于api文档
205+
request_from_swagger = request.headers.get('referer').endswith('docs') if request.headers.get('referer') else False
206+
request_from_redoc = request.headers.get('referer').endswith('redoc') if request.headers.get('referer') else False
207+
# 判断是否开启验证码,开启则验证,否则不验证(dev模式下来自API文档的登录请求不检验)
208+
if not login_user.captcha_enabled or ((request_from_swagger or request_from_redoc) and AppConfig.app_env == 'dev'):
209+
pass
210+
else:
189211
await check_login_captcha(request, login_user)
190212
user = login_by_account(query_db, login_user.user_name)
191213
if not user:

0 commit comments

Comments
 (0)