def api_profile_get(profile_id: int):

    profile = Profile.find_by_id(profile_id)

    if profile is None:
        return jsonify({'error': {'message': 'profile not found'}}), 404

    output = {'profile_id': profile_id}
    output.update(profile.get_fields())

    return jsonify(output), 200
def api_profile_delete(profile_id: int):

    if is_access_denied(profile_id):
        return jsonify({'error': {'message': 'forbidden'}}), 403

    profile = Profile.find_by_id(profile_id)

    if profile is None:
        return jsonify({'error': {'message': 'Not Found'}}), 404

    db.session.delete(profile)
    db.session.commit()

    return '', 204
def api_profile_signup():

    fields = decode_input()

    if fields is None:
        return jsonify({'error': {'message': 'invalid input'}}), 400

    profile, error = Profile.create(fields)

    if profile is None:
        return jsonify({'error': error}), error['status']

    return jsonify({'profile_id': profile.id}), 201, {
        'location': '/api/profile/{}'.format(profile.id)
    }
def api_profile_set(profile_id: int):

    if is_access_denied(profile_id):
        return jsonify({'error': {'message': 'forbidden'}}), 403

    profile = Profile.find_by_id(profile_id)

    if profile is None:
        return jsonify({'error': {'message': 'profile not found'}}), 404

    fields = decode_input()

    if fields is None:
        return jsonify({'error': {'message': 'invalid input'}}), 400

    profile.update_fields(fields)

    return '', 204
Esempio n. 5
0
def profile(profile_id):

    if is_access_denied(profile_id):
        message = 'not authorized profile'
    else:
        message = 'authorized profile'

    profile = Profile.find_by_id(profile_id)

    if profile is None:
        return 'Not Found', 404

    return render_template('profile.html',
                           title='Profile',
                           year=datetime.now().year,
                           message=message,
                           profile_id=profile_id,
                           fields=profile.get_fields())
Esempio n. 6
0
def FriendMake(friendName, imgFilePath, image, g):
    '''
    This function makes a Friend() given just a friendName, imageName, and an image.
    
    Inputs:
        friendName          - the name of the friend, an identifier.
        imgFilePath         - the full path to the file image, just so we can record it.
        image               - the image data itself.
        g                   - Our global constants.

    '''
    
    #Make the Photo:
    photo=Photo(g)
    
    #Make it so we don't save this in the database.
    make_transient(photo)
    
    #Add the image data and compute descriptors:
    photo.set_binary(image,'myType')
    
    #Make a profile:
    profile=Profile('*****@*****.**', 'password', {'phone': '555-555-5555', 
                                                   'use_phone': False,
                                                   'use_msg': False})
    #Make it so we don't save this in the database.
    make_transient(profile)
    
    friend=Friend(profile, {'name'      : friendName,
                            'breed'     : imgFilePath,
                            'sex'       : 'Male',
                            'location'  : 'Minneapolis',
                            'staus'     : 'alive'
                                }, g)
    
    make_transient(friend)
    
    #Update our photo:
    friend.photo=photo
    
    return friend
def api_friend_create(profile_id: int):

    if is_access_denied(profile_id):
        return jsonify({'error': {'message': 'forbidden'}}), 403

    profile = Profile.find_by_id(profile_id)

    if profile is None:
        print('profile not found')
        return jsonify({'error': {'message': 'profile not found'}}), 404

    fields = decode_input()

    if fields is None:
        return jsonify({'error': {'message': 'invalid input'}}), 400

    friend, error = Friend.create(profile, fields)

    if friend is None:
        return jsonify({'error': error}), error['status']

    return jsonify({'friend_id': friend.id}), 201, {
        'location': '/api/friend/{}'.format(friend.id)
    }
from main.api.model import db, Profile

if __name__ == '__main__':
    print('Creating all database tables...')
    db.create_all()

    p = Profile("admin", "EWnwjBNLPGi0l8mOOEKF")
    p.isadmin = True
    db.session.add(p)
    db.session.commit()

    print('Done!')