提交 dd7f423f9e6bcc8198a43882507b843e5a7c0284

作者 qianyingz
1 个父辈 a3228acb

用户接口

... ... @@ -9,7 +9,7 @@ from .models import *
9 9 from .oauth2 import authorization, require_oauth, generate_user_info
10 10 from authlib.oauth2 import OAuth2Error
11 11 from authlib.integrations.flask_oauth2 import current_token
12   -from . import user_create, client_create, client_query
  12 +from . import user_create, client_create, client_query,user_query
13 13
14 14
15 15 def current_user():
... ... @@ -139,7 +139,7 @@ class DataManager(BlueprintApi):
139 139 @bp.route("/logout", methods=["GET"])
140 140 # @require_oauth("profile")
141 141 def logout():
142   - url=''
  142 + url = ''
143 143 try:
144 144 user = current_user()
145 145 grant = authorization.validate_consent_request(end_user=user)
... ... @@ -150,7 +150,7 @@ class DataManager(BlueprintApi):
150 150 db.session.commit()
151 151 remove_user()
152 152 if accesstoken:
153   - url =grant.client.client_uri
  153 + url = grant.client.client_uri
154 154 except OAuth2Error as error:
155 155 return jsonify(dict(error.get_body()))
156 156 return redirect(url)
... ... @@ -170,7 +170,17 @@ class DataManager(BlueprintApi):
170 170
171 171 """接口"""
172 172 @staticmethod
173   - @bp.route("/user_create", methods=["POST"])
  173 + @bp.route("/users", methods=["GET"])
  174 + @swag_from(user_query.Api.api_doc)
  175 + def user_query():
  176 + """
  177 + 获取用户列表
  178 + """
  179 + return user_query.Api().result
  180 +
  181 +
  182 + @staticmethod
  183 + @bp.route("/users", methods=["POST"])
174 184 @swag_from(user_create.Api.api_doc)
175 185 def user_create():
176 186 """
... ... @@ -179,7 +189,7 @@ class DataManager(BlueprintApi):
179 189 return user_create.Api().result
180 190
181 191 @staticmethod
182   - @bp.route("/client_create", methods=["POST"])
  192 + @bp.route("/client", methods=["POST"])
183 193 @swag_from(client_create.Api.api_doc)
184 194 def client_create():
185 195 """
... ...
  1 +# coding=utf-8
  2 +#author: qianyingz
  3 +#createtime: 2021/8/14
  4 +#email: qianyingz@chinadci.com
  5 +
  6 +from authlib.oidc.core.claims import UserInfo
  7 +from .models import *
  8 +from app.util.component.ApiTemplate import ApiTemplate
  9 +
  10 +
  11 +class Api(ApiTemplate):
  12 + api_name = "获取用户列表"
  13 +
  14 + def para_check(self):
  15 + pass
  16 +
  17 + def process(self):
  18 + # 返回结果
  19 + res = {}
  20 + res["result"] = False
  21 + try:
  22 + # 业务逻辑
  23 + pass
  24 + page_index = int(self.para.get("pageIndex", "0"))
  25 + page_size = int(self.para.get("pageSize", "1000"))
  26 + name = self.para.get("name")
  27 + id = self.para.get('guid')
  28 +
  29 + if id:
  30 + tmp_user = User.query.filter_by(id=id).first()
  31 + res["data"] = {"id": tmp_user.id, "username": tmp_user.username,
  32 + "role": tmp_user.role}
  33 + else:
  34 + # 获取集合
  35 + userLinq = User.query.order_by(User.id.desc())
  36 + if name:
  37 + userLinq = userLinq.filter(
  38 + User.username.like("%" + name + "%"))
  39 + tmp_count = userLinq.count()
  40 + tmp_list = userLinq.limit(page_size).offset(
  41 + page_index * page_size).all()
  42 + res["data"] = {
  43 + "count": tmp_count,
  44 + "list": list(map(lambda t:
  45 + {"id": t.id, "username": t.username,
  46 + "role": t.role},
  47 + tmp_list))}
  48 + res["result"] = True
  49 +
  50 + except Exception as e:
  51 + raise e
  52 + return res
  53 +
  54 + api_doc = {
  55 +
  56 + "tags": ["认证接口"],
  57 + "parameters": [
  58 + {"name": "page_index",
  59 + "in": "query",
  60 + "type": "int",
  61 + "description": "当前页",
  62 + "default": 0},
  63 + {"name": "page_size",
  64 + "in": "query",
  65 + "type": "int",
  66 + "description": "条数",
  67 + "default": 1000},
  68 + {"name": "name",
  69 + "in": "query",
  70 + "type": "string",
  71 + "description": "名称关键字"},
  72 + {"name": "guid",
  73 + "in": "query",
  74 + "type": "string",
  75 + "description": "用户id,用于获取用户信息"}
  76 + ],
  77 + "responses": {
  78 + 200: {
  79 + "schema": {
  80 + "properties": {
  81 + }
  82 + }
  83 + }
  84 + }
  85 + }
... ...
注册登录 后发表评论