Esempio n. 1
0
def logout(self):
    #get auth token
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(" ")[1]
    else:
        auth_token = ' '
    if auth_token:
        resp = User.decode_auth_token(auth_token)
        if not isinstance(resp, str):
            #mark the token as blacklisted
            # blacklist_token = Token(token=0) #blacklisted token
            try:
                #insert the token
                # db.session.add(blacklist_token)
                db.session.commit()
                response_object = {
                    'status': 'success',
                    'message': 'Successfully logged out.'
                }
                return jsonify(response_object), 200
            except Exception as e:
                response_object = {'status': 'fail', 'message': str(e)}
                return jsonify(response_object), 200
        else:
            response_object = {'status': 'fail', 'message': resp}
            return jsonify(response_object), 401
    else:
        response_object = {
            'status': 'fail',
            'message': 'Provide a valid auth token.'
        }
        return jsonify(response_object), 403
Esempio n. 2
0
def getSingleUser():
    auth_header = request.headers.get('Authentication')
    if auth_header:
        try:
            auth_token = auth_header.split(" ")[1]
        except IndexError:
            response_object = {
                'status': 'fail',
                'message': 'Bearer token malformed.'
            }
            return jsonify(response_object), 401
    else:
        auth_token = ' '
    if auth_token:
        resp = User.decode_auth_token(auth_token)
        user = User.query.filter_by(user_id=resp).first()
        if not user:
            return jsonify({'message': 'No records of that user.'}), 422
        user_dict = {'category': user.category, 'email': user.email}
        return jsonify({'data': user_dict})