2021-10-28 16:09:10 +02:00
|
|
|
from flask import jsonify, request
|
|
|
|
from flask_jwt_extended import jwt_required
|
|
|
|
from flask_cors import cross_origin
|
2021-11-02 08:54:07 +01:00
|
|
|
from flask_expects_json import expects_json
|
2021-10-28 16:09:10 +02:00
|
|
|
|
|
|
|
from areas import api_v1
|
2021-11-02 08:54:07 +01:00
|
|
|
from helpers import KratosApi
|
|
|
|
from .validation import schema
|
2021-10-28 16:09:10 +02:00
|
|
|
|
|
|
|
|
2021-11-02 08:54:07 +01:00
|
|
|
@api_v1.route("/users", methods=["GET"])
|
2021-10-28 16:09:10 +02:00
|
|
|
@jwt_required()
|
|
|
|
@cross_origin()
|
|
|
|
def get_users():
|
2021-11-02 08:54:07 +01:00
|
|
|
res = KratosApi.get("/identities")
|
2021-10-28 16:09:10 +02:00
|
|
|
return jsonify(res.json())
|
|
|
|
|
2021-11-02 08:54:07 +01:00
|
|
|
|
|
|
|
@api_v1.route("/users/<string:id>", methods=["GET"])
|
2021-10-28 16:09:10 +02:00
|
|
|
@jwt_required()
|
|
|
|
@cross_origin()
|
|
|
|
def get_user(id):
|
2021-11-02 08:54:07 +01:00
|
|
|
res = KratosApi.get("/identities/{}".format(id))
|
2021-10-28 16:09:10 +02:00
|
|
|
return jsonify(res.json())
|
|
|
|
|
|
|
|
|
2021-11-02 08:54:07 +01:00
|
|
|
@api_v1.route("/users", methods=["POST"])
|
2021-10-28 16:09:10 +02:00
|
|
|
@jwt_required()
|
|
|
|
@cross_origin()
|
2021-11-02 08:54:07 +01:00
|
|
|
@expects_json(schema)
|
2021-10-28 16:09:10 +02:00
|
|
|
def post_user():
|
|
|
|
data = request.get_json()
|
2021-11-02 08:54:07 +01:00
|
|
|
kratos_data = {"schema_id": "default", "traits": data}
|
|
|
|
res = KratosApi.post("/identities", kratos_data)
|
2021-10-28 16:09:10 +02:00
|
|
|
return jsonify(res.json()), res.status_code
|
|
|
|
|
|
|
|
|
2021-11-02 08:54:07 +01:00
|
|
|
@api_v1.route("/users/<string:id>", methods=["PUT"])
|
2021-10-28 16:09:10 +02:00
|
|
|
@jwt_required()
|
|
|
|
@cross_origin()
|
2021-11-02 08:54:07 +01:00
|
|
|
@expects_json(schema)
|
2021-10-28 16:09:10 +02:00
|
|
|
def put_user(id):
|
|
|
|
data = request.get_json()
|
2021-11-02 08:54:07 +01:00
|
|
|
kratos_data = {"schema_id": "default", "traits": data}
|
|
|
|
res = KratosApi.put("/identities/{}".format(id), kratos_data)
|
2021-10-28 16:09:10 +02:00
|
|
|
return jsonify(res.json()), res.status_code
|
|
|
|
|
|
|
|
|
2021-11-02 08:54:07 +01:00
|
|
|
@api_v1.route("/users/<string:id>", methods=["DELETE"])
|
2021-10-28 16:09:10 +02:00
|
|
|
@jwt_required()
|
|
|
|
@cross_origin()
|
|
|
|
def delete_user(id):
|
2021-11-02 08:54:07 +01:00
|
|
|
res = KratosApi.delete("/identities/{}".format(id))
|
|
|
|
if res.status_code == 204:
|
2021-10-28 16:09:10 +02:00
|
|
|
return jsonify(), res.status_code
|
|
|
|
return jsonify(res.json()), res.status_code
|