2019-10-09 00:18:40 +00:00
|
|
|
from models.User import User, user_schema, users_schema
|
|
|
|
from flask import Blueprint, request, json, session, jsonify
|
2019-10-09 01:03:46 +00:00
|
|
|
from ..decorators import jwt_required
|
2019-10-09 00:18:40 +00:00
|
|
|
|
|
|
|
api_users = Blueprint('api_users', __name__, url_prefix='/api')
|
|
|
|
|
|
|
|
@api_users.route('/users/', methods=['GET'])
|
|
|
|
def api_get_users():
|
|
|
|
print('called one')
|
|
|
|
users = User.query.all()
|
|
|
|
response = users_schema.dumps(users)
|
|
|
|
return jsonify(response)
|
|
|
|
|
2019-10-09 01:03:46 +00:00
|
|
|
|
2019-10-09 00:18:40 +00:00
|
|
|
@api_users.route('/users/account', methods=['GET'])
|
2019-10-09 01:03:46 +00:00
|
|
|
@jwt_required()
|
2019-10-09 00:18:40 +00:00
|
|
|
def api_get_user():
|
|
|
|
print('called')
|
|
|
|
auth_header = request.headers.get('Authorization') or None
|
|
|
|
if auth_header:
|
|
|
|
auth_token = auth_header.split(" ")[1]
|
|
|
|
user = User.decode_auth_token(auth_token) or None
|
|
|
|
response = json.dumps(user)
|
|
|
|
else:
|
|
|
|
response = {
|
|
|
|
'status': 'failed',
|
|
|
|
'message': 'Please Log In'}
|
|
|
|
return jsonify(response)
|