browser-go-api/api/users/api_users.py
2019-10-08 18:03:46 -07:00

28 lines
877 B
Python

from models.User import User, user_schema, users_schema
from flask import Blueprint, request, json, session, jsonify
from ..decorators import jwt_required
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)
@api_users.route('/users/account', methods=['GET'])
@jwt_required()
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)