Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import jsonify, request
from flask_jwt_extended import jwt_required
from flask_cors import cross_origin
from areas import api_v1
from helpers.kratos_api import KratosApi
@api_v1.route('/users', methods=['GET'])
@jwt_required()
@cross_origin()
def get_users():
res = KratosApi.get('/identities')
return jsonify(res.json())
@api_v1.route('/users/<string:id>', methods=['GET'])
@jwt_required()
@cross_origin()
def get_user(id):
res = KratosApi.get('/identities/{}'.format(id))
return jsonify(res.json())
@api_v1.route('/users', methods=['POST'])
@jwt_required()
@cross_origin()
def post_user():
data = request.get_json()
kratos_data = {
"schema_id": "default",
"traits": data
}
res = KratosApi.post('/identities', kratos_data)
return jsonify(res.json()), res.status_code
@api_v1.route('/users/<string:id>', methods=['PUT'])
@jwt_required()
@cross_origin()
def put_user(id):
data = request.get_json()
kratos_data = {
"schema_id": "default",
"traits": data
}
res = KratosApi.put('/identities/{}'.format(id), kratos_data)
return jsonify(res.json()), res.status_code
@api_v1.route('/users/<string:id>', methods=['DELETE'])
@jwt_required()
@cross_origin()
def delete_user(id):
res = KratosApi.delete('/identities/{}'.format(id))
if (res.status_code == 204):
return jsonify(), res.status_code
return jsonify(res.json()), res.status_code