Skip to content

Commit 39d8258

Browse files
committed
2 parents a422fe6 + ecbc603 commit 39d8258

9 files changed

Lines changed: 51 additions & 100 deletions

File tree

add_super.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22
:copyright: © 2019 by the Lin team.
33
:license: MIT, see LICENSE for more details.
44
"""
5+
from sqlalchemy.exc import IntegrityError
56

67
from app.app import create_app
78
from lin.db import db
89
from lin.core import User
910

10-
app = create_app()
11-
with app.app_context():
12-
with db.auto_commit():
13-
# 创建一个超级管理员
14-
user = User()
15-
user.nickname = 'super'
16-
user.password = '123456'
17-
user.email = '1234995678@qq.com'
18-
# admin 2 的时候为超级管理员,普通用户为 1
19-
user.admin = 2
20-
db.session.add(user)
11+
12+
def main():
13+
app = create_app()
14+
with app.app_context():
15+
with db.auto_commit():
16+
# 创建一个超级管理员
17+
user = User()
18+
user.nickname = 'super'
19+
user.password = '123456'
20+
user.email = '1234995678@qq.com'
21+
# admin 2 的时候为超级管理员,普通用户为 1
22+
user.admin = 2
23+
db.session.add(user)
24+
25+
26+
if __name__ == '__main__':
27+
try:
28+
main()
29+
print("新增超级管理员成功")
30+
except Exception as e:
31+
raise e

app/api/cms/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ def create_cms():
1313
from .admin import admin_api
1414
from .user import user_api
1515
from .log import log_api
16-
from .notify import notify_api
1716
from .test import test_api
1817
admin_api.register(cms)
1918
user_api.register(cms)
2019
log_api.register(cms)
21-
notify_api.register(cms)
2220
test_api.register(cms)
2321
return cms

app/api/cms/notify.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

app/api/cms/user.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
from operator import and_
88

99
from flask import jsonify
10-
from flask_jwt_extended import create_access_token, jwt_refresh_token_required, get_jwt_identity, get_current_user, \
11-
create_refresh_token
10+
from flask_jwt_extended import create_access_token, get_jwt_identity, get_current_user, \
11+
create_refresh_token, verify_jwt_refresh_token_in_request
1212
from lin.core import manager, route_meta, Log
1313
from lin.db import db
1414
from lin.exception import NotFound, Success, Failed, RepeatException, ParameterException
1515
from lin.jwt import login_required, admin_required, get_tokens
1616
from lin.log import Logger
1717
from lin.redprint import Redprint
1818

19+
from app.libs.error_code import RefreshException
1920
from app.validators.forms import LoginForm, RegisterForm, ChangePasswordForm, UpdateInfoForm
2021

2122
user_api = Redprint('user')
@@ -100,8 +101,13 @@ def get_information():
100101

101102
@user_api.route('/refresh', methods=['GET'])
102103
@route_meta(auth='刷新令牌', module='用户', mount=False)
103-
@jwt_refresh_token_required
104104
def refresh():
105+
106+
try:
107+
verify_jwt_refresh_token_in_request()
108+
except Exception:
109+
return RefreshException()
110+
105111
identity = get_jwt_identity()
106112
if identity:
107113
access_token = create_access_token(identity=identity)
@@ -110,6 +116,7 @@ def refresh():
110116
'access_token': access_token,
111117
'refresh_token': refresh_token
112118
})
119+
113120
return NotFound(msg='refresh_token未被识别')
114121

115122

app/config/setting.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# 令牌配置
1313
JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)
1414

15+
# 屏蔽 sql alchemy 的 FSADeprecationWarning
16+
SQLALCHEMY_TRACK_MODIFICATIONS = False
17+
1518
# 插件模块暂时没有开启,以下配置可忽略
1619
# plugin config写在字典里面
1720
PLUGIN_PATH = {

app/libs/error_code.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ class BookNotFound(APIException):
1010
code = 404 # http状态码
1111
msg = '没有找到相关图书' # 异常信息
1212
error_code = 80010 # 约定的异常码
13+
14+
15+
class RefreshException(APIException):
16+
code = 401
17+
msg = "refresh token 获取失败"
18+
error_code = 10100

app/validators/forms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
:copyright: © 2019 by the Lin team.
33
:license: MIT, see LICENSE for more details.
44
"""
5-
5+
from lin import manager
66
from wtforms import DateTimeField, PasswordField, FieldList, IntegerField, StringField
77
from wtforms.validators import DataRequired, Regexp, EqualTo, length, Optional, NumberRange
88
import time
@@ -27,6 +27,11 @@ class RegisterForm(Form):
2727
Optional()
2828
])
2929

30+
def validate_group_id(self, value):
31+
exists = manager.group_model.get(id=value.data)
32+
if not exists:
33+
raise ValueError('分组不存在')
34+
3035

3136
# 登陆校验
3237
class LoginForm(Form):

code.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
10070 禁止操作
2626

27+
10100 refresh token 获取失败
28+
2729
20000 werkzeug 中的HTTP EXCEPTION,error_code统一为1007,前端应读取msg
2830

2931
## 项目使用的状态码

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Flask-WTF==0.14.2
1010
idna==2.6
1111
itsdangerous==1.1.0
1212
Jinja2==2.10
13-
Lin-CMS==0.1.1a4
13+
Lin-CMS==0.1.1a6
1414
MarkupSafe==1.1.1
1515
pipfile==0.0.2
1616
PyJWT==1.7.1
@@ -21,3 +21,4 @@ toml==0.10.0
2121
urllib3==1.22
2222
Werkzeug==0.14.1
2323
WTForms==2.2.1
24+
oss2==2.6.1

0 commit comments

Comments
 (0)