Skip to content

Commit bc97134

Browse files
sunlin92colorful3
authored andcommitted
替换过时的jwt方法
1 parent 7029e01 commit bc97134

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

app/api/cms/user.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
:copyright: © 2020 by the Lin team.
55
:license: MIT, see LICENSE for more details.
66
"""
7+
import jwt
78
from flask import Blueprint, current_app, g, request
89
from flask_jwt_extended import (
910
create_access_token,
@@ -12,7 +13,6 @@
1213
get_jwt_identity,
1314
verify_jwt_in_request,
1415
)
15-
from itsdangerous import JSONWebSignatureSerializer as JWSSerializer
1616
from lin import (
1717
DocResponse,
1818
Duplicated,
@@ -100,8 +100,7 @@ def login(json: LoginSchema):
100100
if current_app.config.get("LOGIN_CAPTCHA"):
101101
tag = request.headers.get("tag")
102102
secret_key = current_app.config.get("SECRET_KEY")
103-
serializer = JWSSerializer(secret_key)
104-
if g.captcha != serializer.loads(tag):
103+
if g.captcha != jwt.decode(tag, secret_key, algorithms=["HS256"]).get("code"):
105104
raise Failed("验证码校验失败") # type: ignore
106105

107106
user = manager.user_model.verify(g.username, g.password)
@@ -251,6 +250,5 @@ def get_captcha():
251250
return CaptchaSchema() # type: ignore
252251
image, code = CaptchaTool().get_verify_code()
253252
secret_key = current_app.config.get("SECRET_KEY")
254-
serializer = JWSSerializer(secret_key)
255-
tag = serializer.dumps(code)
253+
tag = jwt.encode({"code": code}, secret_key, algorithm="HS256")
256254
return {"tag": tag, "image": image}

0 commit comments

Comments
 (0)