Пример #1
0
def getS3objects():
    request = app.current_request
    username = get_authorized_username(app.current_request)
    user = User.find(username)
    try:
        return {'image_url': user.get_profile_pic()}
    except ClientError as e:
        raise NotFoundError('image')
Пример #2
0
def upload():
    files = _get_parts()
    username = get_authorized_username(app.current_request)
    user = User.find(username)
    user.update_profile_pic(files['file'].filename, files['file'].value)
    return {
        "uploaded": "true",
        "profile_pic_url": user.get_profile_pic(),
    }
Пример #3
0
def update_current_user():
    body = app.current_request.json_body
    username = get_authorized_username(app.current_request)
    user = User.find(username)
    if user != None:
        user.update_attributes(body)
        return_data = user.attributes()
    else:
        return_data = {'error': 'Record not found.'}
    return return_data
Пример #4
0
def s3objects(file_name):
    request = app.current_request
    username = get_authorized_username(app.current_request)
    user = User.find(username)
    body = app.current_request.raw_body
    user.update_profile_pic(file_name, body)
    return {
        "uploaded": "true",
        "profile_pic_url": user.get_profile_pic(),
    }
Пример #5
0
def login():
    body = app.current_request.json_body
    user = User.find(body['username'])
    if user == None:
        return {'error': 'User name or password is invalid.'}
    else:
        record = user.attributes()
        record['hash'] = user.hash
        record['salt'] = user.salt
        record['rounds'] = user.rounds
        record['hashed'] = user.hashed
        jwt_token = auth.get_jwt_token(body['username'], body['password'],
                                       record)
        return {'token': jwt_token}
Пример #6
0
def create_user():
    # This is the JSON body the user sent in their POST request.
    user_as_json = app.current_request.json_body
    table_name = get_table_name()
    table = boto3.resource('dynamodb').Table(table_name)
    username = user_as_json['username']
    user_detail = User.find(user_as_json['username'])
    if user_detail != None:
        return {'error': 'Username has been taken.'}
    else:
        user = User(user_as_json)
        user.save()
        record = user.attributes()
        record['hash'] = user.hash
        record['salt'] = user.salt
        record['rounds'] = user.rounds
        record['hashed'] = user.hashed
        jwt_token = auth.get_jwt_token(user_as_json['username'],
                                       user_as_json['password'], record)
        # We'll echo the json body back to the user in a 'user' key.
        return {
            'success': 'User was successfully created.',
            'token': jwt_token
        }
Пример #7
0
def get_user():
    username = get_authorized_username(app.current_request)
    user = User.find(username)
    return user.attributes()
Пример #8
0
def user_update_password():
    return User.validate_reset_password_token(app.current_request.json_body)
Пример #9
0
def forgot_password():
    return User.generate_reset_password_token(app.current_request.json_body)