Skip to content

Commit

Permalink
Merge pull request #43 from TaleLin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
colorful3 authored Apr 26, 2019
2 parents 464e3d4 + 218519f commit ecbc603
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 88 deletions.
1 change: 1 addition & 0 deletions add_super.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lin.db import db
from lin.core import User


def main():
app = create_app()
with app.app_context():
Expand Down
2 changes: 0 additions & 2 deletions app/api/cms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ def create_cms():
from .admin import admin_api
from .user import user_api
from .log import log_api
from .notify import notify_api
from .test import test_api
admin_api.register(cms)
user_api.register(cms)
log_api.register(cms)
notify_api.register(cms)
test_api.register(cms)
return cms
82 changes: 0 additions & 82 deletions app/api/cms/notify.py

This file was deleted.

13 changes: 10 additions & 3 deletions app/api/cms/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
from operator import and_

from flask import jsonify
from flask_jwt_extended import create_access_token, jwt_refresh_token_required, get_jwt_identity, get_current_user, \
create_refresh_token
from flask_jwt_extended import create_access_token, get_jwt_identity, get_current_user, \
create_refresh_token, verify_jwt_refresh_token_in_request
from lin.core import manager, route_meta, Log
from lin.db import db
from lin.exception import NotFound, Success, Failed, RepeatException, ParameterException
from lin.jwt import login_required, admin_required, get_tokens
from lin.log import Logger
from lin.redprint import Redprint

from app.libs.error_code import RefreshException
from app.validators.forms import LoginForm, RegisterForm, ChangePasswordForm, UpdateInfoForm

user_api = Redprint('user')
Expand Down Expand Up @@ -100,8 +101,13 @@ def get_information():

@user_api.route('/refresh', methods=['GET'])
@route_meta(auth='刷新令牌', module='用户', mount=False)
@jwt_refresh_token_required
def refresh():

try:
verify_jwt_refresh_token_in_request()
except Exception:
return RefreshException()

identity = get_jwt_identity()
if identity:
access_token = create_access_token(identity=identity)
Expand All @@ -110,6 +116,7 @@ def refresh():
'access_token': access_token,
'refresh_token': refresh_token
})

return NotFound(msg='refresh_token未被识别')


Expand Down
6 changes: 6 additions & 0 deletions app/libs/error_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ class BookNotFound(APIException):
code = 404 # http状态码
msg = '没有找到相关图书' # 异常信息
error_code = 80010 # 约定的异常码


class RefreshException(APIException):
code = 401
msg = "refresh token 获取失败"
error_code = 10100
7 changes: 6 additions & 1 deletion app/validators/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:copyright: © 2019 by the Lin team.
:license: MIT, see LICENSE for more details.
"""

from lin import manager
from wtforms import DateTimeField, PasswordField, FieldList, IntegerField, StringField
from wtforms.validators import DataRequired, Regexp, EqualTo, length, Optional, NumberRange
import time
Expand All @@ -27,6 +27,11 @@ class RegisterForm(Form):
Optional()
])

def validate_group_id(self, value):
exists = manager.group_model.get(id=value.data)
if not exists:
raise ValueError('分组不存在')


# 登陆校验
class LoginForm(Form):
Expand Down
2 changes: 2 additions & 0 deletions code.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

10070 禁止操作

10100 refresh token 获取失败

20000 werkzeug 中的HTTP EXCEPTION,error_code统一为1007,前端应读取msg

## 项目使用的状态码
Expand Down

0 comments on commit ecbc603

Please sign in to comment.